Skip to content

Commit c7c4954

Browse files
authored
add retrieve all pickups function (#225)
1 parent b91c6e6 commit c7c4954

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## Next Release
4+
5+
- Adds `all` function to `Pickup` to retrieve all pickups
6+
37
## v6.1.0 (2023-01-11)
48

59
- Adds new beta billing functionality for ReferralCustomer users

src/main/java/com/easypost/service/PickupService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.easypost.http.Requestor;
55
import com.easypost.http.Requestor.RequestMethod;
66
import com.easypost.model.Pickup;
7+
import com.easypost.model.PickupCollection;
78
import com.easypost.model.PickupRate;
89
import com.easypost.utils.InternalUtilities;
910

@@ -22,6 +23,19 @@ public class PickupService {
2223
this.client = client;
2324
}
2425

26+
/**
27+
* Get a list of all Pickup objects.
28+
*
29+
* @param params The options for the query.
30+
* @return PickupCollection object
31+
* @throws EasyPostException when the request fails.
32+
*/
33+
public PickupCollection all(final Map<String, Object> params)
34+
throws EasyPostException {
35+
return Requestor.request(RequestMethod.GET, InternalUtilities.classURL(Pickup.class), params,
36+
PickupCollection.class, client);
37+
}
38+
2539
/**
2640
* Create a new Pickup object from a map of parameters.
2741
*

src/test/cassettes/pickup/all.json

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/java/com/easypost/PickupTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.easypost.exception.EasyPostException;
44
import com.easypost.model.Pickup;
5+
import com.easypost.model.PickupCollection;
56
import com.easypost.model.PickupRate;
67
import com.easypost.model.Shipment;
78
import org.junit.jupiter.api.BeforeAll;
@@ -47,6 +48,27 @@ private static Pickup createBasicPickup() throws EasyPostException {
4748
return vcr.client.pickup.create(pickupData);
4849
}
4950

51+
/**
52+
* Test retrieving all shipments.
53+
*
54+
* @throws EasyPostException when the request fails.
55+
*/
56+
@Test
57+
public void testAll() throws EasyPostException {
58+
vcr.setUpTest("all");
59+
60+
Map<String, Object> params = new HashMap<String, Object>();
61+
params.put("page_size", Fixtures.pageSize());
62+
63+
PickupCollection pickupCollection = vcr.client.pickup.all(params);
64+
65+
List<Pickup> pickups = pickupCollection.getPickups();
66+
67+
assertTrue(pickups.size() <= Fixtures.pageSize());
68+
assertNotNull(pickupCollection.getHasMore());
69+
assertTrue(pickups.stream().allMatch(pickup -> pickup instanceof Pickup));
70+
}
71+
5072
/**
5173
* Test creating a pickup.
5274
*

0 commit comments

Comments
 (0)