NTP-12518 | Owais | lazy Retrofit (#272)
This commit is contained in:
@@ -30,7 +30,9 @@ import retrofit2.converter.gson.GsonConverterFactory
|
||||
object AlfredFailureRetrofitProvider {
|
||||
private const val FAILURE_BASE_URL_QA = "https://qa-sa.navi.com/"
|
||||
private const val FAILURE_BASE_URL_PROD = "https://sa.navi.com/"
|
||||
private lateinit var apiService: AlfredFailureRetrofitService
|
||||
val apiService: AlfredFailureRetrofitService by lazy {
|
||||
getRetrofit().create(AlfredFailureRetrofitService::class.java)
|
||||
}
|
||||
private lateinit var okHttpClient: OkHttpClient
|
||||
|
||||
private val networkInterceptor: Interceptor
|
||||
@@ -91,7 +93,6 @@ object AlfredFailureRetrofitProvider {
|
||||
.protocols(listOf(Protocol.HTTP_1_1))
|
||||
}
|
||||
.build()
|
||||
apiService = getRetrofit().create(AlfredFailureRetrofitService::class.java)
|
||||
}
|
||||
|
||||
private fun getRetrofit(): Retrofit {
|
||||
@@ -114,10 +115,6 @@ object AlfredFailureRetrofitProvider {
|
||||
.build()
|
||||
}
|
||||
|
||||
fun getApiService(): AlfredFailureRetrofitService {
|
||||
return apiService
|
||||
}
|
||||
|
||||
private fun loggingInterceptor() =
|
||||
HttpLoggingInterceptor().apply { setLevel(HttpLoggingInterceptor.Level.BODY) }
|
||||
}
|
||||
|
||||
@@ -23,8 +23,13 @@ class AlfredNetworkRepository {
|
||||
apiKey: String,
|
||||
analyticsRequest: AnalyticsRequest
|
||||
): Response<Unit> {
|
||||
return AlfredRetrofitProvider.getApiService()
|
||||
.sendEvents(url, "application/json", ALFRED, apiKey, analyticsRequest)
|
||||
return AlfredRetrofitProvider.apiService.sendEvents(
|
||||
url,
|
||||
"application/json",
|
||||
ALFRED,
|
||||
apiKey,
|
||||
analyticsRequest
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun sendNegativeCase(
|
||||
@@ -32,12 +37,17 @@ class AlfredNetworkRepository {
|
||||
apiKey: String,
|
||||
analyticsRequest: AnalyticsRequest
|
||||
): Response<Unit> {
|
||||
return AlfredRetrofitProvider.getApiService()
|
||||
.sendNegativeCase(url, "application/json", ALFRED, apiKey, analyticsRequest)
|
||||
return AlfredRetrofitProvider.apiService.sendNegativeCase(
|
||||
url,
|
||||
"application/json",
|
||||
ALFRED,
|
||||
apiKey,
|
||||
analyticsRequest
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun getPreSignedUrl(sessionId: String, apiKey: String): Response<PreSignedUrlResponse> {
|
||||
return AlfredRetrofitProvider.getApiService().getPreSignedUrl(sessionId, ALFRED, apiKey)
|
||||
return AlfredRetrofitProvider.apiService.getPreSignedUrl(sessionId, ALFRED, apiKey)
|
||||
}
|
||||
|
||||
suspend fun sendSession(
|
||||
@@ -45,8 +55,13 @@ class AlfredNetworkRepository {
|
||||
apiKey: String,
|
||||
sessionRequest: SessionRequest
|
||||
): Response<Unit> {
|
||||
return AlfredRetrofitProvider.getApiService()
|
||||
.sendSession(url, "application/json", apiKey, ALFRED, sessionRequest)
|
||||
return AlfredRetrofitProvider.apiService.sendSession(
|
||||
url,
|
||||
"application/json",
|
||||
apiKey,
|
||||
ALFRED,
|
||||
sessionRequest
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun sendFailure(
|
||||
@@ -54,12 +69,17 @@ class AlfredNetworkRepository {
|
||||
apiKey: String,
|
||||
failureRequest: FailureRequest
|
||||
): Response<Unit> {
|
||||
return AlfredFailureRetrofitProvider.getApiService()
|
||||
.sendFailure(url, "application/json", ALFRED, apiKey, failureRequest)
|
||||
return AlfredFailureRetrofitProvider.apiService.sendFailure(
|
||||
url,
|
||||
"application/json",
|
||||
ALFRED,
|
||||
apiKey,
|
||||
failureRequest
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun uploadZipToS3(preSignedUrl: String, request: RequestBody): Response<Unit> {
|
||||
return AlfredRetrofitProvider.getApiService().uploadToS3(preSignedUrl, request, ALFRED)
|
||||
return AlfredRetrofitProvider.apiService.uploadToS3(preSignedUrl, request, ALFRED)
|
||||
}
|
||||
|
||||
suspend fun cruiseConfig(
|
||||
@@ -71,20 +91,19 @@ class AlfredNetworkRepository {
|
||||
apiKey: String,
|
||||
cruiseAttributes: CruiseAttributes
|
||||
): Response<CruiseResponse> {
|
||||
return AlfredRetrofitProvider.getApiService()
|
||||
.getCruiseConfig(
|
||||
url,
|
||||
ALFRED,
|
||||
contentType = "application/json",
|
||||
appVersionName = appVersionName,
|
||||
appVersionCode = appVersionCode,
|
||||
osVersion = osVersionCode,
|
||||
deviceId = deviceId,
|
||||
apiKey = apiKey,
|
||||
networkType = cruiseAttributes.networkType,
|
||||
networkStrength = cruiseAttributes.networkStrength.toString(),
|
||||
battery = cruiseAttributes.deviceAttributes?.battery.toString(),
|
||||
memory = cruiseAttributes.deviceAttributes?.memory.toString(),
|
||||
)
|
||||
return AlfredRetrofitProvider.apiService.getCruiseConfig(
|
||||
url,
|
||||
ALFRED,
|
||||
contentType = "application/json",
|
||||
appVersionName = appVersionName,
|
||||
appVersionCode = appVersionCode,
|
||||
osVersion = osVersionCode,
|
||||
deviceId = deviceId,
|
||||
apiKey = apiKey,
|
||||
networkType = cruiseAttributes.networkType,
|
||||
networkStrength = cruiseAttributes.networkStrength.toString(),
|
||||
battery = cruiseAttributes.deviceAttributes?.battery.toString(),
|
||||
memory = cruiseAttributes.deviceAttributes?.memory.toString(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,9 @@ object AlfredRetrofitProvider {
|
||||
private const val BASE_URL_DEBUG = "https://dev-sa.navi.com/"
|
||||
private const val BASE_URL_PROD = "https://alfred-ingester.prod.navi-sa.in/"
|
||||
private const val BASE_URL_QA = "https://qa-alfred-ingester.np.navi-sa.in/"
|
||||
private lateinit var apiService: AlfredRetrofitService
|
||||
val apiService: AlfredRetrofitService by lazy {
|
||||
getRetrofit().create(AlfredRetrofitService::class.java)
|
||||
}
|
||||
private lateinit var okHttpClient: OkHttpClient
|
||||
|
||||
private val networkInterceptor: Interceptor
|
||||
@@ -93,7 +95,6 @@ object AlfredRetrofitProvider {
|
||||
.protocols(listOf(Protocol.HTTP_1_1))
|
||||
}
|
||||
.build()
|
||||
apiService = getRetrofit().create(AlfredRetrofitService::class.java)
|
||||
}
|
||||
|
||||
private fun getRetrofit(): Retrofit {
|
||||
@@ -120,10 +121,6 @@ object AlfredRetrofitProvider {
|
||||
.build()
|
||||
}
|
||||
|
||||
fun getApiService(): AlfredRetrofitService {
|
||||
return apiService
|
||||
}
|
||||
|
||||
private fun loggingInterceptor() =
|
||||
HttpLoggingInterceptor().apply { setLevel(HttpLoggingInterceptor.Level.BODY) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user