|
| 1 | +package com.easypost.model; |
| 2 | + |
| 3 | +import com.easypost.EasyPost; |
| 4 | +import com.easypost.exception.EasyPostException; |
| 5 | + |
| 6 | +import java.util.HashMap; |
| 7 | +import java.util.Map; |
| 8 | + |
| 9 | +public final class EndShipper extends BaseAddress { |
| 10 | + /** |
| 11 | + * Create EndShipper object from parameter map. |
| 12 | + * |
| 13 | + * @param params Map of EndShipper parameters. |
| 14 | + * @return EndShipper object. |
| 15 | + * @throws EasyPostException when the request fails. |
| 16 | + */ |
| 17 | + public static EndShipper create(final Map<String, Object> params) throws EasyPostException { |
| 18 | + return create(params, null); |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * Create EndShipper object from parameter map. |
| 23 | + * |
| 24 | + * @param params Map of EndShipper parameters. |
| 25 | + * @param apiKey Optional API key to use for this request. |
| 26 | + * @return EndShipper object. |
| 27 | + * @throws EasyPostException when the request fails. |
| 28 | + */ |
| 29 | + public static EndShipper create(final Map<String, Object> params, final String apiKey) throws EasyPostException { |
| 30 | + Map<String, Object> wrappedParams = new HashMap<String, Object>(); |
| 31 | + |
| 32 | + wrappedParams.put("address", params); |
| 33 | + |
| 34 | + return request(RequestMethod.POST, String.format("%s/%s", EasyPost.API_BASE, "end_shippers"), |
| 35 | + wrappedParams, EndShipper.class, apiKey); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Retrieve EndShipper object from API. |
| 40 | + * |
| 41 | + * @param id ID of EndShipper to retrieve. |
| 42 | + * @return EndShipper object. |
| 43 | + * @throws EasyPostException when the request fails. |
| 44 | + */ |
| 45 | + public static EndShipper retrieve(final String id) throws EasyPostException { |
| 46 | + return retrieve(id, null); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Retrieve EndShipper object from API. |
| 51 | + * |
| 52 | + * @param id ID of EndShipper to retrieve. |
| 53 | + * @param apiKey API key to use in request (overrides default API key). |
| 54 | + * @return EndShipper object. |
| 55 | + * @throws EasyPostException when the request fails. |
| 56 | + */ |
| 57 | + public static EndShipper retrieve(final String id, final String apiKey) throws EasyPostException { |
| 58 | + return request(RequestMethod.GET, String.format("%s/%s/%s", EasyPost.API_BASE, "end_shippers", id), null, |
| 59 | + EndShipper.class, apiKey); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * List all EndShipper objects. |
| 64 | + * |
| 65 | + * @param params Map of parameters. |
| 66 | + * @return EndShipperCollection object. |
| 67 | + * @throws EasyPostException when the request fails. |
| 68 | + */ |
| 69 | + public static EndShipperCollection all(final Map<String, Object> params) throws EasyPostException { |
| 70 | + return all(params, null); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * List all EndShipper objects. |
| 75 | + * |
| 76 | + * @param params Map of parameters. |
| 77 | + * @param apiKey API key to use in request (overrides default API key). |
| 78 | + * @return EndShipperCollection object. |
| 79 | + * @throws EasyPostException when the request fails. |
| 80 | + */ |
| 81 | + public static EndShipperCollection all(final Map<String, Object> params, final String apiKey) |
| 82 | + throws EasyPostException { |
| 83 | + return request(RequestMethod.GET, classURL(EndShipper.class), params, EndShipperCollection.class, apiKey); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Update an EndShipper object. |
| 88 | + * |
| 89 | + * @param params Map of parameters. |
| 90 | + * @return EndShipper object. |
| 91 | + * @throws EasyPostException when the request fails. |
| 92 | + */ |
| 93 | + public EndShipper update(final Map<String, Object> params) throws EasyPostException { |
| 94 | + return update(params, null); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Update an EndShipper object. |
| 99 | + * |
| 100 | + * @param params Map of parameters. |
| 101 | + * @param apiKey API key to use in request (overrides default API key). |
| 102 | + * @return EndShipper object. |
| 103 | + * @throws EasyPostException when the request fails. |
| 104 | + */ |
| 105 | + public EndShipper update(final Map<String, Object> params, final String apiKey) throws EasyPostException { |
| 106 | + Map<String, Object> wrappedParams = new HashMap<String, Object>(); |
| 107 | + |
| 108 | + wrappedParams.put("address", params); |
| 109 | + |
| 110 | + EndShipper response = request(RequestMethod.PUT, |
| 111 | + String.format("%s/%s/%s", EasyPost.API_BASE, "end_shippers", this.getId()), wrappedParams, |
| 112 | + EndShipper.class, apiKey); |
| 113 | + |
| 114 | + this.merge(this, response); |
| 115 | + return this; |
| 116 | + } |
| 117 | +} |
0 commit comments