New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cats-effect module #155
Merged
Merged
cats-effect module #155
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2b04152
cats-effect module
BenFradet e1a52d6
js support
BenFradet 2d086a3
excluding cats-effect from code cov
BenFradet 99c963b
Fixes sbt dependencies for cats-effects module
juanpedromoreno 5eec899
Fixes cats-effect tests for scalajs
juanpedromoreno db0780c
docs
BenFradet d222b52
Fixes cats-effect docs
juanpedromoreno 8226339
cats-effect taken into account during code coverage
BenFradet c3690d2
dummy test to increase coverage
BenFradet File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
cats-effect/js/src/main/scala/github4s/cats/effect/IOHttpRequestBuilderExtensionJS.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.cats.effect | ||
|
||
import cats.effect.IO | ||
import cats.Eval.later | ||
import fr.hmil.roshttp.response.SimpleHttpResponse | ||
import github4s.{HttpRequestBuilder, HttpRequestBuilderExtension, HttpRequestBuilderExtensionJS} | ||
import github4s.GithubResponses._ | ||
import io.circe.Decoder | ||
|
||
import scala.concurrent.Future | ||
|
||
trait IOHttpRequestBuilderExtensionJS extends HttpRequestBuilderExtensionJS { | ||
|
||
import monix.execution.Scheduler.Implicits.global | ||
|
||
implicit def extensionIOJS: HttpRequestBuilderExtension[SimpleHttpResponse, IO] = | ||
new HttpRequestBuilderExtension[SimpleHttpResponse, IO] { | ||
|
||
def run[A](rb: HttpRequestBuilder[SimpleHttpResponse, IO])( | ||
implicit D: Decoder[A]): IO[GHResponse[A]] = | ||
runMapWrapper[A](rb, decodeEntity[A]) | ||
|
||
def runEmpty(rb: HttpRequestBuilder[SimpleHttpResponse, IO]): IO[GHResponse[Unit]] = | ||
runMapWrapper[Unit](rb, emptyResponse) | ||
|
||
private[this] def runMapWrapper[A]( | ||
rb: HttpRequestBuilder[SimpleHttpResponse, IO], | ||
mapResponse: SimpleHttpResponse => GHResponse[A]): IO[GHResponse[A]] = | ||
IO.fromFuture(later(runMap[A, IO](rb, mapResponse))) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
cats-effect/js/src/main/scala/github4s/cats/effect/js/Implicits.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.cats.effect.js | ||
|
||
object Implicits extends ImplicitsJS |
29 changes: 29 additions & 0 deletions
29
cats-effect/js/src/main/scala/github4s/cats/effect/js/ImplicitsJS.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.cats.effect.js | ||
|
||
import cats.effect.IO | ||
import fr.hmil.roshttp.response.SimpleHttpResponse | ||
import github4s.HttpRequestBuilderExtensionJS | ||
import github4s.cats.effect.{IOCaptureInstance, IOHttpRequestBuilderExtensionJS} | ||
import github4s.free.interpreters.Interpreters | ||
import github4s.implicits._ | ||
|
||
trait ImplicitsJS extends IOHttpRequestBuilderExtensionJS with IOCaptureInstance { | ||
implicit val intInstanceIORosHttp = | ||
new Interpreters[IO, SimpleHttpResponse] | ||
} |
51 changes: 51 additions & 0 deletions
51
cats-effect/js/src/test/scala/github4s/cats/effect/js/CatsEffectJSSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.cats.effect.js | ||
|
||
import cats.effect.IO | ||
import github4s.Github | ||
import github4s.Github._ | ||
import github4s.cats.effect.js.Implicits._ | ||
import org.scalatest.{FlatSpec, Matchers} | ||
import fr.hmil.roshttp.response.SimpleHttpResponse | ||
|
||
class CatsEffectJSSpec extends FlatSpec with Matchers { | ||
val accessToken = sys.env.get("GITHUB4S_ACCESS_TOKEN") | ||
val headerUserAgent = Map("user-agent" -> "github4s") | ||
val validUsername = "rafaparadela" | ||
val invalidUsername = "GHInvalidUserName" | ||
val okStatusCode = 200 | ||
|
||
"cats-effect js integration" should "return a succeded result for a valid call" in { | ||
val response = Github(accessToken).users | ||
.get(validUsername) | ||
.exec[IO, SimpleHttpResponse](headerUserAgent) | ||
|
||
val res = response.unsafeRunSync | ||
res.isRight shouldBe true | ||
res.right.map(_.statusCode) shouldBe Right(okStatusCode) | ||
} | ||
|
||
it should "return a failed result for an invalid call" in { | ||
val response = Github(accessToken).users | ||
.get(invalidUsername) | ||
.exec[IO, SimpleHttpResponse](headerUserAgent) | ||
|
||
val res = response.unsafeRunSync | ||
res.isLeft shouldBe true | ||
} | ||
} | ||
19 changes: 19 additions & 0 deletions
19
cats-effect/jvm/src/main/scala/github4s/cats/effect/jvm/Implicits.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.cats.effect.jvm | ||
|
||
object Implicits extends ImplicitsJVM |
29 changes: 29 additions & 0 deletions
29
cats-effect/jvm/src/main/scala/github4s/cats/effect/jvm/ImplicitsJVM.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.cats.effect.jvm | ||
|
||
import cats.effect.IO | ||
import github4s.HttpRequestBuilderExtensionJVM | ||
import github4s.cats.effect.IOCaptureInstance | ||
import github4s.free.interpreters.Interpreters | ||
import github4s.implicits._ | ||
import scalaj.http.HttpResponse | ||
|
||
trait ImplicitsJVM extends HttpRequestBuilderExtensionJVM with IOCaptureInstance { | ||
implicit val intInstanceIOScalaJ = | ||
new Interpreters[IO, HttpResponse[String]] | ||
} |
51 changes: 51 additions & 0 deletions
51
cats-effect/jvm/src/test/scala/github4s/cats/effect/jvm/CatsEffectJVMSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.cats.effect.jvm | ||
|
||
import cats.effect.IO | ||
import github4s.Github | ||
import github4s.Github._ | ||
import github4s.cats.effect.jvm.Implicits._ | ||
import org.scalatest.{FlatSpec, Matchers} | ||
import scalaj.http.HttpResponse | ||
|
||
class CatsEffectJVMSpec extends FlatSpec with Matchers { | ||
val accessToken = sys.env.get("GITHUB4S_ACCESS_TOKEN") | ||
val headerUserAgent = Map("user-agent" -> "github4s") | ||
val validUsername = "rafaparadela" | ||
val invalidUsername = "GHInvalidUserName" | ||
val okStatusCode = 200 | ||
|
||
"cats-effect jvm integration" should "return a succeded result for a valid call" in { | ||
val response = | ||
Github(accessToken).users.get(validUsername).exec[IO, HttpResponse[String]](headerUserAgent) | ||
|
||
val res = response.unsafeRunSync | ||
res.isRight shouldBe true | ||
res.right.map(_.statusCode) shouldBe Right(okStatusCode) | ||
} | ||
|
||
it should "return a failed result for an invalid call" in { | ||
val response = | ||
Github(accessToken).users | ||
.get(invalidUsername) | ||
.exec[IO, HttpResponse[String]](headerUserAgent) | ||
|
||
val res = response.unsafeRunSync | ||
res.isLeft shouldBe true | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
cats-effect/shared/src/main/scala/github4s/cats/effect/IOCaptureInstance.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2016-2017 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package github4s.cats.effect | ||
|
||
import cats.effect.IO | ||
import github4s.free.interpreters.Capture | ||
|
||
trait IOCaptureInstance { | ||
implicit val ioCaptureInstance = new Capture[IO] { | ||
override def capture[A](a: ⇒ A): IO[A] = IO.pure(a) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This spec is never run, I don't know why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #156