Getting Started
How to implement the Food SDK
The following sections cover how you can get started using Food functionality. You can easily integrate the Food Service by following these steps.
1. Dependencies
Open the main build.gradle file of your project and add the following dependencies:
1 2 3 4 5 6 7 |
|
2. Initialization of the Food Service
The entry point to the Commerce Food Service is the IFoodApi which exposes the APIs needed for getting food specific information.
IFoodApi is exposed to the client by the implementation of IFoodUserServiceProvider → FoodManagerProvider.
IFoodApi
The interface exposes the APIs needed for getting food specific information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
This method initializes or updates the food service. Before interacting with food service, the client is responsible to call this method. In case of a switch to a different environment is desired, the method can be called again with the new endpoint and corresponding api keys and tokens.
The apiEndpoint parameter denotes the Commerce Service environment that we will use.
The default value points to ApiEndpoint.PRODUCTION.
The apiKey represents the unique key used by each integration client in order to use food module functionality.
The apiKeySecret parameter represents the unique key used by each integration client in order to use food module functionality together with apiKey.
The userServiceProvider parameter represents the user dependency required by food service for proper running. View the IFoodUserServiceProvider.
The paymentProvider parameter represents the user dependency required by food service for proper running. View the IFoodPaymentServiceProvider.
It throws com.telenav.commerce.models.network.InitException if called with empty apiKey and apiKeySecret.
1 2 3 4 5 6 7 8 |
|
The getBrands method returns a list of available food brands. If there are no available brands, then it returns an empty list.
1 2 |
|
The getFoodStores method makes a search based on the given location and brand and returns a list of FoodStore. The maximum of retrieve results is 9.
The location parameter represents the location for which the search is done.
The brandId parameter represents the id of the Brand for which the search is done.
It returns the list of the avalilable FoodStore. If there are no food stores available, then it returns an empty list.
1 2 3 4 5 |
|
The getFoodStoresAlongRoute method returns a list of available food stores around the given location, along the provided route, and for the given brand. The results have the first one set as the default store.
The location parameter represents the coordinates around which the search should be done.
The brandId parameter represents the id of the Brand for which the search is done.
The routePoints parameter provides the list of route GeoLocation objects representing the route points.
It returns the list of the available FoodStore. If there are no food stores available, then it returns an empty list.
1 2 3 4 5 6 7 |
|
The getHistory method retrieves user's food orders.
The onlyActive parameter sets if request should return only active orders.
It returns a list of FoodOrderInformation representing the orders placed by an user.
1 2 |
|
IFoodUserServiceProvider
This interface is used for exposing an implementation of the API that is used by the client for accessing the food module functionality.
1 2 3 |
|
The getUserToken method retrieves the user token.
1 |
|
2.1 Recommended initialization of the Food Service
Here is the code on how to initialize food service using the FoodManagerProvider:
1 2 3 4 5 6 7 |
|
Implementation example of IFoodUserServiceProvider
In order to implement the IFoodUserServiceProvider, use the following code.
1 2 3 4 5 |
|
2.2 Initialization of the Food Service with a IFoodCommerceApi provided by the client
If the client needs a specific SDK (network) configuration, then they can initialize the food service passing their own instance of IFoodCommerceApi.
1 2 3 4 5 6 7 |
|
IFoodCommerceApi
This interface represents the entry point to Commerce Service in regards of food flow. It exposes APIs needed for getting food specific information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
The setConfiguration method updates the IHttpApi instance with the given configuration to be used in the communication with commerce service.
1 |
|
The getBrands method returns a list of available food brands. If there are no available brands, then it returns an empty list.
1 |
|
The getFoodStoresAlongRoute method returns a list of available food stores around the given location, along the provided route, and for the given brand.
The location parameter provides the coordinates around which the search should be done.
The brandId parameter represents the id of the Brand for which the search should be done.
The routePoints parameter represents the list of route GeoLocation objects representing the route points.
1 2 3 4 5 |
|
The getDefaultStore method returns a store that matches the default store algorithm described below:
- If there is no previous order history with the merchant(brand)
- If Free Drive:
- If there is a store within 'food search radius' and store if open -> Select nearest store.
- If Active Navigation:
- If there is a store within 'X' minutes (X <= 10) of detour time from current route; store is open.
- Driving time from CVP and store is less than 'Y' mins (Y = 60) -> select the store that is closest (driving time) to the user and has a detour of less X mins
- If Free Drive:
- If there is previous order history with the merchant:
- If Free Drive:
- select the nearest open store from all available order history within 'search radius'
- if no order history store is open and available within the search radius -> select the nearest open store
- If Active Navigation:
- use the same logic as no order history.
- If Free Drive:
The location parameter represents the coordinates around which the search is done.
The brandId parameter represents the id of the Brand for which the search is done.
The routePoints parameter represents the list of route GeoLocation objects representing the route points.
1 2 3 4 5 6 |
|
The getFoodStores method returns a list of available food stores around the given location and for the given brand.
The location parameter represents the coordinates around which the search should be done.
The brandId parameter represents the id of the Brand for which the search is done.
1 2 3 4 |
|
The getFoodHistory method retrieves user's food orders.
The onlyActive parameter sets if request should return only active items.
It returns a list of FoodOrderInformation representing the orders placed by an user.
1 |
|