A Retrofit 2 CallAdapter.Factory for executing web service calls as Bolts Tasks.
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.
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'
}
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.