RetroBuilder is an helper module for retrofit with added new features like authentication interceptor, enabled logging interceptor, and gson interceptor. Now migrated to kotlin.
repositories {
jcenter()
}
dependencies {
implementation 'site.business.appslandz:retrobuilder:X.X.X'
}
android {
...
....
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
public interface ApiInterface {
@GET("/api/users")
Call<ApiResponse<List<User>>> getAllUsers();
}
Call<ApiResponse<List<User>>> call = ApiClient.getInstance(this)
.setBaseUrl("https://reqres.in")
.getAuthClient(new AuthInitializer() {
@Override
public String getBearerToken() {
return "Bearer 129318309809843589350938509893540832945";
}}).create(ApiInterface.class)
.getAllUsers();
Call<ApiResponse<List<User>>> call = ApiClient.getInstance(this)
.setBaseUrl("https://reqres.in")
.getClient().create(ApiInterface.class)
.getAllUsers();
call.enqueue(new Callback<ApiResponse<List<User>>>() {
@Override
public void onResponse(Call<ApiResponse<List<User>>> call, Response<ApiResponse<List<User>>> respons
Timber.i(response.body().toString());
}
@Override
public void onFailure(Call<ApiResponse<List<User>>> call, Throwable t) {
call.cancel();
}});
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.