Skip to content

Commit 6a056bd

Browse files
authored
Improve create list tracker (#96)
* improve createlist for tracker. * update the variable name.
1 parent 1e0f400 commit 6a056bd

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

src/main/java/com/easypost/model/Tracker.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.easypost.exception.EasyPostException;
44
import com.easypost.net.EasyPostResource;
55

6-
import java.util.ArrayList;
76
import java.util.Date;
87
import java.util.HashMap;
98
import java.util.List;
@@ -119,16 +118,11 @@ public static boolean createList(final Map<String, Object> params) throws EasyPo
119118
public static boolean createList(final Map<String, Object> params, final String apiKey) throws EasyPostException {
120119
String createListUrl = String.format("%s/create_list", classURL(Tracker.class));
121120

122-
int count = 0;
123121
Map<String, Object> newParams = new HashMap<String, Object>();
124-
Map<String, Object> trackers = new HashMap<String, Object>();
125-
for (Object tracker : (ArrayList) params.get("trackers")) {
126-
trackers.put(String.valueOf(count), tracker);
127-
count++;
128-
}
129-
newParams.put("trackers", trackers);
122+
newParams.put("trackers", params);
130123

131124
request(RequestMethod.POST, createListUrl, newParams, Object.class, apiKey);
125+
// This endpoint does not return a response so we return true here
132126
return true;
133127
}
134128

src/test/java/com/easypost/EasyPostTest.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -354,25 +354,18 @@ public void testTrackerCreateAndRetrieve() throws EasyPostException, ParseExcept
354354

355355
@Test
356356
public void testBatchTrackerCreate() throws EasyPostException {
357-
List<String> trackingCodes = new ArrayList<String>();
358-
trackingCodes.add("EZ1000000001");
359-
trackingCodes.add("EZ2000000002");
360-
trackingCodes.add("EZ3000000003");
361357

362-
List<HashMap<String, Object>> trackingCodeParams = new ArrayList<HashMap<String, Object>>();
363-
HashMap<String, Object> code;
358+
String[] trackingCodes = new String[]{"EZ1000000001", "EZ1000000002", "EZ1000000003"};
359+
HashMap<String, Object> trackingCodeParams = new HashMap<String, Object>();
364360

365-
for (int i = 0; i < trackingCodes.size(); i++) {
366-
code = new HashMap<String, Object>();
367-
code.put("tracking_code", trackingCodes.get(i));
361+
for (int i = 0; i < trackingCodes.length; i++) {
362+
HashMap<String, Object> code = new HashMap<String, Object>();
363+
code.put("tracking_code", trackingCodes[i]);
368364
code.put("carrier", "USPS");
369-
trackingCodeParams.add(code);
365+
trackingCodeParams.put(String.valueOf(i), code);
370366
}
371367

372-
Map createListParams = new HashMap<String, Object>();
373-
createListParams.put("trackers", trackingCodeParams);
374-
375-
Tracker.createList(createListParams);
368+
Tracker.createList(trackingCodeParams);
376369
}
377370

378371
@Test
@@ -1098,7 +1091,7 @@ public void testShipmentReportDates() throws EasyPostException {
10981091
assertEquals("Incorrect ShipmentReport start_date", "Sun Oct 01 00:00:00 PDT 2017", shipmentReport2.getStartDate().toString());
10991092
assertEquals("Incorrect ShipmentReport end_date", "Mon Oct 30 00:00:00 PDT 2017", shipmentReport2.getEndDate().toString());
11001093
}*/
1101-
1094+
11021095

11031096
/*
11041097
// This test requires a FedExSameDayCity account

0 commit comments

Comments
 (0)