Android Open Source - uber-android A P I Controller






From Project

Back to project page uber-android.

License

The source code is released under:

MIT License

If you think the Android project uber-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * UberAPILib//  w w w.jav  a  2 s .  c  o  m
 *
 * This file was automatically generated by APIMATIC BETA v2.0 on 08/22/2014
 */
package io.apimatic.uberapilib.controllers;
import java.io.*;
import java.util.*;
import java.util.concurrent.*;
import com.fasterxml.jackson.core.type.TypeReference;
import com.mashape.unirest.request.*;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import io.apimatic.uberapilib.*;
import io.apimatic.uberapilib.models.*;

public class APIController {
    /**
     * The Products endpoint returns information about the Uber products offered at a given location. The response includes the display name and other details about each product, and lists the products in the proper display order.
     * @param    latitude    Required parameter: Latitude component of location.
     * @param    longitude    Required parameter: Longitude component of location.
   * @return  Returns the ProductCollectionModel response from the API call*/
    public Future<ProductCollectionModel> getProductsAsync (
            final double latitude,
            final double longitude
            ) {
        //the base uri for api requests
        String baseUri = Configuration.baseUri;

        //prepare query string for API call
        StringBuilder queryBuilder = new StringBuilder(baseUri);
        queryBuilder.append("/v1/products");

        //process optional query parameters
        APIHelper.appendUrlWithQueryParameters(queryBuilder, new HashMap<String, Object>() {
            private static final long serialVersionUID = 5659883235789524689L;
            {
                    put( "latitude", latitude );
                    put( "longitude", longitude );
            }});

        //validate and preprocess url
        String queryUrl = APIHelper.cleanUrl(queryBuilder);

        //prepare and invoke the API call request to fetch the response
        HttpRequest request = Unirest.get(queryUrl);

        //append request with appropriate headers and parameters
        request.header("accept", "application/json")
                .header("Authorization", String.format("Bearer %1$s", Configuration.oAuthAccessToken));

        //invoke request and get response
        final Future<HttpResponse<String>> responseAsync = request.asStringAsync();
        return new FutureTask<ProductCollectionModel>(new Callable<ProductCollectionModel>() {
            public ProductCollectionModel call() throws IOException, APIException, ExecutionException, InterruptedException {
                //execute and get response from async task
                HttpResponse<String> response = responseAsync.get();

                //Error handling using HTTP status codes
                int responseCode = response.getCode();
                if (responseCode == 400)
                    throw new APIException("Malformed request.", 400);

                else if (responseCode == 401)
                    throw new APIException("Unauthorized the request requires user authentication (not logged in).", 401);

                else if (responseCode == 403)
                    throw new APIException("Forbidden. Also used for unauthorized requests such as improper OAuth 2.0 scopes or permissions issues.", 403);

                else if (responseCode == 404)
                    throw new APIException("Not found.", 404);

                else if (responseCode == 406)
                    throw new APIException("Unacceptable content type. Client sent an accepts header for a content type which does not exist on the server. Body includes a list of acceptable content types: Unacceptable content type. Request resource as: application/json, etc.", 406);

                else if (responseCode == 422)
                    throw new APIException("Invalid request. The request body is parse-able however with invalid content.", 422);

                else if (responseCode == 429)
                    throw new APIException("Too Many Requests. Rate limited.", 429);

                else if (responseCode == 500)
                    throw new APIException("Internal Server Error.", 500);

                else if (responseCode != 200) //200 = HTTP OK
                    throw new APIException("HTTP Response Not OK", responseCode);

                return APIHelper.jsonDeserialize(response.getBody(),
                 new TypeReference<ProductCollectionModel>(){});
        }});
    }
        
