Created
July 28, 2022 08:33
-
-
Save 90K2/0be3de3614be05c7b17f84c272c21fd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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