Created
December 31, 2018 15:03
-
-
Save fievx/a0cd2dae4360293f2f84f1076622f7b1 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 AuthenticationManager(endpoint: String) { | |
var login : LoginResponse? = null | |
private val okHttpClient = OkHttpClient.Builder().build() | |
private val retrofit = Retrofit.Builder() | |
.baseUrl(endpoint) | |
.client(okHttpClient) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) | |
.build() | |
private val api = retrofit.create(LoginCall::class.java) | |
fun authenticateBlocking(): LoginResponse?{ | |
return api.login(LoginBody(username, password)) | |
.doOnSuccess { login = it } | |
.blockingGet() | |
} | |
companion object { | |
private const val username = "fake_address@gmail.com" | |
private const val password = "hrfuqai@8979457" | |
const val PROD_ENDPOINT = "https://any_api.com" | |
} | |
} | |
interface LoginCall { | |
@POST("/v2/auth/login") | |
fun login(@Body loginBody: LoginBody): Single<LoginResponse> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment