Please use the new one at https://github.com/xee-lab/sdk-android which is based on our new API V4.
This SDK make easier the usage of Xee API on Android devices !
This SDK works for all devices with an Android version >= 14
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'
}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:
-
Create a
XeeEnvwith your credentials informationXeeEnv 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)
-
Use this
XeeEnvto create an instance of APIXee xeeApi = new Xee(xeeEnv);
Here you have the SDK ready to be used.
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
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.
}
});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
}
});xeeApi.getUser()
.enqueue(new XeeRequest.Callback<User>() {
@Override
public void onSuccess(User response) {
// Item response
}
@Override
public void onError(Error error) {
// Handle the error
}
});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
}
});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
}
});All entities from the SDK implement the Parcelable interface, making easier the way to pass data between your components
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
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
}
});We provide a demo app that shows how the SDK might be used
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 !
