Skip to content

palimad/percolate-java-sdk

 
 

Repository files navigation

Percolate Java SDK

Circle CI codecov.io

Usage

The SDK is broken up into multiple libraries:

Component Description
core Core objects. Required.
api API requests.
rxjava RxJava objects.
auth OAuth2 helper objects.
android Android-specific objects.
python-bridge Allows core/api usage from python.

Using Gradle / Maven

See our wiki on instructions for adding the libraries to your application using gradle or maven. sbt and leinigen build configuration is also supported.

Usage example

Use the PercolateApi class to access an API endpoint by name. For example, PercolateApi#terms is used to access our v5/terms endpoint. You can then call get(), create(), update(), or delete() on the returned object.

new PercolateApi(API_KEY)
  .terms()
  .get(params);

Extended Example:

PercolateApi percolateApi = new PercolateApi(API_KEY);
TermsParams params = new TermsParams()
  .scopeId("license:12345")
  .search("abc");
Call<Terms> call = percolateApi.terms().get(params);
Terms terms = call.execute().body();  
...  

The returned Call objects can be used in 1 of 2 ways:

Synchronously

Terms terms = call.execute().body();

Asynchronously

call.enqueue(new Callback<Terms>() {

    @Override
    public void onResponse(Call<Terms> call, Response<Terms> response) {
        Terms terms = response.body();
        ...
    }

    @Override
    public void onFailure(Call<Terms> call, Throwable t) { }    
});

Usage with RxJava

If you want to do reactive programming using RxJava then you can use the PercolateApiRx class. The class provides methods that return an Observable for an API endpoint. For example, PercolateApiRx#termsRx returns an object on which get(), create() and update() methods can be invoked to get an Observable. Subscribing to this Observable will you allow to interact with the Terms API.

Example:

PercolateApiRx percolateApi = new PercolateApiRx(API_KEY);
TermsParams params = new TermsParams()
  .scopeId("license:12345")
  .search("abc");
Observable<Terms> observable = percolateApiRx.termsRx().get(params);
observable.subscribe(new Action1<Terms>() {
     @Override
     public void call(Terms terms) {
         ...
     }
});
...

OAuth2 Authentication

This library supports API_KEY authentication or OAuth2 authentication. See the auth module README file and the wiki page for details.

Usage from Python

This is an experimental feature. See python-bridge for details.

License

Distributed under the BSD 3 license. See LICENSE for details.

Packages

No packages published

Languages

  • Java 95.3%
  • Kotlin 4.7%