Skip to content

Instantly share code, notes, and snippets.

@khle
Created November 11, 2021 14:14
Show Gist options
  • Save khle/0789268b881b47706eb67610e029064f to your computer and use it in GitHub Desktop.
Save khle/0789268b881b47706eb67610e029064f to your computer and use it in GitHub Desktop.
import my.androidapp
import my.androidapp.models
suspend fun getSpaceX(limit:Int) {
val vLimit = "\$limit"
val query = """
query($vLimit:Int)
{
launchesPast(limit: $vLimit) {
mission_name
launch_date_local
launch_site {
site_name_long
}
links {
article_link
video_link
}
rocket {
rocket_name
first_stage {
cores {
flight
core {
reuse_count
status
}
}
}
second_stage {
payloads {
payload_type
payload_mass_kg
payload_mass_lbs
}
}
}
ships {
name
image
home_port
}
}
}
""".trimIndent()
val variables = """
{
"limit": $limit
}
""".trimIndent()
val headersMap = emptyMap<String, String>()
val bodyJSON = JSONObject()
val jsonVariables = JSONObject(variables)
bodyJSON.put("query", query)
bodyJSON.put("variables", jsonVariables)
val SpaceXApiUrl = "https://api.spacex.land/graphql/"
try {
val spaceX = RequesterGQL().makeRequest(
SpaceXApiUrl,
headersMap,
bodyJSON,
Action.POST
) { json -> SpaceX.fromJson(json) }
println(spaceX)
} catch (e:Exception) {
println(e.toString())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment