-
-
Save kobeumut/46d7c897a0ac43cae5262a4505fb13f9 to your computer and use it in GitHub Desktop.
Retrofit Settings Sample
This file contains hidden or 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
object MyService { | |
private val TIMEOUTOFSECOND = 15 | |
private val _instanceOfService: Service by lazy { setupHttpClient() } | |
fun on(): Service { | |
return _instanceOfService | |
} | |
private fun setupHttpClient(): Service { | |
val cookieManager = CookieManager() | |
CookieHandler.setDefault(cookieManager) | |
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL) | |
val client = OkHttpClient.Builder() | |
.connectTimeout(TIMEOUTOFSECOND.toLong(), TimeUnit.SECONDS) | |
.writeTimeout(TIMEOUTOFSECOND.toLong(), TimeUnit.SECONDS) | |
.readTimeout(TIMEOUTOFSECOND.toLong(), TimeUnit.SECONDS) | |
.connectionPool(ConnectionPool()) | |
.build() | |
val gson = GsonBuilder().create() | |
val retrofit = Retrofit.Builder() | |
.baseUrl(Config.BaseUrl) | |
.client(client) | |
.addConverterFactory(GsonStringConverterFactory()) | |
.addConverterFactory(GsonConverterFactory.create(gson)) | |
.build() | |
return retrofit.create(Service::class.java) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment