VOTO JAVA SDK

Additional

Language
Java
Version
v0.3.0 (Sep 7, 2016)
Created
Mar 18, 2016
Updated
Jan 12, 2024
Owner
Henry Addo (eyedol)
Contributors
Henry Addo (eyedol)
renovate[bot]
2
Activity
Badge
Generate
Download
Source code

VOTO JAVA SDK

VOTO Java SDK is a wrapper around the VOTO API to make it very easy to use. The goal of this SDK is to ease VOTO API integration into both Android and Java applications.

It comes with three independent modules:

  • Synchronous module; Access the API synchronously
  • Asynchronous module; Access the API asynchronously
  • RxJava module; Access the API using RxJava

Note: These are not official libraries from the VOTO team.

###Setup Add gradle dependency:

Add jcenter repostory:

repositories {
    jcenter()
}

Synchronous module:

dependencies {
    compile 'com.addhen:voto-sdk-sync:0.3.0'
}

Asynchronous module:

dependencies {
    compile 'com.addhen:voto-sdk-async:0.3.0'
}

RxJava module:

dependencies {
    compile 'com.addhen:voto-sdk-rxjava:0.3.0'
}

Usage

GET Data From VOTO API

Build API Client
  • Synchronous:
SyncVotoApiClient syncVotoApilient = new SyncVotoApiClient.Builder(<api_key>)
 .withLogLevel(HttpLoggingInterceptor.Level.BODY)
 .build();
  • Asynchronous:
AsyncVotoApiClient asyncVotoClient = new AsyncVotoApiClient.Builder(<api_key>)
 .withLogLevel(HttpLoggingInterceptor.Level.BODY)
 .build();
  • RxJava:
RxJavaVotoApiClient rxVotoClient = new RxJavaVotoApiClient.Builder(<api_key>)
 .withLogLevel(HttpLoggingInterceptor.Level.BODY)
 .build();
Execute API Request
  • Synchronous:
SyncVotoApiClient syncVotoApiClient = new SyncVotoApiClient.Builder("api_key")
 .withLogLevel(HttpLoggingInterceptor.Level.BODY)
 .build();
 
ListSubscribersResponse listSubscribersResponse = null;
try {
    listSubscribersResponse = syncVotoApiClient.listSubscribers(10);
} catch (IOException e) {
    e.printStackTrace();
}

System.out.println(listSubscribersResponse);
  • Asynchronous:
AsyncVotoApiClient asyncVotoApiClient = new AsyncVotoApiClient.Builder("api_key")
 .withLogLevel(HttpLoggingInterceptor.Level.BODY)
 .build();
 
asyncVotoApiClient.listSubscribers(10, new Callback<ListSubscribersResponse>() {
 @Override
    public void onResponse(Call<ListSubscribersResponse> call, Response<ListSubscribersResponse> response) {
    ListSubscribersResponse listSubscribersResponse = response.body();
     System.out.println(listSubscribersResponse);
    }

    @Override
    public void onFailure(Call<ListSubscribersResponse> call, Throwable t) {
     t.printStackTrace();
    }
});
  • RxJava:
RxJavaVotoApiClient rxJavaVotoApiClient = new RxJavaVotoApiClient.Builder("api_key")
 .withLogLevel(HttpLoggingInterceptor.Level.BODY)
 .build();
 
rxJavaVotoApiClient.listSubscribers(10).subscribe(new Action1<ListSubscribersResponse>() {
 @Override
 public void call(ListSubscribersResponse listSubscribersResponse) {
     System.out.println(listSubscribersResponse);
   }
});

Run sample

Make sure you've your VOTO API key set in the local.properties file located in the root directory of the project. The property name should be votoApiKey. If you don't set this, a dummy API key will be used.

After setting the voto api key, issue ./gradlew run. This should run the sample app and output the results in the console.

License

Copyright 2016 Henry Addo Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.