File tree Expand file tree Collapse file tree 4 files changed +52
-1
lines changed
src/main/java/cloud/mindbox/mobile_sdk Expand file tree Collapse file tree 4 files changed +52
-1
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 1+ package cloud.mindbox.mobile_sdk
2+
Original file line number Diff line number Diff 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 () {
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments