fix schedule request. Add Moshi and network logger
This commit is contained in:
@@ -42,5 +42,12 @@ dependencies {
|
||||
api(libs.retrofit)
|
||||
api(libs.okhttp)
|
||||
|
||||
implementation(libs.retrofit.simplexml)
|
||||
implementation(libs.okhttp.logging)
|
||||
implementation(libs.converter.gson)
|
||||
|
||||
api(libs.moshi)
|
||||
api(libs.moshiKotlin)
|
||||
api(libs.retrofitMoshi)
|
||||
|
||||
api(libs.retrofit.simplexml)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package ru.fincode.tsudesk.core.network
|
||||
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import android.util.Log
|
||||
|
||||
class DebugInterceptor : Interceptor {
|
||||
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val request = chain.request()
|
||||
|
||||
Log.d("NETWORK_DEBUG", "URL: ${request.url}")
|
||||
Log.d("NETWORK_DEBUG", "Method: ${request.method}")
|
||||
Log.d("NETWORK_DEBUG", "Headers: ${request.headers}")
|
||||
|
||||
return chain.proceed(request)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
package ru.fincode.tsudesk.core.network
|
||||
|
||||
object NetworkConstants {
|
||||
const val BASE_URL = "https://api.tsu.tula.ru/"
|
||||
const val BASE_URL = "https://tulsu.ru/schedule/queries/"
|
||||
}
|
||||
@@ -8,12 +8,16 @@ import okhttp3.OkHttpClient
|
||||
import retrofit2.Retrofit
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Singleton
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object NetworkModule {
|
||||
|
||||
private const val TIMEOUT_SEC = 30L
|
||||
val logging = HttpLoggingInterceptor().apply {
|
||||
level = HttpLoggingInterceptor.Level.BODY
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
@@ -23,6 +27,7 @@ object NetworkModule {
|
||||
.readTimeout(TIMEOUT_SEC, TimeUnit.SECONDS)
|
||||
.writeTimeout(TIMEOUT_SEC, TimeUnit.SECONDS)
|
||||
.retryOnConnectionFailure(true)
|
||||
.addInterceptor(DebugInterceptor())
|
||||
.build()
|
||||
|
||||
@Provides
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
package ru.fincode.tsudesk.core.network
|
||||
|
||||
import com.squareup.moshi.Moshi
|
||||
import okhttp3.OkHttpClient
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.simplexml.SimpleXmlConverterFactory
|
||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||
import javax.inject.Inject
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class RetrofitProvider @Inject constructor() {
|
||||
|
||||
private val moshi: Moshi = Moshi.Builder()
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
.build()
|
||||
|
||||
class RetrofitProvider {
|
||||
fun process(baseUrl: String, client: OkHttpClient): Retrofit =
|
||||
Retrofit.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.client(client)
|
||||
.addConverterFactory(SimpleXmlConverterFactory.create())
|
||||
.addConverterFactory(MoshiConverterFactory.create(moshi))
|
||||
.build()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user