Skip to content

RetroBuilder is an helper module developed in kotlin for retrofit

Notifications You must be signed in to change notification settings

profahad/RetroBuilder

Repository files navigation

RetroBuilder

RetroBuilder is an helper module for retrofit with added new features like authentication interceptor, enabled logging interceptor, and gson interceptor. Now migrated to kotlin.

Download

Installation

Add the jCenter repository to your build file

repositories {
    jcenter()
}

Add the dependency

dependencies {
    implementation 'site.business.appslandz:retrobuilder:X.X.X'
}

Add Compatibility version tag

android {
    ...
    ....
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

Usage

i. Retrofit api service interface

public interface ApiInterface {

    @GET("/api/users")
    Call<ApiResponse<List<User>>> getAllUsers();

}

ii. Create auth call with bearer

 
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();

Or create simple call

 
Call<ApiResponse<List<User>>> call = ApiClient.getInstance(this)
                .setBaseUrl("https://reqres.in")
                .getClient().create(ApiInterface.class)
                .getAllUsers();

iii. Enqueue call to request queue

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();
     }});

Contributing

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.

License

Apache 2.0

About

RetroBuilder is an helper module developed in kotlin for retrofit

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published