Created
July 23, 2017 19:43
-
-
Save caseykulm/2b3e8803f4f6ff0d0f63ff98fc43daea to your computer and use it in GitHub Desktop.
Reversed After
This file contains hidden or 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
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 | |
} | |
} |
This file contains hidden or 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
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") | |
} | |
} | |
} |
This file contains hidden or 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
data class UserRequest(val userName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment