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
val client = NinjatoOkHttpClient(okHttpClient) { | |
retryPolicy = MyRetryPolicy() | |
fallbackPolicy = MyFallbackPolicy() | |
retryPolicy { request, throwable -> | |
if (request.retries > 3) Retry.DoNotRetry else Retry.WithoutDelay | |
} | |
fallbackPolicy { request, throwable -> | |
request.also { it.baseUrl = "https://anotherServer.com" } |
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
class YourRequestFactory : Request.Factory() { | |
override fun create() = YourRequest() | |
} | |
class YourRequestInterceptor : RequestInterceptor() { | |
fun intercept(request: Request): Request { | |
if (request is YourRequest) { | |
request.headers["request_id"] = request.id | |
} | |
} |
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
val client = NinjatoOkHttpClient(okHttpClient) { | |
interceptors += MyRequestInterceptor() | |
interceptors += MyResponseInterceptor() | |
interceptors { | |
request { r -> | |
Log.d(r) | |
r | |
} | |
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
interface YourApi { | |
val api: Api | |
fun putListing(listing: Listing) = api.put { | |
endpointUrl = "/putListing" | |
body = listing | |
} | |
} |
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
class YourApi(client: HttpClient, config: Api.() -> Unit) : Api(client, config) { | |
override val baseUrl = "https://yourApi.com" | |
fun search(query: String): SearchResult = get { | |
endpointUrl = "/search" | |
parameters { "query" to query } | |
} | |
} |
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
class RetryCallEnqueueOnSubscribe<T>( | |
private val originalCall: Call<T> | |
) : OnSubscribe<Response<T>> { | |
private var retries = 0 | |
override fun call(subscriber: Subscriber<in Response<T>>) { | |
val call = originalCall.clone() | |
val headers = call.request() |
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
class SplashActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate() | |
Boots { | |
boot(all()) { | |
onBoot = { report -> sendToAnalytics(report) } | |
onFailure = { report -> logErrors(report) } | |
} | |
} |
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
class MainApplication : Application() { | |
@Inject | |
lateinit var boots: Set<Bootable> | |
fun onCreate() { | |
/* Dagger init */ | |
Boots { | |
add(listOf(boots)) | |
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
Boots { | |
val report = report(all()) | |
} |
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
Boots { | |
// Adding instance of bootable to the system | |
add(DeviceIdBootable(applicationContext)) | |
// Requesting to boot all bootables and saving listener instance | |
listener = boot(all()) { | |
onBoot = { /* do something */ } | |
} | |
} |
NewerOlder