|
1 | 1 | package com.easypost.service; |
2 | 2 |
|
| 3 | +import java.util.List; |
3 | 4 | import java.util.Map; |
4 | 5 |
|
5 | 6 | import com.easypost.exception.EasyPostException; |
6 | 7 | import com.easypost.http.Requestor; |
7 | 8 | import com.easypost.http.Requestor.RequestMethod; |
8 | 9 | import com.easypost.model.Event; |
9 | 10 | import com.easypost.model.EventCollection; |
| 11 | +import com.easypost.model.Payload; |
| 12 | +import com.easypost.model.PayloadCollection; |
10 | 13 | import com.easypost.utils.InternalUtilities; |
11 | 14 |
|
12 | 15 | public class EventService { |
@@ -44,4 +47,34 @@ public EventCollection all(final Map<String, Object> params) throws EasyPostExce |
44 | 47 | return Requestor.request(RequestMethod.GET, InternalUtilities.classURL(Event.class), params, |
45 | 48 | EventCollection.class, client); |
46 | 49 | } |
| 50 | + |
| 51 | + /** |
| 52 | + * Retrieve all payloads. |
| 53 | + * |
| 54 | + * @param eventId The ID of event. |
| 55 | + * @return List of Payload objects. |
| 56 | + * @throws EasyPostException when the request fails. |
| 57 | + */ |
| 58 | + public List<Payload> retrieveAllPayloads(final String eventId) throws EasyPostException { |
| 59 | + PayloadCollection payloads = Requestor.request(RequestMethod.GET, |
| 60 | + String.format("%s/%s", InternalUtilities.instanceURL(Event.class, eventId), "payloads"), null, |
| 61 | + PayloadCollection.class, client); |
| 62 | + |
| 63 | + return payloads.getPayloads(); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Retrieve a payload. |
| 68 | + * |
| 69 | + * @param eventId The ID of event. |
| 70 | + * @param payloadId The ID of payload. |
| 71 | + * @return PayloadCollection object |
| 72 | + * @throws EasyPostException when the request fails. |
| 73 | + */ |
| 74 | + public Payload retrievePayload(final String eventId, final String payloadId) throws EasyPostException { |
| 75 | + return Requestor.request(RequestMethod.GET, |
| 76 | + String.format("%s/%s/%s", InternalUtilities.instanceURL(Event.class, eventId), "payloads", payloadId), |
| 77 | + null, |
| 78 | + Payload.class, client); |
| 79 | + } |
47 | 80 | } |
0 commit comments