Skip to content

Commit

Permalink
Replaces circe-jawn by circe-jackson Parser (#253)
Browse files Browse the repository at this point in the history
* Makes circe-parser only needed in test stage

* Replaces parser by decoder

* Replaces circe-jawn parser by circe-jackson parser
  • Loading branch information
juanpedromoreno authored Feb 25, 2019
1 parent 9a23562 commit f5ddafa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import fr.hmil.roshttp.response.SimpleHttpResponse
import fr.hmil.roshttp.util.HeaderMap
import github4s.GithubResponses._
import github4s.HttpClient.{HttpCode200, HttpCode299}
import io.circe.Decoder
import io.circe.parser._
import io.circe._
import io.circe.jackson._
import io.circe.syntax._

import scala.concurrent.Future

Expand Down Expand Up @@ -81,7 +82,7 @@ trait HttpRequestBuilderExtensionJS {

def toEntity[A](
response: SimpleHttpResponse,
mapResponse: (SimpleHttpResponse) => GHResponse[A]): GHResponse[A] =
mapResponse: SimpleHttpResponse => GHResponse[A]): GHResponse[A] =
response match {
case r if r.statusCode <= HttpCode299.statusCode && r.statusCode >= HttpCode200.statusCode
mapResponse(r)
Expand All @@ -97,10 +98,12 @@ trait HttpRequestBuilderExtensionJS {
Either.right(GHResult((): Unit, r.statusCode, rosHeaderMapToRegularMap(r.headers)))

def decodeEntity[A](r: SimpleHttpResponse)(implicit D: Decoder[A]): GHResponse[A] =
decode[A](r.body).bimap(
e JsonParsingException(e.getMessage, r.body),
result GHResult(result, r.statusCode, rosHeaderMapToRegularMap(r.headers))
)
parse(r.body)
.flatMap(_.as[A])
.bimap(
e JsonParsingException(e.getMessage, r.body),
result GHResult(result, r.statusCode, rosHeaderMapToRegularMap(r.headers))
)
private def rosHeaderMapToRegularMap(
headers: HeaderMap[String]): Map[String, IndexedSeq[String]] =
headers.flatMap(m => Map(m._1.toLowerCase -> IndexedSeq(m._2)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
package github4s

import github4s.GithubResponses._
import io.circe.Decoder
import io.circe.parser._
import io.circe._
import io.circe.syntax._
import io.circe.jackson._
import scalaj.http._
import cats.implicits._
import github4s.free.interpreters.Capture
Expand Down Expand Up @@ -89,10 +90,12 @@ trait HttpRequestBuilderExtensionJVM {
Either.right(GHResult((): Unit, r.code, toLowerCase(r.headers)))

def decodeEntity[A](r: HttpResponse[String])(implicit D: Decoder[A]): GHResponse[A] =
decode[A](r.body).bimap(
e JsonParsingException(e.getMessage, r.body),
result GHResult(result, r.code, toLowerCase(r.headers))
)
parse(r.body)
.flatMap(_.as[A])
.bimap(
e JsonParsingException(e.getMessage, r.body),
result GHResult(result, r.code, toLowerCase(r.headers))
)

private def toLowerCase(
headers: Map[String, IndexedSeq[String]]): Map[String, IndexedSeq[String]] =
Expand Down
11 changes: 6 additions & 5 deletions project/ProjectPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ object ProjectPlugin extends AutoPlugin {
%%("simulacrum", V.simulacrum),
%%("circe-core", V.circe),
%%("circe-generic", V.circe),
%%("circe-parser", V.circe),
"io.circe" %% "circe-jackson28" % V.circe,
%%("base64", V.base64),
%%("scalamockScalatest", V.scalamockScalatest) % "test",
%%("scalatest", V.scalaTest) % "test"
%%("circe-parser", V.circe) % Test,
%%("scalamockScalatest", V.scalamockScalatest) % Test,
%%("scalatest", V.scalaTest) % Test
)
)

Expand All @@ -83,7 +84,7 @@ object ProjectPlugin extends AutoPlugin {
lazy val jvmDeps = Seq(
libraryDependencies ++= Seq(
%%("scalaj", V.scalaj),
"org.mock-server" % "mockserver-netty" % "3.10.4" % "test" excludeAll ExclusionRule(
"org.mock-server" % "mockserver-netty" % "3.10.4" % Test excludeAll ExclusionRule(
"com.twitter")
)
)
Expand All @@ -100,7 +101,7 @@ object ProjectPlugin extends AutoPlugin {
lazy val catsEffectDependencies = Seq(
libraryDependencies ++= Seq(
%%("cats-effect", V.catsEffect),
%%("scalatest", V.scalaTest) % "test"
%%("scalatest", V.scalaTest) % Test
)
)

Expand Down

0 comments on commit f5ddafa

Please sign in to comment.