Skip to content

Instantly share code, notes, and snippets.

@caseykulm
Created July 23, 2017 19:43
Show Gist options
  • Save caseykulm/2b3e8803f4f6ff0d0f63ff98fc43daea to your computer and use it in GitHub Desktop.
Save caseykulm/2b3e8803f4f6ff0d0f63ff98fc43daea to your computer and use it in GitHub Desktop.
Reversed After
class LibClient(val libOptions: LibOptions) {
lazy val reqFactory: OkRequestFactory
fun init() {
reqFactory = OkRequestFactory(libOptions)
}
fun getUser(userRequest: UserRequest): UserResponse {
val okRequest = reqFactory.toOkRequest(userRequest)
// execute request, and parse response
return userResponse
}
}
class OkRequestFactory(val libOptions: LibOptions) {
fun toOkRequest(request: BaseRequest): okhttp3.Request {
if (request is UserRequest) {
val requestBuilder = okhttp3.Request.Builder()
.addQueryParam("config_1", libOptions.getConfig1())
.addQueryParam("config_2", libOptions.getConfig2())
.addQueryParam("user_name", request.userName)
return requestBuilder.build()
} else {
throw IllegalStateException("Unknown request type")
}
}
}
data class UserRequest(val userName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment