-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitHubrApp.kt
More file actions
42 lines (34 loc) · 1.3 KB
/
GitHubrApp.kt
File metadata and controls
42 lines (34 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.tigcal.samples.githubr
import android.app.Application
import com.squareup.moshi.Moshi
import com.tigcal.samples.githubr.data.GitHubRepository
import com.tigcal.samples.githubr.data.GitHubService
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
class GitHubrApp: Application() {
lateinit var gitHubRepository: GitHubRepository
private val token = "YOUR_PERSONAL_ACCESS_TOKEN"
override fun onCreate() {
super.onCreate()
val moshi = Moshi.Builder()
.build()
val okHttpClient = OkHttpClient.Builder().apply {
addInterceptor(
Interceptor { chain ->
val builder = chain.request().newBuilder()
builder.header("Authorization", "Bearer $token")
return@Interceptor chain.proceed(builder.build())
}
)
}.build()
val retrofit = Retrofit.Builder()
.baseUrl("https://api.github.com/")
.addConverterFactory(MoshiConverterFactory.create(moshi))
.client(okHttpClient)
.build()
val gitHubService = retrofit.create(GitHubService::class.java)
gitHubRepository = GitHubRepository(gitHubService)
}
}