rlac / retrofitbolts

Retrofit 2 CallAdapter.Factory for Bolts Tasks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bolts Tasks Call Adapter for Retrofit 2

A Retrofit 2 CallAdapter.Factory for executing web service calls as Bolts Tasks.

How to use

Add the BoltsCallAdapterFactory when constructing your Retrofit instance:

new Retrofit.Builder()
    .addCallAdapterFactory(BoltsCallAdapterFactory.create())
    // further configuration
    .build();

Use BoltsCall<T> as the return type for your service interface methods:

interface Service {
    @GET("/fizzbuzz")
    BoltsCall<String> getFizzBuzz();
}

Use the returned BoltsCall to execute the call as a Task on an appropriate Executor:

// call can be made on an immediate, background, or custom executor
// this example uses the background executor
Task<String> getTask = service.getFizzBuzz().background();

Unsuccessful responses throw a HttpException. HttpException includes the error code, deserialized error body if available, and the error body type.

Project setup

Ensure the jitpack repository has been added to your build file:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Add retrofitbolts as a dependency:

dependencies {
    implementation 'com.github.rlac:retrofitbolts:1.1'
}

License

Copyright (C) 2018 Robert Carr

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Retrofit 2 CallAdapter.Factory for Bolts Tasks

License:Apache License 2.0


Languages

Language:Java 100.0%