    /**
     * The Price Estimates endpoint returns an estimated price range for each product offered at a given location. The price estimate is provided as a formatted string with the full price range and the localized currency symbol.
     * @param    startLatitude    Required parameter: Latitude component of start location.
     * @param    startLongitude    Required parameter: Longitude component of start location.
     * @param    endLatitude    Required parameter: Latitude component of end location.
     * @param    endLongitude    Required parameter: Longitude component of end location.
   * @return  Returns the PriceEstimateCollectionModel response from the API call*/
    public Future<PriceEstimateCollectionModel> getPriceEstimatesAsync (
            final double startLatitude,
            final double startLongitude,
            final double endLatitude,
            final double endLongitude
            ) {
        //the base uri for api requests
        String baseUri = Configuration.baseUri;

        //prepare query string for API call
        StringBuilder queryBuilder = new StringBuilder(baseUri);
        queryBuilder.append("/v1/estimates/price");

        //process optional query parameters
        APIHelper.appendUrlWithQueryParameters(queryBuilder, new HashMap<String, Object>() {
            private static final long serialVersionUID = 4621328737372838362L;
            {
                    put( "start_latitude", startLatitude );
                    put( "start_longitude", startLongitude );
                    put( "end_latitude", endLatitude );
                    put( "end_longitude", endLongitude );
            }});

        //validate and preprocess url
        String queryUrl = APIHelper.cleanUrl(queryBuilder);

        //prepare and invoke the API call request to fetch the response
        HttpRequest request = Unirest.get(queryUrl);

        //append request with appropriate headers and parameters
        request.header("accept", "application/json")
                .header("Authorization", String.format("Bearer %1$s", Configuration.oAuthAccessToken));

        //invoke request and get response
        final Future<HttpResponse<String>> responseAsync = request.asStringAsync();
        return new FutureTask<PriceEstimateCollectionModel>(new Callable<PriceEstimateCollectionModel>() {
            public PriceEstimateCollectionModel call() throws IOException, APIException, ExecutionException, InterruptedException {
                //execute and get response from async task
                HttpResponse<String> response = responseAsync.get();

                //Error handling using HTTP status codes
                int responseCode = response.getCode();
                if (responseCode == 400)
                    throw new APIException("Malformed request.", 400);

                else if (responseCode == 401)
                    throw new APIException("Unauthorized the request requires user authentication (not logged in).", 401);

                else if (responseCode == 403)
                    throw new APIException("Forbidden. Also used for unauthorized requests such as improper OAuth 2.0 scopes or permissions issues.", 403);

                else if (responseCode == 404)
                    throw new APIException("Not found.", 404);

                else if (responseCode == 406)
                    throw new APIException("Unacceptable content type. Client sent an accepts header for a content type which does not exist on the server. Body includes a list of acceptable content types: Unacceptable content type. Request resource as: application/json, etc.", 406);

                else if (responseCode == 422)
                    throw new APIException("Invalid request. The request body is parse-able however with invalid content.", 422);

                else if (responseCode == 429)
                    throw new APIException("Too Many Requests. Rate limited.", 429);

                else if (responseCode == 500)
                    throw new APIException("Internal Server Error.", 500);

                else if (responseCode != 200) //200 = HTTP OK
                    throw new APIException("HTTP Response Not OK", responseCode);

                return APIHelper.jsonDeserialize(response.getBody(),
                 new TypeReference<PriceEstimateCollectionModel>(){});
        }});
    }
        
    /**
     * The Time Estimates endpoint returns ETAs for all products offered at a given location, with the responses expressed as integers in seconds. We recommend that this endpoint be called every minute to provide the most accurate, up-to-date ETAs.
     * @param    startLatitude    Required parameter: Latitude component of the start location
     * @param    startLongitude    Required parameter: Longitude component of the start location
     * @param    customerUuid    Optional parameter: The customer id interested in estimate
     * @param    productId    Optional parameter: Id of the requested product
   * @return  Returns the TimeEstimateCollectionModel response from the API call*/
    public Future<TimeEstimateCollectionModel> getTimeEstimatesAsync (
            final double startLatitude,
            final double startLongitude,
            final String customerUuid,
            final String productId
            ) {
        //the base uri for api requests
        String baseUri = Configuration.baseUri;

        //prepare query string for API call
        StringBuilder queryBuilder = new StringBuilder(baseUri);
        queryBuilder.append("/v1/estimates/time");

        //process optional query parameters
        APIHelper.appendUrlWithQueryParameters(queryBuilder, new HashMap<String, Object>() {
            private static final long serialVersionUID = 4659638116524460108L;
            {
                    put( "start_latitude", startLatitude );
                    put( "start_longitude", startLongitude );
                    put( "customer_uuid", customerUuid );
                    put( "product_id", productId );
            }});

        //validate and preprocess url
        String queryUrl = APIHelper.cleanUrl(queryBuilder);

        //prepare and invoke the API call request to fetch the response
        HttpRequest request = Unirest.get(queryUrl);

        //append request with appropriate headers and parameters
        request.header("accept", "application/json")
                .header("Authorization", String.format("Bearer %1$s", Configuration.oAuthAccessToken));

        //invoke request and get response
        final Future<HttpResponse<String>> responseAsync = request.asStringAsync();
        return new FutureTask<TimeEstimateCollectionModel>(new Callable<TimeEstimateCollectionModel>() {
            public TimeEstimateCollectionModel call() throws IOException, APIException, ExecutionException, InterruptedException {
                //execute and get response from async task
                HttpResponse<String> response = responseAsync.get();

                //Error handling using HTTP status codes
                int responseCode = response.getCode();
                if (responseCode == 400)
                    throw new APIException("Malformed request.", 400);

                else if (responseCode == 401)
                    throw new APIException("Unauthorized the request requires user authentication (not logged in).", 401);

                else if (responseCode == 403)
                    throw new APIException("Forbidden. Also used for unauthorized requests such as improper OAuth 2.0 scopes or permissions issues.", 403);

                else if (responseCode == 404)
                    throw new APIException("Not found.", 404);

                else if (responseCode == 406)
                    throw new APIException("Unacceptable content type. Client sent an accepts header for a content type which does not exist on the server. Body includes a list of acceptable content types: Unacceptable content type. Request resource as: application/json, etc.", 406);

                else if (responseCode == 422)
                    throw new APIException("Invalid request. The request body is parse-able however with invalid content.", 422);

                else if (responseCode == 429)
                    throw new APIException("Too Many Requests. Rate limited.", 429);

                else if (responseCode == 500)
                    throw new APIException("Internal Server Error.", 500);

                else if (responseCode != 200) //200 = HTTP OK
                    throw new APIException("HTTP Response Not OK", responseCode);

                return APIHelper.jsonDeserialize(response.getBody(),
                 new TypeReference<TimeEstimateCollectionModel>(){});
        }});
    }
        
    /**
     * The User Activity endpoint returns data about a user's lifetime activity with Uber. The response will include pickup locations and times, dropoff locations and times, the distance of past requests, and information about which products were requested.
     * @param    offset    Required parameter: Page offset for pagging
     * @param    limit    Required parameter: Number of items to return for pagging
   * @return  Returns the UserActivityModel response from the API call*/
    public Future<UserActivityModel> getUserActivityAsync (
            final int offset,
            final int limit
            ) {
        //the base uri for api requests
        String baseUri = Configuration.baseUri;

        //prepare query string for API call
        StringBuilder queryBuilder = new StringBuilder(baseUri);
        queryBuilder.append("/v1/history");

        //process optional query parameters
        APIHelper.appendUrlWithQueryParameters(queryBuilder, new HashMap<String, Object>() {
            private static final long serialVersionUID = 5465107307302128885L;
            {
                    put( "offset", offset );
                    put( "limit", limit );
            }});

        //validate and preprocess url
        String queryUrl = APIHelper.cleanUrl(queryBuilder);

        //prepare and invoke the API call request to fetch the response
        HttpRequest request = Unirest.get(queryUrl);

        //append request with appropriate headers and parameters
        request.header("accept", "application/json")
                .header("Authorization", String.format("Bearer %1$s", Configuration.oAuthAccessToken));

        //invoke request and get response
        final Future<HttpResponse<String>> responseAsync = request.asStringAsync();
        return new FutureTask<UserActivityModel>(new Callable<UserActivityModel>() {
            public UserActivityModel call() throws IOException, APIException, ExecutionException, InterruptedException {
                //execute and get response from async task
                HttpResponse<String> response = responseAsync.get();

                //Error handling using HTTP status codes
                int responseCode = response.getCode();
                if (responseCode == 400)
                    throw new APIException("Malformed request.", 400);

                else if (responseCode == 401)
                    throw new APIException("Unauthorized the request requires user authentication (not logged in).", 401);

                else if (responseCode == 403)
                    throw new APIException("Forbidden. Also used for unauthorized requests such as improper OAuth 2.0 scopes or permissions issues.", 403);

                else if (responseCode == 404)
                    throw new APIException("Not found.", 404);

                else if (responseCode == 406)
                    throw new APIException("Unacceptable content type. Client sent an accepts header for a content type which does not exist on the server. Body includes a list of acceptable content types: Unacceptable content type. Request resource as: application/json, etc.", 406);

                else if (responseCode == 422)
                    throw new APIException("Invalid request. The request body is parse-able however with invalid content.", 422);

                else if (responseCode == 429)
                    throw new APIException("Too Many Requests. Rate limited.", 429);

                else if (responseCode == 500)
                    throw new APIException("Internal Server Error.", 500);

                else if (responseCode != 200) //200 = HTTP OK
                    throw new APIException("HTTP Response Not OK", responseCode);

                return APIHelper.jsonDeserialize(response.getBody(),
                 new TypeReference<UserActivityModel>(){});
        }});
    }
        
