Skip to content

Instantly share code, notes, and snippets.

@RoRoche
Created November 6, 2019 12:47
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 RoRoche/e0b7496e1ddaa93f5cb31c0949e5910a to your computer and use it in GitHub Desktop.
Save RoRoche/e0b7496e1ddaa93f5cb31c0949e5910a to your computer and use it in GitHub Desktop.
import okhttp3.Call
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
class GetReposRequest(private val call: Call) : RestRequest {
constructor(client: OkHttpClient, baseUrl: String, user: String) : this(
client,
Request.Builder()
.url(
baseUrl.toHttpUrl()
.newBuilder()
.addPathSegment("users")
.addPathSegment(user)
.addPathSegment("repos")
.build()
)
.build()
)
constructor(client: OkHttpClient, request: Request) : this(
client.newCall(request)
)
override fun response(): Response {
return call.execute()
}
override fun cancel() {
if (!call.isCanceled()) {
call.cancel()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment