Skip to content

Instantly share code, notes, and snippets.

@DjakaTechnology
Created March 11, 2019 12:31
Show Gist options
  • Save DjakaTechnology/3bd363ba4f95369dd5e107fdaef8c74f to your computer and use it in GitHub Desktop.
Save DjakaTechnology/3bd363ba4f95369dd5e107fdaef8c74f to your computer and use it in GitHub Desktop.
private fun getRetrofit(c: Context): Retrofit {
val pref = c.getSharedPreferences(SharedKey.Session.SESSION, MODE_PRIVATE)
val client = OkHttpClient.Builder().addInterceptor { chain ->
val newRequest = chain.request().newBuilder()
.addHeader("Authorization", "Bearer " + pref.getString(SharedKey.Session.TOKEN, "")!!)
.build()
chain.proceed(newRequest)
}.build()
return Retrofit.Builder().baseUrl(baseUrl).client(client).addConverterFactory(
ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.build()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment