Move your app forward with the Uber API
The generated code uses a few Maven dependencies e.g., Jackson, OkHttp, and Apache HttpClient. The reference to these dependencies is already added in the pom.xml file will be installed automatically. Therefore, you will need internet access for a successful build.
- In order to open the client library in Eclipse click on
File -> Import
.
- In the import dialog, select
Existing Java Project
and clickNext
.
- Browse to locate the folder containing the source code. Select the detected location of the project and click
Finish
.
- Upon successful import, the project will be automatically built by Eclipse after automatically resolving the dependencies.
The following section explains how to use the UberAPILib library in a new project.
For starting a new project, click the menu command File > New > Project
.
Next, choose Maven > Maven Project
and click Next
.
Here, make sure to use the current workspace by choosing Use default Workspace location
, as shown in the picture below and click Next
.
Following this, select the quick start project type to create a simple project with an existing class and a main
method. To do this, choose maven-archetype-quickstart
item from the list and click Next
.
In the last step, provide a Group Id
and Artifact Id
as shown in the picture below and click Finish
.
The created Maven project manages its dependencies using its pom.xml
file. In order to add a dependency on the UberAPILib client library, double click on the pom.xml
file in the Package Explorer
. Opening the pom.xml
file will render a graphical view on the canvas. Here, switch to the Dependencies
tab and click the Add
button as shown in the picture below.
Clicking the Add
button will open a dialog where you need to specify UberAPILib in Group Id
, uber-apilib in Artifact Id
and 1.0.0 in the Version
fields. Once added click OK
. Save the pom.xml
file.
Once the SimpleConsoleApp
is created, a file named App.java
will be visible in the Package Explorer with a main
method. This is the entry point for the execution of the created project.
Here, you can add code to initialize the client library and instantiate a Controller class. Sample code to initialize the client library and using controller methods is given in the subsequent sections.
The following parameters are configurable for the API Client:
Parameter | Type | Description |
---|---|---|
timeout |
long |
The timeout to use for making HTTP requests. Default: 0L |
httpClientConfig |
ReadonlyHttpClientConfiguration |
Http Client Configuration instance. |
The API client can be initialized as follows:
UberAPIClient client = new UberAPIClient.Builder()
.build();
The generated code and the server can be tested using automatically generated test cases. JUnit is used as the testing framework and test runner.
In Eclipse, for running the tests do the following:
- Select the project UberAPILib from the package explorer.
- Select
Run -> Run as -> JUnit Test
or useAlt + Shift + X
followed byT
to run the Tests.
The gateway for the SDK. This class acts as a factory for the Controllers and also holds the configuration of the SDK.
Name | Description | Return Type |
---|---|---|
getProductsController() |
Provides access to Products controller. | ProductsController |
getEstimatesController() |
Provides access to Estimates controller. | EstimatesController |
getUserController() |
Provides access to User controller. | UserController |
Name | Description | Return Type |
---|---|---|
shutdown() |
Shutdown the underlying HttpClient instance. | void |
getEnvironment() |
Current API environment. | Environment |
getHttpClient() |
The HTTP Client instance to use for making HTTP requests. | HttpClient |
getTimeout() |
The timeout to use for making HTTP requests. | long |
getHttpClientConfig() |
Http Client Configuration instance. | ReadonlyHttpClientConfiguration |
getBaseUri(Server server) |
Get base URI by current environment | String |
getBaseUri() |
Get base URI by current environment | String |
An instance of the ProductsController
class can be accessed from the API Client.
ProductsController productsController = client.getProductsController();
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.
ℹ️ Note This endpoint does not require authentication.
CompletableFuture<ProductList> productTypesAsync(
final double latitude,
final double longitude)
Parameter | Type | Tags | Description |
---|---|---|---|
latitude |
double |
Query, Required | Latitude component of location. |
longitude |
double |
Query, Required | Longitude component of location. |
double latitude = 65.76;
double longitude = 188.04;
productsController.productTypesAsync(latitude, longitude).thenAccept(result -> {
// TODO success callback handler
}).exceptionally(exception -> {
// TODO failure callback handler
return null;
});
HTTP Status Code | Error Description | Exception Class |
---|---|---|
Default | Unexpected error | ErrorException |
An instance of the EstimatesController
class can be accessed from the API Client.
EstimatesController estimatesController = client.getEstimatesController();
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.
The response also includes low and high estimates, and the ISO 4217 currency code for situations requiring currency conversion. When surge is active for a particular product, its surge_multiplier will be greater than 1, but the price estimate already factors in this multiplier.
ℹ️ Note This endpoint does not require authentication.
CompletableFuture<List<PriceEstimate>> priceEstimatesAsync(
final double startLatitude,
final double startLongitude,
final double endLatitude,
final double endLongitude)
Parameter | Type | Tags | Description |
---|---|---|---|
startLatitude |
double |
Query, Required | Latitude component of start location. |
startLongitude |
double |
Query, Required | Longitude component of start location. |
endLatitude |
double |
Query, Required | Latitude component of end location. |
endLongitude |
double |
Query, Required | Longitude component of end location. |
double startLatitude = 163.52;
double startLongitude = 96.76;
double endLatitude = 243.82;
double endLongitude = 205.12;
estimatesController.priceEstimatesAsync(startLatitude, startLongitude, endLatitude, endLongitude).thenAccept(result -> {
// TODO success callback handler
}).exceptionally(exception -> {
// TODO failure callback handler
return null;
});
HTTP Status Code | Error Description | Exception Class |
---|---|---|
Default | Unexpected error | ErrorException |
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.
ℹ️ Note This endpoint does not require authentication.
CompletableFuture<List<Product>> timeEstimatesAsync(
final double startLatitude,
final double startLongitude,
final UUID customerUuid,
final String productId)
Parameter | Type | Tags | Description |
---|---|---|---|
startLatitude |
double |
Query, Required | Latitude component of start location. |
startLongitude |
double |
Query, Required | Longitude component of start location. |
customerUuid |
UUID |
Query, Optional | Unique customer identifier to be used for experience customization. |
productId |
String |
Query, Optional | Unique identifier representing a specific product for a given latitude & longitude. |
double startLatitude = 163.52;
double startLongitude = 96.76;
estimatesController.timeEstimatesAsync(startLatitude, startLongitude, null, null).thenAccept(result -> {
// TODO success callback handler
}).exceptionally(exception -> {
// TODO failure callback handler
return null;
});
HTTP Status Code | Error Description | Exception Class |
---|---|---|
Default | Unexpected error | ErrorException |
An instance of the UserController
class can be accessed from the API Client.
UserController userController = client.getUserController();
The User Profile endpoint returns information about the Uber user that has authorized with the application.
ℹ️ Note This endpoint does not require authentication.
CompletableFuture<Profile> userProfileAsync()
userController.userProfileAsync().thenAccept(result -> {
// TODO success callback handler
}).exceptionally(exception -> {
// TODO failure callback handler
return null;
});
HTTP Status Code | Error Description | Exception Class |
---|---|---|
Default | Unexpected error | ErrorException |
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.
The history array in the response will have a maximum length based on the limit parameter. The response value count may exceed limit, therefore subsequent API requests may be necessary.
ℹ️ Note This endpoint does not require authentication.
CompletableFuture<Activities> userActivityAsync(
final Integer offset,
final Integer limit)
Parameter | Type | Tags | Description |
---|---|---|---|
offset |
Integer |
Query, Optional | Offset the list of returned results by this amount. Default is zero. |
limit |
Integer |
Query, Optional | Number of items to retrieve. Default is 5, maximum is 100. |
userController.userActivityAsync(null, null).thenAccept(result -> {
// TODO success callback handler
}).exceptionally(exception -> {
// TODO failure callback handler
return null;
});
HTTP Status Code | Error Description | Exception Class |
---|---|---|
Default | Unexpected error | ErrorException |
Product
Name | Type | Tags | Description | Getter | Setter |
---|---|---|---|---|---|
ProductId |
String |
Optional | Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles. | String getProductId() | setProductId(String productId) |
Description |
String |
Optional | Description of product. | String getDescription() | setDescription(String description) |
DisplayName |
String |
Optional | Display name of product. | String getDisplayName() | setDisplayName(String displayName) |
Capacity |
Integer |
Optional | Capacity of product. For example, 4 people. | Integer getCapacity() | setCapacity(Integer capacity) |
Image |
String |
Optional | Image URL representing the product. | String getImage() | setImage(String image) |
{
"product_id": null,
"description": null,
"display_name": null,
"capacity": null,
"image": null
}
ProductList
Name | Type | Tags | Description | Getter | Setter |
---|---|---|---|---|---|
Products |
List<Product> |
Optional | Contains the list of products | List getProducts() | setProducts(List products) |
{
"products": null
}
PriceEstimate
Name | Type | Tags | Description | Getter | Setter |
---|---|---|---|---|---|
ProductId |
String |
Optional | Unique identifier representing a specific product for a given latitude & longitude. For example, uberX in San Francisco will have a different product_id than uberX in Los Angeles | String getProductId() | setProductId(String productId) |
CurrencyCode |
String |
Optional | ISO 4217 currency code. | String getCurrencyCode() | setCurrencyCode(String currencyCode) |
DisplayName |
String |
Optional | Display name of product. | String getDisplayName() | setDisplayName(String displayName) |
Estimate |
String |
Optional | Formatted string of estimate in local currency of the start location. Estimate could be a range, a single number (flat rate) or "Metered" for TAXI. | String getEstimate() | setEstimate(String estimate) |
LowEstimate |
Double |
Optional | Lower bound of the estimated price. | Double getLowEstimate() | setLowEstimate(Double lowEstimate) |
HighEstimate |
Double |
Optional | Upper bound of the estimated price. | Double getHighEstimate() | setHighEstimate(Double highEstimate) |
SurgeMultiplier |
Double |
Optional | Expected surge multiplier. Surge is active if surge_multiplier is greater than 1. Price estimate already factors in the surge multiplier. | Double getSurgeMultiplier() | setSurgeMultiplier(Double surgeMultiplier) |
{
"product_id": null,
"currency_code": null,
"display_name": null,
"estimate": null,
"low_estimate": null,
"high_estimate": null,
"surge_multiplier": null
}
Profile
Name | Type | Tags | Description | Getter | Setter |
---|---|---|---|---|---|
FirstName |
String |
Optional | First name of the Uber user. | String getFirstName() | setFirstName(String firstName) |
LastName |
String |
Optional | Last name of the Uber user. | String getLastName() | setLastName(String lastName) |
Email |
String |
Optional | Email address of the Uber user | String getEmail() | setEmail(String email) |
Picture |
String |
Optional | Image URL of the Uber user. | String getPicture() | setPicture(String picture) |
PromoCode |
String |
Optional | Promo code of the Uber user. | String getPromoCode() | setPromoCode(String promoCode) |
{
"first_name": null,
"last_name": null,
"email": null,
"picture": null,
"promo_code": null
}
Activity
Name | Type | Tags | Description | Getter | Setter |
---|---|---|---|---|---|
Uuid |
String |
Optional | Unique identifier for the activity | String getUuid() | setUuid(String uuid) |
{
"uuid": null
}
Activities
Name | Type | Tags | Description | Getter | Setter |
---|---|---|---|---|---|
Offset |
Integer |
Optional | Position in pagination. | Integer getOffset() | setOffset(Integer offset) |
Limit |
Integer |
Optional | Number of items to retrieve (100 max). | Integer getLimit() | setLimit(Integer limit) |
Count |
Integer |
Optional | Total number of items available. | Integer getCount() | setCount(Integer count) |
History |
List<Activity> |
Optional | - | List getHistory() | setHistory(List history) |
{
"offset": null,
"limit": null,
"count": null,
"history": null
}
ErrorException
Name | Type | Tags | Description | Getter | Setter |
---|---|---|---|---|---|
Code |
String |
Optional | - | String getCode() | setCode(String code) |
Message |
String |
Optional | - | String getMessage() | setMessage(String message) |
Fields |
String |
Optional | - | String getFields() | setFields(String fields) |
{
"code": null,
"message": null,
"fields": null
}
This is a Helper class with commonly used utilities for the SDK.
Name | Description | Type |
---|---|---|
mapper | Deserialization of Json data. | ObjectMapper |
Name | Description | Return Type |
---|---|---|
serialize(Object obj) |
Json Serialization of a given object. | String |
deserialize(String json) |
Json deserialization of the given Json string. | LinkedHashMap<String, Object> |
deserialize(String json, Class<T> clazz) |
Json deserialization of the given Json string. | <T extends Object> T |
deserialize(String json, TypeReference<T> typeReference) |
JSON Deserialization of the given json string. | <T extends Object> T |
deserializeArray(String json, Class<T[]> classArray) |
JSON Deserialization of the given json string. | <T extends Object> List<T> |
Class to wrap file and contentType to be sent as part of a HTTP request.
Name | Description |
---|---|
FileWrapper(File file) |
Initialization constructor. |
FileWrapper(File file, String contentType) |
Initialization constructor. |
Name | Description | Return Type |
---|---|---|
getFile() |
File instance. | File |
getContentType() |
Content type of the file. | String |
Class for creating and managing HTTP Requests.
Name | Description |
---|---|
HttpRequest(HttpMethod method, StringBuilder queryUrlBuilder, Headers headers, Map<String, Object> queryParameters, List< SimpleEntry < String, Object >> parameters) |
Initializes a simple http request. |
Name | Description | Return Type |
---|---|---|
getHttpMethod() |
HttpMethod for the http request. | HttpMethod |
getHeaders() |
Headers for the http request. | Headers |
getQueryUrl() |
Query url for the http request. | String |
getParameters() |
Parameters for the http request. | List<SimpleEntry<String, Object>> |
getQueryParameters() |
Query parameters for the http request. | Map<String, Object> |
addQueryParameter(String key, Object value) |
Add Query parameter in http request. | void |
Class to hold HTTP Response.
Name | Description |
---|---|
HttpResponse(int code, Headers headers, InputStream rawBody) |
Constructor for HttpResponse. |
Name | Description | Return Type |
---|---|---|
getStatusCode() |
HTTP Status code of the http response.. | int |
getHeaders() |
Headers of the http response. | Headers |
getRawBody() |
Raw body of the http response. | InputStream |
Class to hold response body as string.
Name | Description |
---|---|
HttpStringResponse(int code, Headers headers, InputStream rawBody, String body) |
Constructor for HttpStringResponse. |
Name | Description | Return Type |
---|---|---|
getStatusCode() |
HTTP Status code of the http response. | int |
getHeaders() |
Headers of the http response. | Headers |
getBody() |
String body of the http response. | String |
Class to wrap the request sent to the server and the response received from the server.
Name | Description |
---|---|
HttpContext(HttpRequest request, HttpResponse response) |
Constructor for HttpContext. |
Name | Description | Return Type |
---|---|---|
getRequest() |
Getter for the Http Request. | HttpRequest |
getHttpContext() |
Getter for the Http Response. | HttpContext |
HTTP Request with an explicit body.
Name | Description |
---|---|
HttpBodyRequest(HttpMethod method, StringBuilder queryUrlBuilder, Headers headers, Map<String, Object> queryParams, Object body) |
Create a request with explicit body. |
Name | Description | Return Type |
---|---|---|
getBody() |
Body for the http request. | Object |
Callback to be called before and after the HTTP call for an endpoint is made.
Name | Description | Return Type |
---|---|---|
onBeforeRequest(HttpRequest request) |
Callback called just before the HTTP request is sent. | void |
onAfterResponse(HttpContext context) |
Callback called just after the HTTP response is received. | void |
Class for creating and managing HTTP Headers.
Name | Description |
---|---|
Headers() |
Default constructor. |
Headers(Map<String, List<String>> headers) |
Constructor that creates a new instance using a given Map. |
Headers(Headers h) |
Copy Constructor. |
Name | Description | Return Type |
---|---|---|
has(String headerName) |
Use to check if the given name is present in headers. | boolean |
names() |
Returns a Set containing all header names. | Set<String> |
value(String headerName) |
Returns the first value associated with a given header name, or null if the header name is not found. | String |
values(String headerName) |
Returns a List of all values associated with a given header name, or null if the header name is not found. | List<String> |
asSimpleMap() |
Returns a Map of the headers, giving only one value for each header name. | Map<String, String> |
asMultimap() |
Returns a simulated MultiMap of the headers. | Map<String, List<String>> |
cloneHeaderMap(Map<String, List<String>> headerMap) |
Clones a header map. | Map<String, List<String>> |
add(String headerName, String value) |
Adds a value for a header name to this object. | void |
add(String headerName, List<String> values) |
Adds a List of values for a header name to this object. | void |
addAllFromMap(Map<String, String> headers) |
Adds values from a Map to this object. | void |
addAllFromMultiMap(Map<String, List<String>> headers) |
Adds values from a simulated Multi-Map to this object. | void |
addAll(Headers headers) |
Adds all the entries in a Headers object to this object. | void |
remove(String headerName) |
Removes the mapping for a header name if it is present. | List<String> |
This is the base class for all exceptions that represent an error response from the server.
Name | Description |
---|---|
ApiException(String reason) |
Initialization constructor. |
ApiException(String reason, HttpContext context) |
Initialization constructor. |
Name | Description | Return Type |
---|---|---|
getResponseCode() |
The HTTP response code from the API request | int |
getHeaders() |
The HTTP response body from the API request. | Headers |
This is the base class for all exceptions that represent an error response from the server.
Name | Description | Return Type |
---|---|---|
getEnvironment() |
Current API environment. | Environment |
getTimeout() |
The timeout to use for making HTTP requests. | long |
getHttpClientConfig() |
Http Client Configuration instance. | ReadonlyHttpClientConfiguration |
getBaseUri(Server server) |
Get base URI by current environment. | String |
getBaseUri() |
Get base URI by current environment. | String |