Skip to content

Commit 68e75c5

Browse files
authored
Add content to upgrade guide for v6 major bump (#208)
1 parent 0c7d924 commit 68e75c5

File tree

4 files changed

+151
-8
lines changed

4 files changed

+151
-8
lines changed

UPGRADE_GUIDE.md

Lines changed: 148 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,165 @@
22

33
Use the following guide to assist in the upgrade process of the `easypost-java` library between major versions.
44

5-
* [Upgrading from 4.x to 5.0](#upgrading-from-4x-to-50)
5+
- [Upgrading from 5.x to 6.0](#upgrading-from-5x-to-60)
6+
- [Upgrading from 4.x to 5.0](#upgrading-from-4x-to-50)
7+
8+
## Upgrading from 5.x to 6.0
9+
10+
### 6.0 High Impact Changes
11+
12+
- [Client Instance](#60-client-instance)
13+
- [Error Types](#60-error-types)
14+
- [Empty Response Function Return Types](#60-empty-response-function-return-types)
15+
- [Services and Resources](#60-services-and-resources)
16+
17+
### 6.0 Medium Impact Changes
18+
19+
- [Removal of Setters](#60-removal-of-setters)
20+
- [Rename Some Getters](#60-rename-some-getters)
21+
22+
### 6.0 Low Impact Changes
23+
24+
- [Type Changes](#60-type-changes)
25+
26+
## 6.0 Client Instance
27+
28+
*Likelihood of Impact: **High***
29+
30+
The library is now designed around the idea of a `EasyPostClient`. Users will initialize an `EasyPostClient` instance with their API key and then use that instance to make API calls.
31+
32+
This change allows for multiple clients to be instantiated with different API keys which allows this library to be safely used in a multi-threaded environment.
33+
34+
```java
35+
// Old
36+
EasyPost.apiKey = System.getenv("EASYPOST_API_KEY"); // global API key
37+
38+
// New
39+
EasyPostClient client1 = new EasyPostClient("EASYPOST_API_KEY_1"); // per-client API key
40+
EasyPostClient client2 = new EasyPostClient("EASYPOST_API_KEY_2"); // per-client API key
41+
```
42+
43+
All functions are now accessed via the `EasyPostClient` instance. For example, to create a shipment:
44+
45+
```java
46+
// Old
47+
EasyPost.apiKey = System.getenv("EASYPOST_API_KEY");
48+
Shipment shipment = Shipment.create(shipmentMap);
49+
50+
// New
51+
EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY_1");
52+
Shipment shipment = client.shipment.create(shipmentMap);
53+
```
54+
55+
## 6.0 Error Types
56+
57+
*Likelihood of Impact: **High***
58+
59+
Error handling has been overhauled and a number of specific exception types have been introduced.
60+
61+
All exceptions inherit from `EasyPost.Exception.EasyPostException` (which extends `Java Exception` class). Users can catch this exception type to handle all errors thrown by the library.
62+
63+
Subclasses of `EasyPostException` are grouped into two categories:
64+
65+
- `EasyPost.Exception.API` for errors returned by the API. Subclasses of this exception type are:
66+
- `ExternalApiError` - thrown when an issue occurs with an external API (e.g. Stripe)
67+
- `ForbiddenError` - thrown when you don't have permission to access this API resource
68+
- `GatewayTimeoutError` - thrown when the API gateway times out (504 status code)
69+
- `InternalServerError` - thrown when an internal server error occurs (500 status code)
70+
- `InvalidRequestError` - thrown when the API received an invalid request (422 status code)
71+
- `MethodNotAllowedError` - thrown when the API receives a request with an invalid HTTP method (
72+
405 status code)
73+
- `NotFoundError` - thrown when the API receives a request for a resource that does not exist (
74+
404 status code)
75+
- `PaymentError` - thrown when a payment error occurs (402 status code)
76+
- `ProxyError` - thrown when the library is unable to connect to the API via a proxy
77+
- `RateLimitError` - thrown when the API rate limit is exceeded (429 status code)
78+
- `RedirectError` - thrown when the http status is between 300 and 308.
79+
- `ServiceUnavailableError` - thrown when the API is unavailable (503 status code)
80+
- `TimeoutError` - thrown when the API request times out (408 status code)
81+
- `UnauthorizedError` - thrown when the API receives an unauthorized request (401 or 403 status
82+
code)
83+
- `UnknownApiError` - thrown when an unknown API error occurs (unexpected 4xx status code)
84+
- `EasyPost.Exception.General` for Generic error returned by the client library. Subclasses of this exception type are:
85+
- `FilteringError` - thrown when an error occurs during filtering (e.g. calculating lowest rate)
86+
- `InvalidObjectError` - thrown when an invalid object is being used
87+
- `InvalidParameterError` - thrown when an invalid parameter is being used
88+
- `MissingPropertyError` - thrown when a required property is missing (e.g. `Id` for most objects)
89+
- `SignatureVerificationError` - thrown when the signature for a webhook is invalid
90+
91+
Any exception thrown by the EasyPost library will be one of the above types.
92+
93+
Any `EasyPost.Exception.API` exception will have the following properties:
94+
95+
- `String Code` - the HTTP status code returned by the API call (e.g. 404)
96+
- `String Message` - the error message returned by the API (e.g. "PARAMETER.INVALID")
97+
- `List<Error> Errors` - a list of errors returned by the API (e.g. "Invalid parameter: to_address")
98+
99+
Users can better anticipate exception information through utilities in the `EasyPost.Exception.Constants` file.
100+
101+
## 6.0 Empty Response Function Return Types
102+
103+
*Likelihood of Impact: **High***
104+
105+
The following functions return an empty body from the API have been changed to return void.
106+
107+
- `fundWallet()` and `deletePaymentMethod()` in Billing class
108+
- `createList()` in Tracker class
109+
- `updateEmail()` in ReferralCustomer class
110+
111+
## 6.0 Services and Resources
112+
113+
*Likelihood of Impact: **High***
114+
115+
Static and instance-based methods have been divided into separate services and resources, methods that have API interactions are in services now.
116+
117+
For example:
118+
119+
- The static method `Shipment.buy()` is now accessible in the Shipment service via `client.shipment.buy("shp_...")`.
120+
- The instance method `myShipment.lowestRate()` is still accessible only via a Shipment instance because there is no API interaction.
121+
- The instance method of `refresh()` has been removed because you can no longer use an object to make a HTTP request.
122+
123+
Instances of an object cannot be initialized directly. Instead, use the service to create the instance via a `create`, `retrieve`, or `all` API call.
124+
125+
## 6.0 Removal of Setters
126+
127+
*Likelihood of Impact: **Medium***
128+
129+
Objects no longer have setters. The use case of the setter is extremely low, but if you need to use the setter for a specific reason, try to use `reflection` in Java.
130+
131+
## 6.0 Rename Some Getters
132+
133+
*Likelihood of Impact: **Medium***
134+
135+
The following getters have been renamed:
136+
137+
- Pickup class: `getPickoutRates()` -> `getPickupRates()`
138+
- PaymentMethod class: `getPrimaryPaymentMethodObject()` -> `getPrimaryPaymentMethod()`
139+
- PaymentMethod class: `getSecondaryPaymentMethodObject()` -> `getSecondaryPaymentMethod()`
140+
141+
## 6.0 Type Changes
142+
143+
*Likelihood of Impact: **Low***
144+
145+
The following properties have changed types:
146+
147+
- `result` of Event from `EasyPostResource` to `Map<String, object>`
148+
- `amount` of Insurance from `Float` to `String`
6149

7150
## Upgrading from 4.x to 5.0
8151

9152
### 5.0 High Impact Changes
10153

11-
* [Updating Dependencies](#50-updating-dependencies)
12-
* [JSON Encoded Bodies](#50-json-encoded-bodies)
154+
- [Updating Dependencies](#50-updating-dependencies)
155+
- [JSON Encoded Bodies](#50-json-encoded-bodies)
13156

14157
### 5.0 Medium Impact Changes
15158

16-
* [Default Timeouts for HTTP Requests](#50-default-timeouts-for-http-requests)
159+
- [Default Timeouts for HTTP Requests](#50-default-timeouts-for-http-requests)
17160

18161
### 5.0 Low Impact Changes
19162

20-
* [Removal of Item and Container Objects](#50-removal-of-item-and-container-objects)
163+
- [Removal of Item and Container Objects](#50-removal-of-item-and-container-objects)
21164

22165
## 5.0 Updating Dependencies
23166

src/main/java/com/easypost/exception/General/ExternalApiError.java renamed to src/main/java/com/easypost/exception/API/ExternalApiError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.easypost.exception.General;
1+
package com.easypost.exception.API;
22

33
import com.easypost.exception.EasyPostException;
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.easypost.exception.Constants;
44
import com.easypost.exception.EasyPostException;
5-
import com.easypost.exception.General.ExternalApiError;
5+
import com.easypost.exception.API.ExternalApiError;
66
import com.easypost.http.Constant;
77
import com.easypost.http.Requestor;
88
import com.easypost.http.Requestor.RequestMethod;

src/test/java/com/easypost/ReferralTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.easypost;
22

33
import com.easypost.exception.EasyPostException;
4-
import com.easypost.exception.General.ExternalApiError;
4+
import com.easypost.exception.API.ExternalApiError;
55
import com.easypost.model.PaymentMethod;
66
import com.easypost.model.PaymentMethodObject;
77
import com.easypost.model.ReferralCustomer;

0 commit comments

Comments
 (0)