Octodroid

Additional

Language
Java
Version
N/A
Created
Jan 11, 2015
Updated
May 2, 2016 (Retired)
Owner
Kentaro Takiguchi (rejasupotaro)
Contributors
Kentaro Takiguchi (rejasupotaro)
Maciej Górski (mg6maciej)
2
Activity
Badge
Generate
Download
Source code
APK file

Blurb

Octodroid

Android toolkit for the GitHub API using RxJava and RxAndroid.

Getting Started

Let's start with a tangible example of how this library works.

GitHub.client().searchRepositories("Android")
        .map(Response::entity)
        .map(SearchResult::getItems)
        .subscribe(repositories -> ...);

As you can see, we lose the callbacks. Fundamentally, RxJava is the Observer pattern, with for manipulating and transforming the stream of data our Observables emit. The Observable emits events, while the Observer subscribes and receives them. In the example above, The .subscribe() call adds an Observer to the Observable and the requests are made.

You should unsubscribe it when Activity is destroyed.

@Override
public void onDestroy() {
    subscription.unsubscribe();
    super.onDestroy();
}

If you use ViewObservable of RxAndroid, you don't need to call unsubscribe() explicitly. ViewObservable calls unsubscribe() automatically when view is detached.

ViewObservable.bindView(view, GitHub.client().user())
        .subscribe(user -> ...);

APIs

GitHub.client().user("rejasupotaro")
GitHub.client().search()
GitHub.client().searchRepositories("Android")
GitHub.client().hottestRepositories()
GitHub.client().userRepos()

// You can access these API if you have authenticated
GitHub.client().user()
GitHub.client().notifications()

Authentication

// You can give access token OAuth2
GitHub.client().authorize("access_token");
// or use basic authentication
GitHub.client().authorize("username", "password");

GitHub.client().user()
        .map(Response::entity)
        .subscribe(user -> ...);

Set User-Agent

GitHub.client().userAgent(userAgent);

Enable Cache-Control

CacheControl cacheControl = new CacheControl.Builder()
        // cache file is required
        .file(context)                 // use /data/data/package.name/cache/octodroid_response_cache when given context
//        .file(dir, "file_name")      // or give dir and file name
//        .file(file)                  // or give file
        .maxCacheSize(3 * 1024 * 1024) // default max cache size is 3MB
        .maxStale(28 * 24 * 60 * 60)   // default max stale is 3 weeks
        .build();

ApiClient apiClient = new ApiClient();
apiClient.cache(cacheControl);

GitHub.initialize(apiClient);

Download

Download the latest JAR or grab via gradle:

compile 'com.rejasupotaro:octodroid:0.1.2'