Skip to content

Instantly share code, notes, and snippets.

@90K2
Created July 28, 2022 08:33
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 90K2/0be3de3614be05c7b17f84c272c21fd1 to your computer and use it in GitHub Desktop.
Save 90K2/0be3de3614be05c7b17f84c272c21fd1 to your computer and use it in GitHub Desktop.
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
private inline fun < reified T: Any> downloadData(link: String, key: String, offset: String?): T {
val url = link.toHttpUrl()
offset?.let { url.newBuilder().addQueryParameter("offset", offset).build() }
val response = OkHttpClient().newCall(
Request.Builder()
.url(url)
.addHeader("Authorization", "Bearer $key")
.build()
).execute()
val rBody = response.body?.string()
return ObjectMapper().readValue(rBody, T::class.java)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment