项目作者: eyedol

项目描述 :
VOTO Java SDK
高级语言: Java
项目地址: git://github.com/eyedol/voto-java-sdk.git
创建时间: 2016-03-18T21:54:01Z
项目社区:https://github.com/eyedol/voto-java-sdk

开源协议:

下载


Build Status Stories in Ready codecov.io Android Arsenal

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" class="reference-link">Setup

Add gradle dependency:

Add jcenter repostory:

  1. repositories {
  2. jcenter()
  3. }

Synchronous module:

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

Asynchronous module:

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

RxJava module:

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

Usage

GET Data From VOTO API

Build API Client
  • Synchronous:
    1. SyncVotoApiClient syncVotoApilient = new SyncVotoApiClient.Builder(<api_key>)
    2. .withLogLevel(HttpLoggingInterceptor.Level.BODY)
    3. .build();
  • Asynchronous:

    1. AsyncVotoApiClient asyncVotoClient = new AsyncVotoApiClient.Builder(<api_key>)
    2. .withLogLevel(HttpLoggingInterceptor.Level.BODY)
    3. .build();
  • RxJava:

    1. RxJavaVotoApiClient rxVotoClient = new RxJavaVotoApiClient.Builder(<api_key>)
    2. .withLogLevel(HttpLoggingInterceptor.Level.BODY)
    3. .build();
Execute API Request
  • Synchronous:
    ```java
    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);

  1. - Asynchronous:
  2. ```java
  3. AsyncVotoApiClient asyncVotoApiClient = new AsyncVotoApiClient.Builder("api_key")
  4. .withLogLevel(HttpLoggingInterceptor.Level.BODY)
  5. .build();
  6. asyncVotoApiClient.listSubscribers(10, new Callback<ListSubscribersResponse>() {
  7. @Override
  8. public void onResponse(Call<ListSubscribersResponse> call, Response<ListSubscribersResponse> response) {
  9. ListSubscribersResponse listSubscribersResponse = response.body();
  10. System.out.println(listSubscribersResponse);
  11. }
  12. @Override
  13. public void onFailure(Call<ListSubscribersResponse> call, Throwable t) {
  14. t.printStackTrace();
  15. }
  16. });
  • RxJava:
    ```java
    RxJavaVotoApiClient rxJavaVotoApiClient = new RxJavaVotoApiClient.Builder(“api_key”)
    .withLogLevel(HttpLoggingInterceptor.Level.BODY)
    .build();

rxJavaVotoApiClient.listSubscribers(10).subscribe(new Action1() {
@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

  1. Copyright 2016 Henry Addo Open Source Project
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.