Skip to content

Instantly share code, notes, and snippets.

@kohendrix
Created February 2, 2019 04:08
Show Gist options
  • Select an option

  • Save kohendrix/6f4fae1952a3f399d8a9cb6f0548c9cd to your computer and use it in GitHub Desktop.

Select an option

Save kohendrix/6f4fae1952a3f399d8a9cb6f0548c9cd to your computer and use it in GitHub Desktop.
Volley Coroutines Sample
class TestRequest : HttpRequest() {
companion object {
private const val HEADER_AUTHORIZATION_KEY = "Authorization"
private const val QUERY_KEY = "q"
}
override val method: Int = Request.Method.GET
override val url: String = "https://www.testrequestforfun.com"
override val queryParams: Map<String, String> = mapOf(QUERY_KEY to "paramTest")
suspend fun request(): TestResponse {
return request(TestResponse::class, JSONObject())
}
override fun headers(): Map<String, String> {
return mapOf(HEADER_AUTHORIZATION_KEY to "whateverauthvalue")
}
}
class TestResponse : HttpResponse() {
companion object {
private const val TEST_KEY = "test"
}
lateinit var testValue: String
override fun parseJson(json: JSONObject): HttpResponse {
testValue = json.getString(TEST_KEY)
return this
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment