Skip to content

Commit 544652b

Browse files
author
Javier de Silóniz Sandino
committed
Added objects for easier implicit handling for both JVM and JS projects - Gists in tests are not publico
1 parent fcaf13c commit 544652b

16 files changed

Lines changed: 104 additions & 65 deletions

File tree

docs/src/main/tut/docs.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@ WIP: Import
1111
import github4s.Github
1212
```
1313

14-
In order for github4s to work in both JVM and scala-js environments, you'll need to place different implicits in your scope:
14+
In order for github4s to work in both JVM and scala-js environments, you'll need to place different implicits in your scope, depending on your needs:
1515

1616
```tut:silent
17-
object JVMProgram extends github4s.ImplicitsJVM {
18-
// Your JVM-compatible code...
19-
}
17+
import github4s.jvm.Implicits._
18+
```
2019

21-
/*
22-
object JSProgram extends github4s.ImplicitsJS {
23-
// Your scala-js compatible code...
24-
}
25-
*/
20+
```tut:silent
21+
// import github4s.js.Implicits._
2622
```
2723

2824
```tut:invisible
@@ -46,10 +42,9 @@ user1 in this case `Free[GHException Xor GHResult[User], User]` and we can run (
4642
```tut:silent
4743
import cats.Eval
4844
import github4s.Github._
49-
import github4s.implicits._
5045
import scalaj.http._
5146
52-
object ProgramEval extends github4s.ImplicitsJVM {
47+
object ProgramEval {
5348
val u1 = user1.exec[Eval, HttpResponse[String]].value
5449
}
5550
@@ -75,22 +70,22 @@ WIP: With `Id`
7570
import cats.Id
7671
import scalaj.http._
7772
78-
object ProgramId extends github4s.ImplicitsJVM {
73+
object ProgramId {
7974
val u2 = Github(accessToken).users.get("raulraja").exec[Id, HttpResponse[String]]
8075
}
8176
```
8277

8378
WIP: With `Future`
8479

8580
```tut:silent
86-
import github4s.implicits._
81+
import cats.Id
8782
import scala.concurrent.Future
8883
import scala.concurrent.ExecutionContext.Implicits.global
8984
import scala.concurrent.duration._
9085
import scala.concurrent.Await
9186
import scalaj.http._
9287
93-
object ProgramFuture extends github4s.ImplicitsJVM {
88+
object ProgramFuture {
9489
val u3 = Github(accessToken).users.get("dialelo").exec[Future, HttpResponse[String]]
9590
Await.result(u3, 2.seconds)
9691
}
@@ -102,8 +97,9 @@ WIP: With `scalaz.Task`
10297
import scalaz.concurrent.Task
10398
import github4s.scalaz.implicits._
10499
import scalaj.http._
100+
import github4s.jvm.Implicits._
105101
106-
object ProgramTask extends github4s.ImplicitsJVM {
102+
object ProgramTask {
107103
val u4 = Github(accessToken).users.get("franciscodr").exec[Task, HttpResponse[String]]
108104
u4.attemptRun
109105
}
@@ -116,14 +112,14 @@ import cats.Eval
116112
import cats.implicits._
117113
import github4s.Github
118114
import github4s.Github._
119-
import github4s.implicits._
115+
import github4s.jvm.Implicits._
120116
import scalaj.http._
121117
122118
val accessToken = sys.props.get("token")
123119
```
124120

125121
```tut:book
126-
object ProgramEval extends github4s.ImplicitsJVM {
122+
object ProgramEval {
127123
val user1 = Github(accessToken).users.get("rafaparadela").exec[Eval, HttpResponse[String]].value
128124
}
129125
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2016 47 Degrees, LLC. <http://www.47deg.com>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
package github4s.js
23+
24+
object Implicits extends ImplicitsJS

github4s/js/src/main/scala/github4s/ImplicitsJS.scala renamed to github4s/js/src/main/scala/github4s/js/ImplicitsJS.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2020
*/
2121

22-
package github4s
22+
package github4s.js
2323

24-
import cats.Id
2524
import cats.instances.FutureInstances
26-
import github4s.free.interpreters.Interpreters
2725
import fr.hmil.roshttp.response.SimpleHttpResponse
26+
import github4s.HttpRequestBuilderExtensionJS
27+
import github4s.free.interpreters.Interpreters
28+
import github4s.implicits._
2829
import scala.concurrent.ExecutionContext.Implicits.global
2930
import scala.concurrent.Future
30-
import github4s.implicits._
3131

3232
trait ImplicitsJS extends FutureInstances with HttpRequestBuilderExtensionJS {
3333

github4s/js/src/test/scala/github4s/utils/integration/GHAuthSpec.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,16 @@
2121

2222
package github4s.integration
2323

24-
import cats.Id
25-
import cats.implicits._
2624
import github4s.Github._
27-
import github4s.{Github, ImplicitsJS}
28-
import github4s.implicits._
25+
import github4s.Github
2926
import github4s.utils.TestUtils
3027
import org.scalatest._
3128
import fr.hmil.roshttp.response.SimpleHttpResponse
3229
import github4s.free.domain.Authorize
33-
import org.scalatest.concurrent.ScalaFutures
34-
30+
import github4s.js.Implicits._
3531
import scala.concurrent.Future
3632

37-
class GHAuthSpec extends AsyncFlatSpec with Matchers with TestUtils with ImplicitsJS {
33+
class GHAuthSpec extends AsyncFlatSpec with Matchers with TestUtils {
3834

3935
override implicit val executionContext = scala.concurrent.ExecutionContext.Implicits.global
4036

github4s/js/src/test/scala/github4s/utils/integration/GHGistsSpec.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,16 @@
2121

2222
package github4s.integration
2323

24-
import cats.Id
25-
import cats.implicits._
2624
import github4s.Github._
27-
import github4s.implicits._
28-
import github4s.{Github, ImplicitsJS}
25+
import github4s.Github
2926
import github4s.utils.TestUtils
3027
import org.scalatest._
3128
import fr.hmil.roshttp.response.SimpleHttpResponse
3229
import github4s.free.domain.{Gist, GistFile}
33-
30+
import github4s.js.Implicits._
3431
import scala.concurrent.Future
3532

36-
class GHGistsSpec extends AsyncFlatSpec with Matchers with TestUtils with ImplicitsJS {
33+
class GHGistsSpec extends AsyncFlatSpec with Matchers with TestUtils {
3734

3835
override implicit val executionContext = scala.concurrent.ExecutionContext.Implicits.global
3936

github4s/js/src/test/scala/github4s/utils/integration/GHReposSpec.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,17 @@
2121

2222
package github4s.integration
2323

24-
import cats.Id
25-
import cats.implicits._
2624
import github4s.Github._
2725
import github4s.GithubResponses._
28-
import github4s.implicits._
29-
import github4s.{Github, ImplicitsJS}
26+
import github4s.Github
3027
import github4s.utils.TestUtils
3128
import org.scalatest.{AsyncFlatSpec, FlatSpec, Matchers}
3229
import fr.hmil.roshttp.response.SimpleHttpResponse
3330
import github4s.free.domain.{Commit, Repository, User}
34-
31+
import github4s.js.Implicits._
3532
import scala.concurrent.Future
3633

37-
class GHReposSpec extends AsyncFlatSpec with Matchers with TestUtils with ImplicitsJS {
34+
class GHReposSpec extends AsyncFlatSpec with Matchers with TestUtils {
3835

3936
override implicit val executionContext = scala.concurrent.ExecutionContext.Implicits.global
4037

github4s/js/src/test/scala/github4s/utils/integration/GHUsersSpec.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@
2121

2222
package github4s.integration
2323

24-
import cats.Id
25-
import cats.implicits._
2624
import github4s.Github._
27-
import github4s.implicits._
28-
import github4s.{Github, ImplicitsJS}
25+
import github4s.Github
2926
import github4s.utils.TestUtils
3027
import org.scalatest._
3128
import fr.hmil.roshttp.response.SimpleHttpResponse
3229
import scala.concurrent.Future
3330
import github4s.free.domain.User
31+
import github4s.js.Implicits._
3432

35-
class GHUsersSpec extends AsyncFlatSpec with Matchers with TestUtils with ImplicitsJS {
33+
class GHUsersSpec extends AsyncFlatSpec with Matchers with TestUtils {
3634

3735
override implicit val executionContext = scala.concurrent.ExecutionContext.Implicits.global
3836

github4s/js/src/test/scala/github4s/utils/utils/TestUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ trait TestUtils extends Matchers {
8888
val invalidAnonParameter = "X"
8989

9090
val validGistDescription = "A Gist"
91-
val validGistPublic = true
91+
val validGistPublic = false
9292
val validGistFileContent = "val meaningOfLife = 42"
9393
val validGistFilename = "test.scala"
9494
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2016 47 Degrees, LLC. <http://www.47deg.com>
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
package github4s.jvm
23+
24+
import github4s.FutureCaptureInstance
25+
26+
object Implicits extends ImplicitsJVM with FutureCaptureInstance

github4s/jvm/src/main/scala/github4s/ImplicitsJVM.scala renamed to github4s/jvm/src/main/scala/github4s/jvm/ImplicitsJVM.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@
1919
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2020
*/
2121

22-
package github4s
22+
package github4s.jvm
2323

24-
import cats.{Eval, Id}
24+
import cats.instances.FutureInstances
25+
import cats.{Eval, _}
2526
import github4s.free.interpreters.Interpreters
27+
import github4s.{EvalInstances, HttpRequestBuilderExtensionJVM, IdInstances}
2628
import scala.concurrent.Future
29+
import scalaj.http.HttpResponse
2730
import scala.concurrent.ExecutionContext.Implicits.global
28-
import scalaj.http._
2931
import github4s.implicits._
30-
import cats.instances.FutureInstances
3132

3233
trait ImplicitsJVM
3334
extends IdInstances

0 commit comments

Comments
 (0)