GithubHelp home page GithubHelp logo

bhanditz / retrofit-kaiteki Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kroegerama/retrofit-kaiteki

0.0 2.0 0.0 192 KB

A collection of Retrofit convenience classes

License: Apache License 2.0

Kotlin 88.89% Java 11.11%

retrofit-kaiteki's Introduction

Release Build Status

Retrofit Kaiteki

A collection of Retrofit convenience classes

Importing the library

1. Add jitpack to your toplevel gradle file:

allprojects {
  repositories {
    ...
    
    /* ADD THE FOLLOWING LINE */
    maven { url 'https://jitpack.io' }
  }
}

2. Add the library to your local gradle file:

dependencies {
  implementation 'com.kroegerama:retrofit-kaiteki:2.0.0'
}

Current components

Retrofit LiveData extension function

Convert any retrofit call to LiveData (Android Architecture Components).

Retrofit DSL

Invoke your retrofit calls using a simple domain specific language.

Debug Interceptor

Allows you to see outgoing requests and the incoming responses in your logcat

Retry Call Annotation

Annotate your retrofit calls and let them automatically be retried. Allows to set the retry count per call.

Cache Call Annotation

Annotate your retrofit calls and let them automatically be cached. Allows to set a debounce time and a maximum age per call.

  • debounce: Load from cache and avoid a network call, if the cached value is younger than specified amount of milliseconds. Set to 0 to disable.
  • maxAge: Load from cache and enqueue a network call, if the cached value is younger than the specified amount of milliseconds. onSuccess() may be called twice. Once with cached data and once with the updated data from network. Set to 0 to disable.

Some examples

See Wiki for more documentation and examples.

DSL

myApi.myCall(param).enqueue {
    onSuccess {
        Log.d("onSuccess", body().toString())
        textView.text = body().toString()
    }
    onNoSuccess {
        Log.d("onNoSuccess", body().toString())
    }
    onFailure { t ->
        Log.d("onFailure", "" + t.toString())
        textView.text = t.toString()
    }
}

LiveData

val listing = myApi.myCall(param).createListing()

val networkStateLiveData = listing.networkState
val resultLiveData = listing.result

listing.retry()

Retry and Cache Annotations

interface MyAPI {
  @Retry(3)
  @Cache(5 * 1000, 10 * 1000)
  @GET("...")
  fun getPost(@Path("id") id: Int): Call<Post>

  @Cache(5 * 1000, 10 * 1000)
  @GET("...")
  fun getPostCachedNoRetry(@Path("id") id: Int): Call<Post>

  @GET("..."")
  fun getPostNoCacheNoRetry(@Path("id") id: Int): Call<Post>
}
public interface MyAPI {
    @Retry(5)
    @Cache(debounce = 1000, maxAge = 5000)
    @GET("...")
    Call<Post> getPost(@Path("id") int id);

    @Cache(debounce = 1000, maxAge = 5000)
    @GET("...")
    Call<Post> getPostCachedNoRetry(@Path("id") int id);

    @GET("...")
    Call<Post> getPostNoCacheNoRetry(@Path("id") int id);
}

retrofit-kaiteki's People

Contributors

kroegerama avatar iqbalhood avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.