TP-85622 | Remove cdn http client (#13179)
This commit is contained in:
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2020-2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
|
||||
package com.naviapp.network.retrofit
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.content.ContextCompat.getDataDir
|
||||
import com.chuckerteam.chucker.api.ChuckerCollector
|
||||
import com.chuckerteam.chucker.api.ChuckerInterceptor
|
||||
import com.navi.alfred.utils.AlfredConstants.DISABLE_CDN_LOGS
|
||||
import com.navi.common.firebaseremoteconfig.FirebaseRemoteConfigHelper
|
||||
import com.navi.common.model.NetworkInfo
|
||||
import com.navi.common.network.ApiConstants
|
||||
import com.navi.common.network.BaseHttpClient
|
||||
import com.navi.common.network.handleException
|
||||
import com.navi.common.network.logIOException
|
||||
import com.naviapp.BuildConfig
|
||||
import com.naviapp.app.NaviApplication
|
||||
import java.io.File
|
||||
import okhttp3.Cache
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Protocol
|
||||
import okhttp3.Response
|
||||
import okhttp3.ResponseBody
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
|
||||
class CdnHttpClient(networkInfo: NetworkInfo, context: Context) :
|
||||
BaseHttpClient(networkInfo, context, shouldAddHeaders = false, shouldAddAuthenticator = false) {
|
||||
private val cacheSize = 5 * 1024 * 1024L // 5 MB
|
||||
private val cacheMaxAge = 60 * 24 * 60 * 60L // 60 Days
|
||||
val httpClientBuilder: OkHttpClient.Builder
|
||||
get() {
|
||||
val okHttpClientBuilder = baseHttpClientBuilder
|
||||
with(okHttpClientBuilder) {
|
||||
cache(
|
||||
Cache(
|
||||
File(
|
||||
getDataDir(NaviApplication.instance.applicationContext),
|
||||
"web_view_cache_files"
|
||||
),
|
||||
cacheSize
|
||||
)
|
||||
)
|
||||
addInterceptor { chain ->
|
||||
var request = chain.request()
|
||||
request =
|
||||
request
|
||||
.newBuilder()
|
||||
.header("Cache-Control", "public, max-age=$cacheMaxAge")
|
||||
.build()
|
||||
|
||||
try {
|
||||
chain.proceed(request)
|
||||
} catch (e: Exception) {
|
||||
val errorMessage = handleException(e)
|
||||
logIOException(e, errorMessage, request)
|
||||
// A mocked response in case of n/w exception
|
||||
val errorStatusCode: Int =
|
||||
errorMessage.statusCode ?: ApiConstants.API_CODE_ERROR
|
||||
Response.Builder()
|
||||
.request(request)
|
||||
.protocol(Protocol.HTTP_2)
|
||||
.code(errorStatusCode)
|
||||
.message(e.message.orEmpty())
|
||||
.body(ResponseBody.create("application/json".toMediaTypeOrNull(), "{}"))
|
||||
.addHeader("content-type", "application/json")
|
||||
.build()
|
||||
}
|
||||
}
|
||||
if (BuildConfig.DEBUG && !FirebaseRemoteConfigHelper.getBoolean(DISABLE_CDN_LOGS)) {
|
||||
addInterceptor(loggingInterceptor())
|
||||
addInterceptor(
|
||||
ChuckerInterceptor.Builder(NaviApplication.instance.applicationContext)
|
||||
.collector(
|
||||
ChuckerCollector(NaviApplication.instance.applicationContext)
|
||||
)
|
||||
.maxContentLength(250000L)
|
||||
.redactHeaders(arrayListOf("X-Click-Stream-Data"))
|
||||
.alwaysReadResponseBody(false)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
}
|
||||
return okHttpClientBuilder
|
||||
}
|
||||
|
||||
private fun loggingInterceptor() =
|
||||
HttpLoggingInterceptor().apply { setLevel(HttpLoggingInterceptor.Level.BODY) }
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2023-2024 by Navi Technologies Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
|
||||
package com.naviapp.network.retrofit
|
||||
|
||||
import com.naviapp.app.NaviApplication
|
||||
import com.naviapp.network.util.createCdnRetrofitClient
|
||||
import com.naviapp.network.util.getNetworkInfo
|
||||
import retrofit2.Retrofit
|
||||
|
||||
class CdnRetrofitProvider private constructor() {
|
||||
val services: RetrofitService = defaultRetrofitClient.create(RetrofitService::class.java)
|
||||
|
||||
private object Holder {
|
||||
val INSTANCE = CdnRetrofitProvider()
|
||||
}
|
||||
|
||||
companion object {
|
||||
val instance: CdnRetrofitProvider by lazy { Holder.INSTANCE }
|
||||
val defaultRetrofitClient: Retrofit =
|
||||
createCdnRetrofitClient(
|
||||
CdnHttpClient(getNetworkInfo(), NaviApplication.instance.applicationContext)
|
||||
.httpClientBuilder
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,7 @@ import com.naviapp.models.response.OfferId
|
||||
import com.naviapp.network.retrofit.ResponseCallback
|
||||
import com.naviapp.personalloanrevamp.models.response.FeeDetailsV2Response
|
||||
import com.naviapp.personalloanrevamp.models.response.LoanDetailsV2Response
|
||||
import com.naviapp.utils.cdnRetrofitService
|
||||
import com.naviapp.utils.retrofitService
|
||||
import retrofit2.Response
|
||||
|
||||
class LoanDetailsV2Repository : ResponseCallback() {
|
||||
|
||||
@@ -70,10 +68,6 @@ class LoanDetailsV2Repository : ResponseCallback() {
|
||||
return apiResponseCallback(retrofitService().fetchRepeatLoanDetails(offerId, request))
|
||||
}
|
||||
|
||||
suspend fun fetchWebViewData(fullURL: String): Response<String>? {
|
||||
return cdnRetrofitService().getWebViewJSData(fullURL)
|
||||
}
|
||||
|
||||
suspend fun fetchRPDDetails() = apiResponseCallback(retrofitService().fetchRPDDetails())
|
||||
|
||||
suspend fun fetchAsyncRPDData(requestId: String?) =
|
||||
|
||||
@@ -64,7 +64,6 @@ import com.naviapp.app.NaviApplication
|
||||
import com.naviapp.models.CustomClickConfig
|
||||
import com.naviapp.models.CustomClickType
|
||||
import com.naviapp.models.response.ReferralData
|
||||
import com.naviapp.network.retrofit.CdnRetrofitProvider
|
||||
import com.naviapp.network.retrofit.RetrofitProvider
|
||||
import com.naviapp.network.retrofit.RetrofitService
|
||||
import com.naviapp.payment.models.Amount
|
||||
@@ -104,10 +103,6 @@ fun superAppRetrofitService(): RetrofitService {
|
||||
return NaviSuperAppRetrofitProvider.instance.services
|
||||
}
|
||||
|
||||
fun cdnRetrofitService(): RetrofitService {
|
||||
return CdnRetrofitProvider.instance.services
|
||||
}
|
||||
|
||||
fun Double.formatAmount(): String {
|
||||
val numberFormat = DecimalFormat("#,##,###")
|
||||
return numberFormat.format(this)
|
||||
|
||||
Reference in New Issue
Block a user