Android SDK for Contacthub
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.idea
gradle/wrapper
sample
sdk
.gitignore
CONTRIBUTING.md
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

Version 0.9.2 beta

Contacthub Android SDK

This repository contains the official Android SDK for Contacthub.

Disclaimer

The current version is intended as an alpha release and should not be used in a production environment, as we still reserve the right to change the underlying APIs.

Because Android applications are considered untrusted, only the APIs that can be accessed with an untrusted source have been implemented in this SDK.

Requirements

  • Android 4.0.3 (API 15) or greater
  • Android Studio 2.x

How to use

Node instantiation

Every request will be performed on a Node in a Workspace. Your application will identify itself as a source and authenticate with a SOURCE_TOKEN.

Node * node = new Node.Builder().setToken('SOURCE_TOKEN').setWorkspaceId('WORKSPACE_ID').setNodeId(`NODE_ID`).create();

Create a customer

On a node you can perform several operation. One of the most common is creating a Customer.

Customer * customer = new Customer("john.doe@example.com","John","Doe");
node.createCustomer(customer, null);

The above is a fire-and-forget request. If you want to know if the operation succeeded or not, pass a ResponseCallback as the second parameter instead of null.

CustomerCallback * customerCallback = new CustomerCallback({
  public void onResponse(Response response) {
    if(response.isSuccessful()) {
      // OK
    } else {
      // Something has gone wrong!
    }
  }
});

Customer * customer = new Customer("john.doe@example.com","John","Doe");
node.createCustomer(customer, customerCallback);

Create an event for an preexisting costumer

String * customerId = customer.getObjectId();

final Event * event = new Event.Builder()
  .setProperties()
  .setCustomerId(customerId)
  .setContext(ContextInfo.MOBILE)
  .setType(Event.GENERIC_ACTIVE_EVENT)
  .setDate(new Date())
  .create();

node.addEvent(mCustomer, event, eventCallback);

Installation

Manually as external module

Clone the repository https://github.com/contactlab/contacthub-sdk-android.git

Edit your project settings.gradle to include the sdk module as external module.

// Your app module
include ':app'

// ContactHub SDK module
include ':sdk'
project(':sdk').projectDir = new File(settingsDir, '../contacthub-sdk-android/sdk')

In the above it is assumed you have cloned the repo in the parent directory of your project. The settingsDir variable is defined by gradle and correspond with your project directory.

Add the sdk module to the dependancies section of your app build.gradle.

dependencies {
    // Your app dependancies
    compile 'com.android.support:support-v4:25.1.0'
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:recyclerview-v7:25.1.0'

    // Contacthub SDK module
    compile project(':sdk')
}

You can also add the module as dependancy via the Project Structure dialog in Android Studio.

Acknowledgments