Skip to content

Instantly share code, notes, and snippets.

@grimrose
Created May 20, 2016 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grimrose/e4ffb9d4dfd50c6adba21f4541cfaefc to your computer and use it in GitHub Desktop.
Save grimrose/e4ffb9d4dfd50c6adba21f4541cfaefc to your computer and use it in GitHub Desktop.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "com.squareup.okhttp3:okhttp:3.2.0"
}
}
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import groovy.json.*
task okHttp << {
def client = new OkHttpClient()
def request = new Request.Builder()
.url("https://api.github.com")
.build()
def response = client.newCall(request).execute()
def body = response.body().string()
println body
println JsonOutput.prettyPrint(body)
def slurper = new JsonSlurper()
def parsed = slurper.parseText(body)
println parsed.emojis_url
def emoReq = new Request.Builder().url(parsed.emojis_url).build()
def emoRes = client.newCall(emoReq).execute()
def emoBody = emoRes.body().string()
println JsonOutput.prettyPrint(emoBody)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment