Updated on 2026-08-14
This commit is contained in:
parent
aebd525721
commit
fa75773471
13 changed files with 112 additions and 35 deletions
|
|
@ -11,9 +11,12 @@ import kotlinx.coroutines.withContext
|
|||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
class TangemTechService {
|
||||
class TangemTechService(
|
||||
private val logIsEnabled: Boolean = false,
|
||||
) {
|
||||
|
||||
private val headerInterceptors = mutableListOf<AddHeaderInterceptor>(
|
||||
CacheControlHttpInterceptor(cacheMaxAge)
|
||||
CacheControlHttpInterceptor(cacheMaxAge),
|
||||
)
|
||||
|
||||
private var api: TangemTechApi = createApi()
|
||||
|
|
@ -24,7 +27,7 @@ class TangemTechService {
|
|||
active: Boolean? = null,
|
||||
searchText: String? = null,
|
||||
offset: Int? = null,
|
||||
limit: Int? = null
|
||||
limit: Int? = null,
|
||||
): Result<CoinsResponse> = withContext(Dispatchers.IO) {
|
||||
performRequest {
|
||||
api.coins(
|
||||
|
|
@ -33,14 +36,14 @@ class TangemTechService {
|
|||
active = active,
|
||||
searchText = searchText,
|
||||
offset = offset,
|
||||
limit = limit
|
||||
limit = limit,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun rates(
|
||||
currency: String,
|
||||
ids: List<String>
|
||||
ids: List<String>,
|
||||
): Result<RatesResponse> = withContext(Dispatchers.IO) {
|
||||
performRequest {
|
||||
api.rates(currency.lowercase(), ids.joinToString(","))
|
||||
|
|
@ -65,7 +68,7 @@ class TangemTechService {
|
|||
val retrofit = createRetrofitInstance(
|
||||
baseUrl = baseUrl,
|
||||
interceptors = headerInterceptors.toList(),
|
||||
// logEnabled = true,
|
||||
logEnabled = logIsEnabled,
|
||||
)
|
||||
return retrofit.create(TangemTechApi::class.java)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ fun createRetrofitInstance(
|
|||
okHttpBuilder: OkHttpClient.Builder = OkHttpClient.Builder(),
|
||||
interceptors: List<Interceptor> = emptyList(),
|
||||
converterFactory: Converter.Factory = MoshiConverter.createFactory(),
|
||||
logEnabled: Boolean = false
|
||||
logEnabled: Boolean,
|
||||
): Retrofit {
|
||||
okHttpBuilder.apply {
|
||||
callTimeout(10, TimeUnit.SECONDS)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue