Back to project page UPPlatform_Android_SDK.
The source code is released under:
Apache License
If you think the Android project UPPlatform_Android_SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * @author Omer Muhammed/*from w w w .j ava2s. c o m*/ * Copyright 2014 (c) Jawbone. All rights reserved. * */ package com.jawbone.upplatformsdk.api; import com.jawbone.upplatformsdk.utils.UpPlatformSdkConstants; import retrofit.ErrorHandler; import retrofit.RestAdapter; import retrofit.RetrofitError; import retrofit.client.Response; /** * Main class that handles all the API calls */ public class ApiManager { private static RestAdapter restAdapter; private static RestApiInterface restApiInterface; private static ApiHeaders restApiHeaders; private static RestAdapter getRestAdapter() { if (restAdapter == null) { restAdapter = new RestAdapter.Builder() .setRequestInterceptor(getRequestInterceptor()) .setLogLevel(RestAdapter.LogLevel.FULL) .setErrorHandler(new CustomErrorHandler()) .setEndpoint(UpPlatformSdkConstants.API_URL) .build(); } return restAdapter; } //TODO make this more robust private static class CustomErrorHandler implements ErrorHandler { @Override public Throwable handleError(RetrofitError cause) { Response r = cause.getResponse(); if (r != null && r.getStatus() == 401) { return cause.getCause(); } return cause; } } public static RestApiInterface getRestApiInterface() { restAdapter = getRestAdapter(); if (restApiInterface == null) { restApiInterface = restAdapter.create(RestApiInterface.class); } return restApiInterface; } public static ApiHeaders getRequestInterceptor() { if (restApiHeaders == null) { restApiHeaders = new ApiHeaders(); } return restApiHeaders; } }