Skip to content

Instantly share code, notes, and snippets.

val greetingModule = module(createdAtStart = true) {
single<GreetingService> { GreetingServiceImpl(get()) }
single<IpAddressService> { IpAddressServiceImpl(get()) }
}
fun Application.module() {
val jsonParser = Json {
ignoreUnknownKeys = true
isLenient = true
}
install(ContentNegotiation) {
json(jsonParser)
}
val client = HttpClient(Apache) {
fun Application.module() {
val jsonParser = Json {
ignoreUnknownKeys = true
isLenient = true
}
install(ContentNegotiation) {
json(jsonParser)
}
val restTemplate = RestTemplate()
restTemplate.messageConverters = mutableListOf<HttpMessageConverter<*>>(
KotlinSerializationJsonHttpMessageConverter(JsonParser().json)
@Configuration
open class ConfigureMessageConverters() : WebMvcConfigurer {
override fun extendMessageConverters(converters: MutableList<HttpMessageConverter<*>>) {
val converter = KotlinSerializationJsonHttpMessageConverter(JsonParser().json)
converters.forEachIndexed { index, httpMessageConverter ->
if (httpMessageConverter is KotlinSerializationJsonHttpMessageConverter) {
converters[index] = converter
return
}
class JsonParser {
val json = Json { ignoreUnknownKeys = true; isLenient = true; }
}
fun <T> Observable<T>.prodTimeout(timeout: Long, timeUnit: TimeUnit): Observable<T> {
return if (BuildConfig.BUILD_TYPE == "debug" || timeout == 0L) {
this
} else {
this.timeout(timeout, timeUnit)
}
}
private fun loadAppConfig() {
appConfigManager.getAppConfig(pushNotificationManager.deviceId)
.prodTimeout(2500, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.`as`(AutoDispose.autoDisposable(AndroidLifecycleScopeProvider.from(lifecycle, Lifecycle.Event.ON_DESTROY)))
.subscribe({ appConfig -> processAppConfig(appConfig) },
{ throwable -> Timber.e(throwable) })
}
fun getOnboardingInfoAndSmartMessage() {
viewModelScope.launch {
try {
withTimeout(2500) {
onBoardingData.loadWith(this) {
onBoardDispatchManager.getOnboardingInfoAndSmartMessage()
}
}
} catch (error: TimeoutCancellationException) {
onBoardingData.postError(error)
interface GeoFenceService {
/**
* Return a list of [GeofencingResponse] awaiting for collection by given dpid
*/
@GET("geofencing/v1/articles/{dpid}")
fun getGeoFenceArticles(@Path("dpid") dpid: String): Single<List<GeofencingResponse>>
}