Skip to content

Instantly share code, notes, and snippets.

@fievx
Created December 31, 2018 15:03
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 fievx/a0cd2dae4360293f2f84f1076622f7b1 to your computer and use it in GitHub Desktop.
Save fievx/a0cd2dae4360293f2f84f1076622f7b1 to your computer and use it in GitHub Desktop.
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