Skip to content
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

Replaces circe-jawn by circe-jackson Parser #253

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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