Created
July 20, 2022 12:13
-
-
Save AndroidPoet/8a7439a3d7f110cff3b873c2a3a9b02c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log | |
import com.currency.domain.CurrencyConverter | |
import io.ktor.client.* | |
import io.ktor.client.engine.android.* | |
import io.ktor.client.plugins.* | |
import io.ktor.client.plugins.contentnegotiation.* | |
import io.ktor.client.plugins.logging.* | |
import io.ktor.client.plugins.observer.* | |
import io.ktor.serialization.kotlinx.json.* | |
import kotlinx.serialization.json.Json | |
object NetworkClient { | |
private const val TIME_OUT = 60_000 | |
fun buildNetworkClient() = HttpClient(Android) { | |
defaultRequest { | |
url(AppConstants.API_URL) | |
} | |
engine { | |
connectTimeout = TIME_OUT | |
socketTimeout = TIME_OUT | |
} | |
install(Logging) { | |
logger = object : Logger { | |
override fun log(message: String) { | |
Log.d("Logger Ktor =>", message) // We Can use Timber! | |
} | |
} | |
level = LogLevel.ALL | |
} | |
install(ContentNegotiation) { | |
json(Json { | |
prettyPrint = true | |
isLenient = true | |
}) | |
} | |
install(ResponseObserver) { | |
onResponse { response -> | |
Log.d("HTTP status:", "${response.status.value}") // We Can use Timber! | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment