Skip to content

Instantly share code, notes, and snippets.

@anxiousmodernman
Created February 18, 2014 13:40
Show Gist options
  • Save anxiousmodernman/9071173 to your computer and use it in GitHub Desktop.
Save anxiousmodernman/9071173 to your computer and use it in GitHub Desktop.
made use of the FakeApplication() in the Specicification class again
class GithubServiceITSpec extends Specification {
val app = FakeApplication()
val config = Play.configuration(app)
implicit val access_token = AccessToken(config.getString("github.oauth.token") getOrElse {
throw new IllegalStateException("No github.oauth.token")
})
"Github integration" should {
"allow fetching all public events for user" in {
running(app) {
val githubService = new WSGitHubService
val events = githubService.fetchPublicEvents("anxiousmodernman")(access_token)
val awaited = Await.result(events, Duration("10 seconds"))
println(awaited)
awaited \ "data" \ "login" should beEqualTo(JsString("anxiousmodernman"))
pending
}
}
}
}
@jeffmay
Copy link

jeffmay commented Feb 18, 2014

Yup. That's how you grab info from the json.

Also, you might want to consider writing a JsPath. This is basically the equivalent of a compiled Regular Expression, but for transforming a tree of JsValues into a different shaped tree. It builds a reusable function that does some piece of extraction. You can compose these like functions, so they are nice when you have a certain shape that you want to extract, but don't want to have to write all the steps in each method.

See http://mandubian.com/2012/09/08/unveiling-play-2-dot-1-json-api-part1-jspath-reads-combinators/ for some examples.

I don't think you need it here, but just FYI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment