-
Notifications
You must be signed in to change notification settings - Fork 75
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
Compatibility with scala-js #38
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a922b56
Moves the code to the different modules. WIP
juanpedromoreno aed4702
Merge branch 'master' into g4s-10-support-for-scalajs
juanpedromoreno 34cbe91
Merge branch 'master' into g4s-10-support-for-scalajs
juanpedromoreno 042ef1c
WIP
2e3a545
Merge branch 'g4s-10-support-for-scalajs' of github.com:47deg/github4…
ef4298e
Still WIP - solves major problems with implicits
3d266d3
Still WIP - solves major problems with implicits
311661b
WIP - fixed problems with implicits
586586a
WIP - Fixed compilation issues in tests for JVM
c9515eb
WIP - tests compiling/passing
af091aa
Fixed publishing to local - Switched to latest version of ROSHTTP
0a84652
Added user-agent header to requests from the JS side
683cda3
Fixed issues with tests both in JVM and JS sides
b2b09f2
Excluding JS side from scoverage, as it's not compatible with ScalaJS…
7040a3c
Fixing issues with tut docs
8ba724e
Fixing changes from PRs
fcaf13c
Updating docs to reflect the use of GitHub access tokens to perform t…
544652b
Added objects for easier implicit handling for both JVM and JS projec…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ target/ | |
.idea | ||
docs/src/jekyll/_site/ | ||
docs/src/jekyll/*.md | ||
.DS_Store | ||
|
||
# PGP keys | ||
*.gpg |
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
103 changes: 103 additions & 0 deletions
103
github4s/js/src/main/scala/github4s/HttpRequestBuilderExtensionJS.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,103 @@ | ||
/* | ||
* Copyright (c) 2016 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package github4s | ||
|
||
import scala.concurrent.Future | ||
import fr.hmil.roshttp._ | ||
import fr.hmil.roshttp.body.{BodyPart, BulkBodyPart} | ||
import java.nio.ByteBuffer | ||
|
||
import cats.implicits._ | ||
import fr.hmil.roshttp.response.SimpleHttpResponse | ||
import fr.hmil.roshttp.util.HeaderMap | ||
import fr.hmil.roshttp.body.Implicits._ | ||
import fr.hmil.roshttp.exceptions.HttpException | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import github4s.GithubResponses.{GHResponse, GHResult, JsonParsingException, UnexpectedException} | ||
import github4s.GithubDefaultUrls._ | ||
import github4s.Decoders._ | ||
import github4s.HttpClient.HttpCode400 | ||
import io.circe.Decoder | ||
import io.circe.parser._ | ||
import monix.reactive.Observable | ||
|
||
import scala.util.{Failure, Success} | ||
|
||
case class CirceJSONBody(value: String) extends BulkBodyPart { | ||
override def contentType: String = s"application/json; charset=utf-8" | ||
override def contentData: ByteBuffer = ByteBuffer.wrap(value.getBytes("utf-8")) | ||
} | ||
|
||
trait HttpRequestBuilderExtensionJS { | ||
|
||
import monix.execution.Scheduler.Implicits.global | ||
|
||
val userAgent = { | ||
val name = github4s.BuildInfo.name | ||
val version = github4s.BuildInfo.version | ||
s"$name/$version" | ||
} | ||
|
||
implicit def extensionJS: HttpRequestBuilderExtension[SimpleHttpResponse, Future] = | ||
new HttpRequestBuilderExtension[SimpleHttpResponse, Future] { | ||
def run[A](rb: HttpRequestBuilder[SimpleHttpResponse, Future])( | ||
implicit D: Decoder[A]): Future[GHResponse[A]] = { | ||
val request = HttpRequest(rb.url) | ||
.withMethod(Method(rb.httpVerb.verb)) | ||
.withQueryParameters(rb.params.toSeq: _*) | ||
.withHeader("content-type", "application/json") | ||
.withHeader("user-agent", userAgent) | ||
.withHeaders(rb.authHeader.toList: _*) | ||
.withHeaders(rb.headers.toList: _*) | ||
|
||
rb.data | ||
.map(d => request.send(CirceJSONBody(d))) | ||
.getOrElse(request.send()) | ||
.map(toEntity[A]) | ||
.recoverWith { | ||
case e => Future.successful(Either.left(UnexpectedException(e.getMessage))) | ||
} | ||
} | ||
} | ||
|
||
def toEntity[A](response: SimpleHttpResponse)(implicit D: Decoder[A]): GHResponse[A] = | ||
response match { | ||
case r if r.statusCode < HttpCode400.statusCode ⇒ | ||
decode[A](r.body).fold( | ||
e ⇒ Either.left(JsonParsingException(e.getMessage, r.body)), | ||
result ⇒ | ||
Either.right( | ||
GHResult(result, r.statusCode, rosHeaderMapToRegularMap(r.headers)) | ||
) | ||
) | ||
case r ⇒ | ||
Either.left( | ||
UnexpectedException( | ||
s"Failed invoking get with status : ${r.statusCode}, body : \n ${r.body}")) | ||
} | ||
|
||
private def rosHeaderMapToRegularMap( | ||
headers: HeaderMap[String]): Map[String, IndexedSeq[String]] = | ||
headers.flatMap(m => Map(m._1.toLowerCase -> IndexedSeq(m._2))) | ||
|
||
} |
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,24 @@ | ||
/* | ||
* Copyright (c) 2016 47 Degrees, LLC. <http://www.47deg.com> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package github4s.js | ||
|
||
object Implicits extends ImplicitsJS |
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.
Can this
fork in Test := false
be moved tosharedJsSettings
? In this way, the github4s module can be defined simply withlazy val github4sJS = github4s.js