Skip to content

Commit

Permalink
fix api
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimrod Lahav committed Apr 5, 2016
1 parent f629696 commit 491579a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
5 changes: 1 addition & 4 deletions src/main/java/com/waze/service/WazeNotificationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public class WazeNotificationService {

ObjectMapper mapper = new ObjectMapper();
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();

private static String genNotificationUrl(String server, String left, String right, String top, String bottom){
return "https://www.waze.com/" + server + "/web/TGeoRSS?left="
Expand All @@ -34,8 +35,6 @@ public WazeTrafficNotificationsResponse getNotifications(String left, String rig
ArrayList<WazeJam> jams = new ArrayList<>();


AsyncHttpClient asyncHttpClient = new AsyncHttpClient();

try{
for (String server: serverList){
url = genNotificationUrl(server, left, right, top, bottom);
Expand Down Expand Up @@ -83,8 +82,6 @@ public WazeTrafficNotificationsResponse getNotifications(String left, String rig
}
}catch (Exception ex) {
throw new RuntimeException("failed to get notifications \nurl: "+ url + "\nerror: "+ ex.getMessage());
}finally {
asyncHttpClient.close();
}

wazeTrafficNotificationsResponse.setAlerts(alerts);
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/com/waze/service/WazeRouteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
public class WazeRouteService {

AsyncHttpClient asyncHttpClient = new AsyncHttpClient();


boolean singleAddress = true;
boolean multipleAddress = false;
ObjectMapper mapper = new ObjectMapper();
Expand Down Expand Up @@ -200,10 +203,9 @@ public WazeRouteResponse getRoutes(String start, String end) {

public ArrayList<JsonNode> sendRouteRequest(String routeUrl){
ArrayList<JsonNode> routes = new ArrayList<>();
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
try{
Response response = asyncHttpClient
.preparePost(routeUrl)
.prepareGet(routeUrl)
.execute()
.get();

Expand All @@ -220,20 +222,17 @@ public ArrayList<JsonNode> sendRouteRequest(String routeUrl){
}
}catch (Exception ex) {
throw new RuntimeException("failed to query waze route \nurl: " + routeUrl + " \nerror: "+ ex.getMessage());
}finally {
asyncHttpClient.close();
}

return routes;
}

public JsonNode getAddress(String address, boolean single){
AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
String addressURL = "";
try {
addressURL = "https://www.waze.com/SearchServer/mozi?q=" + URLEncoder.encode(address, "UTF-8") + "&lang=eng&lon=-73.96888732910156%20&lat=40.799981900731964&origin=livemap";
Response response = asyncHttpClient
.preparePost(addressURL)
.prepareGet(addressURL)
.execute().get();
if (single)
return mapper.readTree(response.getResponseBody()).get(0);
Expand All @@ -242,8 +241,6 @@ public JsonNode getAddress(String address, boolean single){

}catch (Exception ex) {
throw new WazeException("failed to query waze address \nurl: " + addressURL + " \nerror: "+ ex.getMessage());
}finally {
asyncHttpClient.close();
}
}

Expand Down
13 changes: 0 additions & 13 deletions src/test/java/com/waze/WazeRouteServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ public class WazeRouteServiceTest {
WazeNotificationService wazeNotificationService = new WazeNotificationService();

@Test
@Ignore
public void getNotificationTest(){
WazeTrafficNotificationsResponse res = wazeNotificationService.getNotifications("34.560293197631836", "35.08736228942871", "32.126451488404435", "31.967679380737046");
assert(res.getAlerts().size() >= 1);
assert(res.getJams().size() >= 1);
}

@Test
@Ignore
public void testWazeRouteWithDirection(){
WazeRouteWithDirectionsResponse res = wazeRouteService.getRouteWithParts("40.7794034", "-73.9525884", "40.7866205", "-73.9773711", null, null);
assert(res.getRoutesWithDirections().size() >= 1);
Expand All @@ -40,7 +38,6 @@ public void testWazeRouteWithDirection(){
}

@Test
@Ignore
public void testWazeRoutesWithDirectionText(){
WazeRouteWithDirectionsResponse res = wazeRouteService.getRouteWithParts("1712 Kilbourne Pl NW, Washington, DC 20010", "2150 K St NW, Washington, DC 20427");
assert(res.getRoutesWithDirections().size() >= 1);
Expand All @@ -50,37 +47,32 @@ public void testWazeRoutesWithDirectionText(){


@Test
@Ignore
public void testWazeGetAddressApi(){
JsonNode addressResult = wazeRouteService.getAddress("5th avenue new york", true);
String addressResultStr = addressResult.get("name").asText();
assert(addressResultStr.contains("5th"));
}

@Test
@Ignore
public void testWazeRouteApi(){
ArrayList<JsonNode> routeResult = wazeRouteService.sendRouteRequest("https://www.waze.com/RoutingManager/routingRequest?from=x%3A-73.96537017822266+y%3A40.77473068237305&to=x%3A-73.99018859863281+y%3A40.751678466796875&at=0&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=3&options=AVOID_TRAILS%3At");
String routeName = routeResult.get(0).get("response").get("routeName").asText();
assert(!routeName.equals(""));
}

@Test
@Ignore
public void testWazeGetRoutesRequest(){
WazeRouteResponse routeResult = wazeRouteService.getRoutes("5th Avenue, Manhattan, New York, NY, United States", "Queens Blvd, Queens, NY, United States");
assert(routeResult.getStartPoint().contains("Avenue"));
assert(routeResult.getEndPoint().contains("Queens"));
}

@Test(expected=WazeException.class)
@Ignore
public void testWazeGetRoutesRequestReturnErrorWhenUserRouteToLong(){
wazeRouteService.getRoutes("5th Avenue, Manhattan, New York, NY, United States", "3722 Crenshaw Blvd Los Angeles");
}

@Test
@Ignore
public void testWazeGetRoutesReturnSingleRequestFromUSA(){
WazeRouteResponse wazeRouteResponse = wazeRouteService.getRoutes("153 5th Ave, Manhattan, NY, United States", "123 5th Avenue, New York, NY 10003");
assert(wazeRouteResponse.getRoutes().size() == 1);
Expand All @@ -90,36 +82,31 @@ public void testWazeGetRoutesReturnSingleRequestFromUSA(){
}

@Test
@Ignore
public void testWazeGetRoutesRequestFromUSA(){
WazeRouteResponse wazeRouteResponse = wazeRouteService.getRoutes("5th Avenue, Manhattan, New York, NY, United States", "2th Avenue, Manhattan, New York, NY");
assert(wazeRouteResponse.getRoutes().size() >= 1);
}

@Test
@Ignore
public void testWazeGetRoutesRequestFromUK(){
WazeRouteResponse wazeRouteResponse = wazeRouteService.getRoutes("305-307 Green Lanes London, United Kingdom", "360 Green Lanes London, United Kingdom");
assert(wazeRouteResponse.getRoutes().size() == 2);
}

@Test
@Ignore
public void testWazeGetRoutesRequestFromIsrael(){
WazeRouteResponse wazeRouteResponse = wazeRouteService.getRoutes("הירקון 28 תל אביב", "פתח תקווה");
assert(wazeRouteResponse.getRoutes().size() == 2);
}

@Test
@Ignore
public void testWazeFreeTextToAddress(){
WazeStreetPickerResult wazeStreetPickerResult = wazeRouteService.getAddressOptionsFromFreeText("5th Avenue, Manhattan, New York, NY");
assert(wazeStreetPickerResult.getAddressList().size() >= 1);
assert(wazeStreetPickerResult.getAddressList().get(0).contains("New York"));
}

@Test
@Ignore
public void testWazeFreeLatLon(){
WazeRouteResponse wazeRouteResponse = wazeRouteService.getRoutes("32.07120132446289", "34.7652473449707", "32.06473159790039", "34.86988830566406", null, null);
assert(wazeRouteResponse.getRoutes().size() == 2);
Expand Down

0 comments on commit 491579a

Please sign in to comment.