    /**
     * The User Profile endpoint returns information about the Uber user that has authorized with the application.
   * @return  Returns the UserProfileModel response from the API call*/
    public Future<UserProfileModel> getUserProfileAsync (
            ) {
        //the base uri for api requests
        String baseUri = Configuration.baseUri;

        //prepare query string for API call
        StringBuilder queryBuilder = new StringBuilder(baseUri);
        queryBuilder.append("/v1/me");

        //validate and preprocess url
        String queryUrl = APIHelper.cleanUrl(queryBuilder);

        //prepare and invoke the API call request to fetch the response
        HttpRequest request = Unirest.get(queryUrl);

        //append request with appropriate headers and parameters
        request.header("accept", "application/json")
                .header("Authorization", String.format("Bearer %1$s", Configuration.oAuthAccessToken));

        //invoke request and get response
        final Future<HttpResponse<String>> responseAsync = request.asStringAsync();
        return new FutureTask<UserProfileModel>(new Callable<UserProfileModel>() {
            public UserProfileModel call() throws IOException, APIException, ExecutionException, InterruptedException {
                //execute and get response from async task
                HttpResponse<String> response = responseAsync.get();

                //Error handling using HTTP status codes
                int responseCode = response.getCode();
                if (responseCode == 400)
                    throw new APIException("Malformed request.", 400);

                else if (responseCode == 401)
                    throw new APIException("Unauthorized the request requires user authentication (not logged in).", 401);

                else if (responseCode == 403)
                    throw new APIException("Forbidden. Also used for unauthorized requests such as improper OAuth 2.0 scopes or permissions issues.", 403);

                else if (responseCode == 404)
                    throw new APIException("Not found.", 404);

                else if (responseCode == 406)
                    throw new APIException("Unacceptable content type. Client sent an accepts header for a content type which does not exist on the server. Body includes a list of acceptable content types: Unacceptable content type. Request resource as: application/json, etc.", 406);

                else if (responseCode == 422)
                    throw new APIException("Invalid request. The request body is parse-able however with invalid content.", 422);

                else if (responseCode == 429)
                    throw new APIException("Too Many Requests. Rate limited.", 429);

                else if (responseCode == 500)
                    throw new APIException("Internal Server Error.", 500);

                else if (responseCode != 200) //200 = HTTP OK
                    throw new APIException("HTTP Response Not OK", responseCode);

                return APIHelper.jsonDeserialize(response.getBody(),
                 new TypeReference<UserProfileModel>(){});
        }});
    }
        
}




Java Source Code List

io.apimatic.uberapilib.APIException.java
io.apimatic.uberapilib.APIHelper.java
io.apimatic.uberapilib.Configuration.java
io.apimatic.uberapilib.controllers.APIController.java
io.apimatic.uberapilib.models.HistoryModel.java
io.apimatic.uberapilib.models.LocationModel.java
io.apimatic.uberapilib.models.PriceEsitmateModel.java
io.apimatic.uberapilib.models.PriceEstimateCollectionModel.java
io.apimatic.uberapilib.models.ProductCollectionModel.java
io.apimatic.uberapilib.models.ProductModel.java
io.apimatic.uberapilib.models.TimeEstimateCollectionModel.java
io.apimatic.uberapilib.models.TimeEstimateModel.java
io.apimatic.uberapilib.models.UserActivityModel.java
io.apimatic.uberapilib.models.UserProfileModel.java