Created
April 9, 2019 07:35
-
-
Save Unlimity/ecae7aec16d94aada479a8a84d0fe5de 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
class YourRequestFactory : Request.Factory() { | |
override fun create() = YourRequest() | |
} | |
class YourRequestInterceptor : RequestInterceptor() { | |
fun intercept(request: Request): Request { | |
if (request is YourRequest) { | |
request.headers["request_id"] = request.id | |
} | |
} | |
} | |
class YourResponseFactory : Response.Factory() { | |
override fun create() = YourResponse() | |
} | |
class YourResponseInterceptor { | |
fun intercept(response: Response): Response { | |
if (response is YourResponse) { | |
response.token = response.headers["auth_token"] | |
} | |
} | |
} | |
val client = NinjatoOkHttpClient(okHttpClient, YourRequestFactory(), YourResponseFactory()) { | |
interceptors += YourRequestInterceptor() | |
interceptors += YourResponseInterceptor() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment