From a48ba80e0e85eaa037ad262f904ad4cc8016efa8 Mon Sep 17 00:00:00 2001 From: Victor Sima Date: Wed, 20 Aug 2014 23:34:09 -0400 Subject: [PATCH 1/3] add cost estimates api call --- .travis.yml | 4 + .../java/com/victorsima/uber/UberService.java | 56 +++++++++++ .../java/com/victorsima/uber/model/Price.java | 95 +++++++++++++++++++ .../com/victorsima/uber/model/Prices.java | 25 +++++ .../victorsima/uber/test/UberClientTest.java | 26 +++++ 5 files changed, 206 insertions(+) create mode 100644 src/main/java/com/victorsima/uber/model/Price.java create mode 100644 src/main/java/com/victorsima/uber/model/Prices.java diff --git a/.travis.yml b/.travis.yml index 2cc9d61..27d4681 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,7 @@ env: - secure: K6WKT4qqLDBlrxrlRysqYmDe7ZCjltcekpxRQFa3EV255p4PfAYdkvS2zejiyrT5Chp3d2Eikk5Yu1GzevYX3BjvnGgBKhZaZne/DnZxWVajTqzbREw5drrzJAofrPWDMc3D8xQy5/NsGWC1uB/v5VK4c14lnuQbJZlT3jiNWfA= - secure: NQyhY89YFVoaDUks9XBuuJSYABzpVZBS+r4b6FZyjvlSIwpW7bYyNZeKo9KBrTEECYPvL2S2+j6TdRDGvpzxIuKj9OmQ0Sw/xl6Nma2cvIhlE+tlGxTdgoYxDWDeld54NT8O22KbRy6QJiWjiHV6/56iOA/5/8hcwBNILCFb9yQ= - secure: x+OuCP9Qo9y9wyEaV7Dw8LqjbBsYKEkq2DbCp3ei1Gpd9N4B9JZJ/OU5Z8w6widy15v/1STWLWruNXkwsa4/7ssyAubpQ/KbFyfQEFK4NjTJvuBoBPmmVGMAVfuwq45RXc6vL5QBK3LoagdDDTBtbnF3L6pWIU3eCv9G7TuZKPw= + - secure: UiseiTT+yq+FLPaYh4sZR1UXw75Hm2HGnt3ACSRwN7EQUpzVz2q8/m1wKEI+tIDGM2kJd+GOGCZj9xKXxwmVkyG9XSeFLivt9JkgdKn4t6KULsRO89sqIBYHG6MirkMdGmt4a646HzRaLfe9LJaHCy7/T12ioauUpPTQNHWoFew= + - secure: asVAo2s431NC9k9pvrwQv4xzs58j5WExnPU6+xZNbHFtJkKPyhTl6ZJWXlGUZjYczyuHHArsaX/D5s0yPPe1IEiBlhka+5xwusm0bOI6n8Vj8LKfCi4PzcA7h6YNMA08MlMxPqGMXEkQDbZQp5+FPlzx4Ru0cDA+NEApObvJnE0= + - secure: YzTbYm25xKsVAH3EoCJ0vPR5g5TqeeiMlpRL1Qlt2IbhqiVyj/T7O3AFiXNBsao+xt3zeinZuZlJL5Do4eh8VisOwPdnWYoPcY9a8kuc2b+7ihFN+GWztE7UkQvxI4v1pPzPzcz5R53kYnyc8nBetx0hIluMNn0PuTVR5fUOKPM= + - secure: D1YgbcQgtvZLXD39laqL2KkvItOsYbYAnBMBcZV64m/9Eb8Jc3TexhaYvCYVMJinCltEL629LwWfy6zklgmmGROgAX+16VPl0ggG4xpJEGfdQ334e30nuH6pgY3o23NembCF06HXA0l1ZCOmrUMfkoWKL5V0W2TqV0Rq+U3MPDg= diff --git a/src/main/java/com/victorsima/uber/UberService.java b/src/main/java/com/victorsima/uber/UberService.java index 757201b..1c3c74b 100644 --- a/src/main/java/com/victorsima/uber/UberService.java +++ b/src/main/java/com/victorsima/uber/UberService.java @@ -1,5 +1,6 @@ package com.victorsima.uber; +import com.victorsima.uber.model.Prices; import com.victorsima.uber.model.Products; import retrofit.Callback; import retrofit.http.GET; @@ -11,11 +12,66 @@ */ public interface UberService { + /** + * 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 + * @param longitude + * @param productsCallback + */ @GET("/products") void getProducts(@Query("latitude") double latitude, @Query("longitude") double longitude, Callback productsCallback); + + /** + * 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 Latitude component of location. + * @param longitude Longitude component of location. + * @return + */ @GET("/products") Products getProducts(@Query("latitude") double latitude, @Query("longitude") double longitude); + + + /** + * 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 Latitude component of start location. + * @param startLongitude Longitude component of start location. + * @param endLatitude Latitude component of end location. + * @param endLongitude Longitude component of end location. + * @param productsCallback + */ + @GET("/estimates/price") + void getPriceEstimates(@Query("start_latitude") double startLatitude, + @Query("start_longitude") double startLongitude, + @Query("end_latitude") double endLatitude, + @Query("end_longitude") double endLongitude, + Callback productsCallback); + + /** + * 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 Latitude component of start location. + * @param startLongitude Longitude component of start location. + * @param endLatitude Latitude component of end location. + * @param endLongitude Longitude component of end location. + * @return + */ + @GET("/estimates/price") + Prices getPriceEstimates(@Query("start_latitude") double startLatitude, + @Query("start_longitude") double startLongitude, + @Query("end_latitude") double endLatitude, + @Query("end_longitude") double endLongitude); } diff --git a/src/main/java/com/victorsima/uber/model/Price.java b/src/main/java/com/victorsima/uber/model/Price.java new file mode 100644 index 0000000..b48ba15 --- /dev/null +++ b/src/main/java/com/victorsima/uber/model/Price.java @@ -0,0 +1,95 @@ +package com.victorsima.uber.model; + + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * Created by victorsima on 8/20/14. + */ +public class Price { + + @Expose + @SerializedName("product_id") + private String productId; + + @Expose + @SerializedName("currency_code") + private String currencyCode;//TODO: parse to java.util.Currency + + @Expose + @SerializedName("display_name") + private String displayName; + + @Expose + @SerializedName("estimate") + private String estimate; + + @Expose + @SerializedName("low_estimate") + private int lowEstimate; + + @Expose + @SerializedName("high_estimate") + private int highEstimate; + + @Expose + @SerializedName("surge_multiplier") + private float surgeMultiplier; + + public String getProductId() { + return productId; + } + + public void setProductId(String productId) { + this.productId = productId; + } + + public String getCurrencyCode() { + return currencyCode; + } + + public void setCurrencyCode(String currencyCode) { + this.currencyCode = currencyCode; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public String getEstimate() { + return estimate; + } + + public void setEstimate(String estimate) { + this.estimate = estimate; + } + + public int getLowEstimate() { + return lowEstimate; + } + + public void setLowEstimate(int lowEstimate) { + this.lowEstimate = lowEstimate; + } + + public int getHighEstimate() { + return highEstimate; + } + + public void setHighEstimate(int highEstimate) { + this.highEstimate = highEstimate; + } + + public float getSurgeMultiplier() { + return surgeMultiplier; + } + + public void setSurgeMultiplier(float surgeMultiplier) { + this.surgeMultiplier = surgeMultiplier; + } +} diff --git a/src/main/java/com/victorsima/uber/model/Prices.java b/src/main/java/com/victorsima/uber/model/Prices.java new file mode 100644 index 0000000..28a45e0 --- /dev/null +++ b/src/main/java/com/victorsima/uber/model/Prices.java @@ -0,0 +1,25 @@ +package com.victorsima.uber.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +/** + * Created by victorsima on 8/20/14. + */ +public class Prices { + + + @Expose + @SerializedName("prices") + private List prices; + + public List getPrices() { + return prices; + } + + public void setPrices(List prices) { + this.prices = prices; + } +} diff --git a/src/test/java/com/victorsima/uber/test/UberClientTest.java b/src/test/java/com/victorsima/uber/test/UberClientTest.java index 9d200c6..1331348 100644 --- a/src/test/java/com/victorsima/uber/test/UberClientTest.java +++ b/src/test/java/com/victorsima/uber/test/UberClientTest.java @@ -1,6 +1,7 @@ package com.victorsima.uber.test; import com.victorsima.uber.UberClient; +import com.victorsima.uber.model.Prices; import com.victorsima.uber.model.Products; import org.junit.After; import org.junit.Before; @@ -22,6 +23,8 @@ public class UberClientTest { private UberClient client; private String latitude, longitude; + private String startLatitude, startLongitude; + private String endLatitude, endLongitude; @Before public void setup() throws Exception { @@ -44,10 +47,20 @@ public void setup() throws Exception { longitude = props.getProperty("uber_product_longitude"); assertNotNull("uber_product_longitude property is null. Make sure you have a test.properties file in " + "/src/test/resources/ directory.", longitude); + + + startLatitude = props.getProperty("uber_price_start_latitude"); + startLongitude = props.getProperty("uber_price_start_longitude"); + endLatitude = props.getProperty("uber_price_end_latitude"); + endLongitude = props.getProperty("uber_price_end_longitude"); } else { serverToken = System.getProperty("uber_server_token"); latitude = System.getProperty("uber_product_latitude"); longitude = System.getProperty("uber_product_longitude"); + startLatitude = System.getProperty("uber_price_start_latitude"); + startLongitude = System.getProperty("uber_price_start_longitude"); + endLatitude = System.getProperty("uber_price_end_latitude"); + endLongitude = System.getProperty("uber_price_end_longitude"); } client = new UberClient("v1", "", "", null, RestAdapter.LogLevel.FULL); @@ -66,4 +79,17 @@ public void testGetProducts() { assertNotNull("get products response is null", products); assertNotNull("products list is null", products.getProducts()); } + + @Test + public void testGetTimeEstimates() { + Prices prices = client.getApiService().getPriceEstimates( + Double.parseDouble(startLatitude), + Double.parseDouble(startLongitude), + Double.parseDouble(endLatitude), + Double.parseDouble(endLongitude)); + + + assertNotNull("get price estimates response is null", prices); + assertNotNull("price estimates list is null", prices.getPrices()); + } } From b800fb0f56301aa27cf7d60533843fac28ca0bd2 Mon Sep 17 00:00:00 2001 From: Victor Sima Date: Thu, 21 Aug 2014 00:17:42 -0400 Subject: [PATCH 2/3] add time estimates api call --- .../java/com/victorsima/uber/UberService.java | 71 +++++++++++-------- .../java/com/victorsima/uber/model/Time.java | 46 ++++++++++++ .../java/com/victorsima/uber/model/Times.java | 24 +++++++ .../victorsima/uber/test/UberClientTest.java | 17 ++++- 4 files changed, 129 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/victorsima/uber/model/Time.java create mode 100644 src/main/java/com/victorsima/uber/model/Times.java diff --git a/src/main/java/com/victorsima/uber/UberService.java b/src/main/java/com/victorsima/uber/UberService.java index 1c3c74b..4202611 100644 --- a/src/main/java/com/victorsima/uber/UberService.java +++ b/src/main/java/com/victorsima/uber/UberService.java @@ -2,6 +2,7 @@ import com.victorsima.uber.model.Prices; import com.victorsima.uber.model.Products; +import com.victorsima.uber.model.Times; import retrofit.Callback; import retrofit.http.GET; import retrofit.http.Header; @@ -12,20 +13,6 @@ */ public interface UberService { - /** - * 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 - * @param longitude - * @param productsCallback - */ - @GET("/products") - void getProducts(@Query("latitude") double latitude, - @Query("longitude") double longitude, - Callback productsCallback); - /** * 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 @@ -37,7 +24,17 @@ void getProducts(@Query("latitude") double latitude, */ @GET("/products") Products getProducts(@Query("latitude") double latitude, - @Query("longitude") double longitude); + @Query("longitude") double longitude); + + /** + * @see #getProducts(double, double) + */ + @GET("/products") + void getProducts(@Query("latitude") double latitude, + @Query("longitude") double longitude, + Callback productsCallback); + + /** @@ -49,7 +46,16 @@ Products getProducts(@Query("latitude") double latitude, * @param startLongitude Longitude component of start location. * @param endLatitude Latitude component of end location. * @param endLongitude Longitude component of end location. - * @param productsCallback + * @return + */ + @GET("/estimates/price") + Prices getPriceEstimates(@Query("start_latitude") double startLatitude, + @Query("start_longitude") double startLongitude, + @Query("end_latitude") double endLatitude, + @Query("end_longitude") double endLongitude); + + /** + * @see #getPriceEstimates(double, double, double, double) */ @GET("/estimates/price") void getPriceEstimates(@Query("start_latitude") double startLatitude, @@ -59,19 +65,28 @@ void getPriceEstimates(@Query("start_latitude") double startLatitude, Callback productsCallback); /** - * 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 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 Latitude component of start location. - * @param startLongitude Longitude component of start location. - * @param endLatitude Latitude component of end location. - * @param endLongitude Longitude component of end location. + * @param startLatitude Latitude component. + * @param startLongitude Longitude component. + * @param customerUUID (optional) Unique customer identifier to be used for experience customization. + * @param productId (optional) Unique identifier representing a specific product for a given latitude & longitude. * @return */ - @GET("/estimates/price") - Prices getPriceEstimates(@Query("start_latitude") double startLatitude, - @Query("start_longitude") double startLongitude, - @Query("end_latitude") double endLatitude, - @Query("end_longitude") double endLongitude); + @GET("/estimates/time") + Times getTimeEstimates(@Query("start_latitude") double startLatitude, + @Query("start_longitude") double startLongitude, + @Query("customer_uuid") String customerUUID, + @Query("product_id") String productId); + + /** + * @see #getTimeEstimates(double, double, String, String) + */ + void getTimeEstimates(@Query("start_latitude") double startLatitude, + @Query("start_longitude") double startLongitude, + @Query("customer_uuid") String customerUUID, + @Query("product_id") String productId, + Callback timesCallback); } diff --git a/src/main/java/com/victorsima/uber/model/Time.java b/src/main/java/com/victorsima/uber/model/Time.java new file mode 100644 index 0000000..763c355 --- /dev/null +++ b/src/main/java/com/victorsima/uber/model/Time.java @@ -0,0 +1,46 @@ +package com.victorsima.uber.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +/** + * Created by victorsima on 8/21/14. + */ +public class Time { + + @Expose + @SerializedName("product_id") + private String productId; + + @Expose + @SerializedName("display_name") + private String displayName; + + @Expose + @SerializedName("estimate") + private int estimate; + + public String getProductId() { + return productId; + } + + public void setProductId(String productId) { + this.productId = productId; + } + + public String getDisplayName() { + return displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public int getEstimate() { + return estimate; + } + + public void setEstimate(int estimate) { + this.estimate = estimate; + } +} diff --git a/src/main/java/com/victorsima/uber/model/Times.java b/src/main/java/com/victorsima/uber/model/Times.java new file mode 100644 index 0000000..052e8b4 --- /dev/null +++ b/src/main/java/com/victorsima/uber/model/Times.java @@ -0,0 +1,24 @@ +package com.victorsima.uber.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +/** + * Created by victorsima on 8/21/14. + */ +public class Times { + + @Expose + @SerializedName("times") + private List