Skip to content

Commit e73d3f0

Browse files
author
Alexandra Batanova
committed
add retrofit
1 parent 2a90d5b commit e73d3f0

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

mobile-sdk/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,10 @@ dependencies {
7676
// coroutines
7777
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
7878
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2'
79+
80+
//network
81+
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
82+
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
83+
implementation "com.squareup.okhttp3:logging-interceptor:4.9.0"
84+
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-experimental-adapter:1.0.0'
7985
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package cloud.mindbox.mobile_sdk
2+

mobile-sdk/src/main/java/cloud/mindbox/mobile_sdk/Mindbox.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ object Mindbox {
2121
mindboxScope.launch {
2222
if (MindboxPreferences.isFirstInitialize) {
2323
firstInitialize(context, callback)
24-
MindboxPreferences.isFirstInitialize = false
2524
} else {
2625
secondaryInitialize()
2726
}
@@ -53,6 +52,7 @@ object Mindbox {
5352
callback: (String?, String?) -> Unit
5453
) {
5554
callback.invoke(firebaseToken, deviceUuid)
55+
MindboxPreferences.isFirstInitialize = false
5656
}
5757

5858
fun release() {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package cloud.mindbox.mobile_sdk
2+
3+
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.experimental.CoroutineCallAdapterFactory
4+
import okhttp3.*
5+
import okhttp3.logging.HttpLoggingInterceptor
6+
import retrofit2.Retrofit
7+
import retrofit2.converter.gson.GsonConverterFactory
8+
9+
10+
open class ServiceGenerator() {
11+
private val retrofit: Retrofit
12+
private val client: OkHttpClient
13+
14+
init {
15+
client = initClient()
16+
retrofit = initRetrofit()
17+
}
18+
19+
companion object {
20+
private const val BASE_URL = "https://api.mindbox.ru/v3/operations"
21+
}
22+
23+
private fun initRetrofit(): Retrofit {
24+
return Retrofit.Builder()
25+
.baseUrl(BASE_URL)
26+
.client(client)
27+
.addConverterFactory(GsonConverterFactory.create())
28+
.addCallAdapterFactory(CoroutineCallAdapterFactory())
29+
.build()
30+
}
31+
32+
private fun initClient(): OkHttpClient {
33+
val builder = OkHttpClient.Builder()
34+
35+
if (BuildConfig.DEBUG) {
36+
builder.addInterceptor(HttpLoggingInterceptor().apply {
37+
level = HttpLoggingInterceptor.Level.BODY
38+
})
39+
}
40+
41+
return builder.build()
42+
}
43+
}

0 commit comments

Comments
 (0)