Skip to content

Commit 3277660

Browse files
committed
Added method to Rename a Route
1 parent f4b0043 commit 3277660

File tree

6 files changed

+83
-4
lines changed

6 files changed

+83
-4
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.route4me</groupId>
66
<artifactId>route4me-java-sdk</artifactId>
7-
<version>RELEASE-1.4.0</version>
7+
<version>RELEASE-1.5.0</version>
88
<packaging>jar</packaging>
99
<properties>
1010
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

src/main/java/com/route4me/sdk/examples/advancedconstraints/AdvancedConstraintsExample11.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static void main(String[] args) {
4242
parameters.setStoreRoute(Boolean.FALSE);
4343
parameters.setShareRoute(Boolean.FALSE);
4444
parameters.setRouteTime(7 * 3600);
45-
parameters.setRt(Boolean.TRUE);
45+
parameters.setRt(Boolean.FALSE);
4646
parameters.setRouteName("Retail Location - Single Depot - Multiple Driver");
4747
parameters.setOptimize(Optimize.DISTANCE.toString());
4848
parameters.setDistanceUnit(DistanceUnit.MI.toString());
@@ -76,7 +76,7 @@ public static void main(String[] args) {
7676

7777
//Retail Location: "4738 BELLEVUE AVE, Louisville, KY, 40215"
7878

79-
Address retailLocationAddress = new Address("4738 BELLEVUE AVE, Louisville, KY, 40215", "RETAIL LOCATION", 38.179806, -85.775558, 300);
79+
Address retailLocationAddress = new Address("4738 BELLEVUE AVE, Louisville, KY, 40215", "DEPOT END LOCATION", 38.179806, -85.775558, 300);
8080

8181
List <Object> locationsSequence = Arrays.asList("", retailLocationAddress);
8282

src/main/java/com/route4me/sdk/examples/bundling/BundlingUsingCustomField.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void main(String[] args) {
5757

5858

5959
Bundling bundling = new Bundling();
60-
60+
6161
bundling.setMergeMode(BundlingEnum.BundledItemsMode.MERGE_INTO_SINGLE_DESTINATION.getValue());
6262

6363
bundling.setMode(BundlingEnum.BundlingMode.BUNDLING_BY_ANY_CUSTOM_DATA.getValue());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.route4me.sdk.examples.routes;
7+
8+
import com.route4me.sdk.exception.APIException;
9+
import com.route4me.sdk.services.routing.RouteRenamedStatus;
10+
import com.route4me.sdk.services.routing.RoutingManager;
11+
12+
/**
13+
*
14+
* @author Route4Me
15+
*/
16+
public class RenameRoute {
17+
18+
public static void main(String[] args) {
19+
String apiKey = "11111111111111111111111111111111";
20+
RoutingManager routeManager = new RoutingManager(apiKey);
21+
try {
22+
RouteRenamedStatus status = routeManager.renameRoute("Renamed Route", "064E14375541A4ECADCF9B3DDAB6958D");
23+
//fetches complete data
24+
System.out.println(status);
25+
} catch (APIException e) {
26+
//handle exceptions
27+
e.printStackTrace();
28+
}
29+
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.route4me.sdk.services.routing;
7+
8+
import com.google.gson.annotations.SerializedName;
9+
import lombok.Data;
10+
11+
/**
12+
*
13+
* @author Route4Me
14+
*/
15+
@Data
16+
public class RouteRenamedStatus {
17+
18+
@SerializedName("success")
19+
private Boolean success;
20+
@SerializedName("error")
21+
private String error;
22+
23+
24+
25+
}

src/main/java/com/route4me/sdk/services/routing/RoutingManager.java

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.route4me.sdk.Manager;
66
import com.route4me.sdk.RequestMethod;
77
import com.route4me.sdk.exception.APIException;
8+
import java.io.UnsupportedEncodingException;
89
import lombok.AllArgsConstructor;
910
import lombok.Getter;
1011
import lombok.ToString;
@@ -13,12 +14,19 @@
1314
import java.util.ArrayList;
1415
import java.util.List;
1516
import java.util.Map;
17+
import java.util.logging.Level;
18+
import java.util.logging.Logger;
19+
import static org.apache.http.Consts.UTF_8;
20+
import org.apache.http.NameValuePair;
21+
import org.apache.http.client.entity.UrlEncodedFormEntity;
22+
import org.apache.http.message.BasicNameValuePair;
1623

1724
public class RoutingManager extends Manager {
1825
public static final String ROUTE_EP = "/api.v4/route.php";
1926
public static final String ADDRESS_EP = "/api.v4/address.php";
2027
public static final String OPTIMIZATION_EP = "/api.v4/optimization_problem.php";
2128
public static final String DUPLICATE_ROUTE_EP = "/actions/duplicate_route.php";
29+
public static final String RENAME_ROUTE_EP = "/actions/route/rename_route.php";
2230

2331
public RoutingManager(String apiKey) {
2432
super(apiKey);
@@ -166,6 +174,20 @@ public DuplicateRouteResponse duplicateRoute(String routeID) throws APIException
166174
return this.makeRequest(RequestMethod.GET, builder, "", DuplicateRouteResponse.class);
167175
}
168176

177+
public RouteRenamedStatus renameRoute(String routeName, String routeID) throws APIException {
178+
URIBuilder builder = Manager.defaultBuilder(RENAME_ROUTE_EP);
179+
builder.setParameter("format", "json");
180+
181+
List<NameValuePair> data = new ArrayList<>();
182+
data.add(new BasicNameValuePair("route_name", routeName));
183+
data.add(new BasicNameValuePair("route_id", routeID));
184+
185+
UrlEncodedFormEntity body = null;
186+
body = new UrlEncodedFormEntity(data, UTF_8);
187+
188+
return this.makeRequest(RequestMethod.POST, builder, body, RouteRenamedStatus.class);
189+
}
190+
169191
@Getter
170192
@ToString
171193
public static class DuplicateRouteResponse {

0 commit comments

Comments
 (0)