-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathEasyPostClient.java
More file actions
240 lines (220 loc) · 9 KB
/
EasyPostClient.java
File metadata and controls
240 lines (220 loc) · 9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
package com.easypost.service;
import lombok.Getter;
import com.easypost.Constants;
import com.easypost.exception.General.MissingParameterError;
import com.easypost.hooks.ResponseHook;
import com.easypost.hooks.ResponseHookResponses;
import com.easypost.hooks.RequestHook;
import com.easypost.hooks.RequestHookResponses;
import java.util.function.Function;
public class EasyPostClient {
private final int connectTimeoutMilliseconds;
private final int readTimeoutMilliseconds;
private final String clientApiKey; // API key for all EasyPost API requests
private final String apiVersion = "v2";
private final String apiBase;
public final AddressService address;
public final ApiKeyService apiKey;
public final BatchService batch;
public final BetaReferralCustomerService betaReferralCustomer;
public final BetaRateService betaRate;
public final BillingService billing;
public final CarrierAccountService carrierAccount;
public final CarrierMetadataService carrierMetadata;
public final CarrierTypeService carrierType;
public final ClaimService claim;
public final CustomsInfoService customsInfo;
public final CustomsItemService customsItem;
public final EndShipperService endShipper;
public final EventService event;
public final InsuranceService insurance;
public final LumaService luma;
public final OrderService order;
public final ParcelService parcel;
public final PaymentMethodService paymentMethod;
public final PickupService pickup;
public final RateService rate;
public final ReferralCustomerService referralCustomer;
public final RefundService refund;
public final ReportService report;
public final ScanformService scanForm;
public final ShipmentService shipment;
public final SmartRateService smartRate;
public final TrackerService tracker;
public final UserService user;
public final WebhookService webhook;
@Getter
private RequestHook requestHooks = new RequestHook();
@Getter
private ResponseHook responseHooks = new ResponseHook();
/**
* EasyPostClient constructor.
*
* @param apiKey API key for API calls.
* @throws MissingParameterError When the request fails.
*/
public EasyPostClient(String apiKey) throws MissingParameterError {
this(apiKey, Constants.Http.DEFAULT_CONNECT_TIMEOUT_MILLISECONDS);
}
/**
* EasyPostClient constructor.
*
* @param apiKey API key for API calls.
* @param apiBase API base for API calls.
* @throws MissingParameterError When the request fails.
*/
public EasyPostClient(String apiKey, String apiBase) throws MissingParameterError {
this(apiKey, Constants.Http.DEFAULT_CONNECT_TIMEOUT_MILLISECONDS,
Constants.Http.DEFAULT_READ_TIMEOUT_MILLISECONDS, apiBase);
}
/**
* EasyPostClient constructor.
*
* @param apiKey API key for API calls.
* @param connectTimeoutMilliseconds Timeout for connection.
* @throws MissingParameterError When the request fails.
*/
public EasyPostClient(String apiKey, int connectTimeoutMilliseconds) throws MissingParameterError {
this(apiKey, connectTimeoutMilliseconds, Constants.Http.API_BASE);
}
/**
* EasyPostClient constructor.
*
* @param apiKey API key for API calls.
* @param connectTimeoutMilliseconds Timeout for connection.
* @param apiBase API base for API calls.
* @throws MissingParameterError When the request fails.
*/
public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, String apiBase) throws MissingParameterError {
this(apiKey, connectTimeoutMilliseconds, Constants.Http.DEFAULT_READ_TIMEOUT_MILLISECONDS, apiBase);
}
/**
* EasyPostClient constructor.
*
* @param apiKey API key for API calls.
* @param connectTimeoutMilliseconds Timeout for connection.
* @param readTimeoutMilliseconds Timeout for read.
* @throws MissingParameterError When the request fails.
*/
public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, int readTimeoutMilliseconds)
throws MissingParameterError {
this(apiKey, connectTimeoutMilliseconds, readTimeoutMilliseconds, Constants.Http.API_BASE);
}
/**
* EasyPostClient constructor.
*
* @param apiKey API key for API calls.
* @param connectTimeoutMilliseconds Timeout for connection.
* @param readTimeoutMilliseconds Timeout for read.
* @param apiBase API base for API calls.
* @throws MissingParameterError When the request fails.
*/
public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, int readTimeoutMilliseconds, String apiBase)
throws MissingParameterError {
if (apiKey == null || apiKey.isEmpty()) {
throw new MissingParameterError("apiKey");
}
this.apiBase = apiBase;
this.clientApiKey = apiKey;
this.connectTimeoutMilliseconds = connectTimeoutMilliseconds;
this.readTimeoutMilliseconds = readTimeoutMilliseconds;
this.address = new AddressService(this);
this.apiKey = new ApiKeyService(this);
this.batch = new BatchService(this);
this.betaReferralCustomer = new BetaReferralCustomerService(this);
this.betaRate = new BetaRateService(this);
this.billing = new BillingService(this);
this.carrierAccount = new CarrierAccountService(this);
this.carrierMetadata = new CarrierMetadataService(this);
this.carrierType = new CarrierTypeService(this);
this.claim = new ClaimService(this);
this.customsInfo = new CustomsInfoService(this);
this.customsItem = new CustomsItemService(this);
this.endShipper = new EndShipperService(this);
this.event = new EventService(this);
this.insurance = new InsuranceService(this);
this.luma = new LumaService(this);
this.order = new OrderService(this);
this.parcel = new ParcelService(this);
this.paymentMethod = new PaymentMethodService(this);
this.pickup = new PickupService(this);
this.rate = new RateService(this);
this.referralCustomer = new ReferralCustomerService(this);
this.refund = new RefundService(this);
this.report = new ReportService(this);
this.scanForm = new ScanformService(this);
this.shipment = new ShipmentService(this);
this.smartRate = new SmartRateService(this);
this.tracker = new TrackerService(this);
this.user = new UserService(this);
this.webhook = new WebhookService(this);
}
/**
* Subscribes to a request hook from the given function.
* @param function The function to be subscribed to the request hook
*/
public void subscribeToRequestHook(Function<RequestHookResponses, Object> function) {
this.requestHooks.addEventHandler(function);
}
/**
* Unsubscribes to a request hook from the given function.
* @param function The function to be unsubscribed from the request hook
*/
public void unsubscribeFromRequestHook(Function<RequestHookResponses, Object> function) {
this.requestHooks.removeEventHandler(function);
}
/**
* Subscribes to a response hook from the given function.
* @param function The function to be subscribed to the response hook
*/
public void subscribeToResponseHook(Function<ResponseHookResponses, Object> function) {
this.responseHooks.addEventHandler(function);
}
/**
* Unubscribes to a response hook from the given function.
* @param function The function to be unsubscribed from the response hook
*/
public void unsubscribeFromResponseHook(Function<ResponseHookResponses, Object> function) {
this.responseHooks.removeEventHandler(function);
}
/**
* Get connection timeout milliseconds for this EasyPostClient object.
*
* @return the connection timeout for this EasyPostClient object
*/
public int getConnectionTimeoutMilliseconds() {
return connectTimeoutMilliseconds;
}
/**
* Get read timeout milliseconds for this EasyPostClient object.
*
* @return the read timeout for this EasyPostClient object
*/
public int getReadTimeoutMilliseconds() {
return readTimeoutMilliseconds;
}
/**
* Get API key for this EasyPostClient object.
*
* @return the API key for this EasyPostClient object
*/
public String getApiKey() {
return clientApiKey;
}
/**
* Get API version for this EasyPostClient object.
*
* @return the API version for this EasyPostClient object.
*/
public String getApiVersion() {
return apiVersion;
}
/**
* Get API base for this EasyPostClient object.
*
* @return the API base for this EasyPostClient object.
*/
public String getApiBase() {
return apiBase;
}
}