Skip to content

xee-lab/xee-sdk-android

Repository files navigation

xee-sdk-android

Build Status Release 3.3.2 License Apache

This SDK is now DEPRECATED!

Please use the new one at https://github.com/xee-lab/sdk-android which is based on our new API V4.

Purpose

This SDK make easier the usage of Xee API on Android devices !

Requirements

This SDK works for all devices with an Android version >= 14

Installation

Our SDK is built over jitpack.io.

In order to use this SDK, please do the following:

Add this to your root project build.gradle

repositories {
    jcenter()
    maven {
    	url "https://jitpack.io"
    }
}

Then just add it to the dependencies in the build.gradle module wherever you need the SDK API.

dependencies {
    compile 'com.github.xee-lab.xee-sdk-android:sdk-core:3.3.2'
    compile 'com.github.xee-lab.xee-sdk-android:sdk-api:3.3.2'
}

Setup

Once the SDK is installed, create an application on our developer space to get credentials, see how to create an app

Then initialize the SDK following these steps:

  1. Create a XeeEnv with your credentials information

    XeeEnv xeeEnv = new XeeEnv(context, new OAuth2Client(clientId, clientSecret, redirectUri), 60, 60, environment);

    The environment can be :

    • XeeEnv.CLOUD : production environment (real client data, Authorization needed)
    • XeeEnv.SANDBOX : sandbox environment (fake data, no Authorization needed)
  2. Use this XeeEnv to create an instance of API

    Xee xeeApi = new Xee(xeeEnv);

Here you have the SDK ready to be used.

Usage

Here are some examples of commons methods you might use.

Note that we'll keep this SDK up to date to provide you all the endpoints availables on the 3rd version of the API

Init the SDK / Authenticate the user

Be aware to run this in an UI context ! As it might show a login screen.

xeeApi.connect(new ConnectionCallback(){

    public  void onSuccess(){
        // once here, the SDK is initialized and ready to be used
    }

    public void onError(Throwable error){
        // something went wrong during the authentication.
    }
});

Use the API

All methods return a XeeRequest which allows you to do synchronous or asynchronous requests.

The synchronous way works like this:

// Do the request
XeeRequest<T> fooRequest = xeeApi.fooMethod();
XeeRequest<T>.Response fooResponse = fooRequest.execute();

// Handle possible error
if(fooResponse.error != null){
    // Handle the error
}

T item = fooResponse.item;

The asynchronous way works like this:

// Do the request
XeeRequest<T> fooRequest = xeeApi.fooMethod();
fooRequest.enqueue(new XeeRequest.Callback<T>(){
    public void onSuccess(T response){
        // Item response
    }

    public void onError(Error error){
        // Handle the error
    }
});

Get user information

xeeApi.getUser()
   .enqueue(new XeeRequest.Callback<User>() {
       @Override
       public void onSuccess(User response) {
           // Item response
       }

       @Override
       public void onError(Error error) {
           // Handle the error
       }
   });

Get the cars of the user

xeeApi.getCars()
   .enqueue(new XeeRequest.Callback<List<Car>>() {
       @Override
       public void onSuccess(List<Car> response) {
           // Item response
       }

       @Override
       public void onError(Error error) {
           // Handle the error
       }
   });

Get the trips of the car

xeeApi.getTrips(carId, beginDate, endDate)
   .enqueue(new XeeRequest.Callback<List<Trip>>() {
       @Override
       public void onSuccess(List<Trip> response) {
           // Item response
       }

       @Override
       public void onError(Error error) {
           // Handle the error
       }
   });

Parcelable entity

All entities from the SDK implement the Parcelable interface, making easier the way to pass data between your components

Sign-In button

Use the Sign-In button to sign in with Xee. Three themes and three sizes are provided

  • size: mini, normal, large
  • theme: grey, green, white

xee auth buttons

Use the Sign-In button in layout file

<com.xee.auth.SignInButton
    android:id="@+id/sign_in_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:signInBtnSize="normal"
    app:signInBtnTheme="grey"
    />

You need to set a callback for result when clicking on the button by using the setOnSignInClickResult method and pass the Xee API instance that you have set (see Setup step)

Either you implement the ConnectionCallback interface and override the OnError and OnSuccess methods to handle result in the activity

public class MainActivity extends AppCompatActivity implements ConnectionCallback {
	@Override
    public void onError(@NonNull Throwable error) {
        // sign in failed
    }

    @Override
    public void onSuccess() {
        // sign in success
    }
}

and pass it in the method

signInButton.setOnSignInClickResult(xeeApi, this);

Or you can simply pass an anonymous implementation of ConnectionCallback in the method

signInButton.setOnSignInClickResult(xeeApi, new ConnectionCallback() {
    @Override
    public void onError(@NonNull Throwable error) {
        // sign in failed
    }

    @Override
    public void onSuccess() {
        // sign in success
    }
});

Example

We provide a demo app that shows how the SDK might be used

Issues

We're working hard to provide you an issue free SDK, but we're just humans so we can do mistakes.

If you find something, feel free to fill an issue or/and fork the repository to fix it !

About

[DEPRECATED] An Android SDK for Xee API V3. Please see README update

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages