Skip to content

Commit 12aa350

Browse files
committed
fix: SmartRate namings
1 parent 6b160e8 commit 12aa350

13 files changed

+185
-170
lines changed

CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ See our [Upgrade Guide](UPGRADE_GUIDE.md#upgrading-from-7x-to-80) for more detai
2020
- Added an explicit `AddressVerificationFieldError` model
2121
- The `BetaPaymentRefund` now uses a list of `FieldError` instead of `Error` for the `errors` field
2222
- Removes deprecated functions
23-
- `TimeInTransit.getSmartRateAccuracy` (use `TimeInTransit.getSmartrateAccuracy` instead)
2423
- `paymentMethod.all` (use `billing.retrievePaymentMethods` instead)
25-
- `shipment.getSmartrates` (use `shipment.smartrates` instead)
26-
- String overload for `shipment.lowestSmartRate`, 3rd param requires a valid `SmartrateAccuracy`
2724
- `user.apiKeys` (use `apiKey.retrieveApiKeysForUser` instead)
28-
- `utilities.getLowestSmartRate` (use `utilities.findLowestSmartrate` instead)
25+
- Replaces deprecated functions
26+
- `shipment.lowestSmartRate` (3rd param expects a valid `SmartRateAccuracy`)
27+
- `utilities.findLowestSmartRate` (3rd param expects a valid `SmartRateAccuracy`)
28+
- Renames
29+
- `SmartrateAccuracy` is now `SmartRateAccuracy`
30+
- `SmartrateCollection` is now `SmartRateCollection`
31+
- `shipment.smartrates` is now `shipment.smartRates`
32+
- `TimeInTransit.getBySmartrateAccuracy` is now `TimeInTransit.getSmartRateAccuracy`
2933
- Bumps dependencies
3034

3135
## v7.4.4 (2025-01-03)

UPGRADE_GUIDE.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ See the `CHANGELOG` for more details.
3333

3434
*Likelihood of Impact: **Medium***
3535

36-
The following deprecated functions have been removed:
37-
38-
- `TimeInTransit.getSmartRateAccuracy` (use `TimeInTransit.getSmartrateAccuracy` instead)
39-
- `paymentMethod.all` (use `billing.retrievePaymentMethods` instead)
40-
- `shipment.getSmartrates` (use `shipment.smartrates` instead)
41-
- String overload for `shipment.lowestSmartRate`, 3rd param requires a valid `SmartrateAccuracy`
42-
- `user.apiKeys` (use `apiKey.retrieveApiKeysForUser` instead)
43-
- `utilities.getLowestSmartRate` (use `utilities.findLowestSmartrate` instead)
36+
The following functions have changed:
37+
38+
- Removed deprecated functions
39+
- `paymentMethod.all` (use `billing.retrievePaymentMethods` instead)
40+
- `user.apiKeys` (use `apiKey.retrieveApiKeysForUser` instead)
41+
- Changed deprecated functions
42+
- `shipment.lowestSmartRate` (3rd param expects a valid `SmartRateAccuracy`)
43+
- `utilities.findLowestSmartRate` (3rd param expects a valid `SmartRateAccuracy`)
44+
- Renames
45+
- `SmartrateAccuracy` is now `SmartRateAccuracy`
46+
- `SmartrateCollection` is now `SmartRateCollection`
47+
- `shipment.smartrates` is now `shipment.smartRates`
48+
- `TimeInTransit.getBySmartrateAccuracy` is now `TimeInTransit.getSmartRateAccuracy`
4449

4550
## Upgrading from 6.x to 7.0
4651

src/main/java/com/easypost/Constants.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import com.easypost.model.AddressVerification;
66
import com.easypost.model.AddressVerificationDeserializer;
77
import com.easypost.model.ErrorDeserializer;
8-
import com.easypost.model.SmartrateCollection;
9-
import com.easypost.model.SmartrateCollectionDeserializer;
8+
import com.easypost.model.SmartRateCollection;
9+
import com.easypost.model.SmartRateCollectionDeserializer;
1010
import com.easypost.model.StatelessRate;
1111
import com.easypost.model.StatelessRateDeserializer;
1212
import com.easypost.model.Webhook;
@@ -24,21 +24,17 @@ public abstract class Constants {
2424
public static final String EASYPOST_SUPPORT_EMAIL = "[email protected]";
2525

2626
public abstract static class ErrorMessages {
27-
public static final String EXTERNAL_API_CALL_FAILED =
28-
"Could not send card details to %s, please try again later";
27+
public static final String EXTERNAL_API_CALL_FAILED = "Could not send card details to %s, please try again later";
2928
public static final String ENCODED_ERROR = "Encode error for %s";
3029
public static final String INVALID_API_KEY_TYPE = "Invalid API key type.";
3130
public static final String INVALID_PARAMETER = "Invalid parameter: %s.";
32-
public static final String INVALID_PAYMENT =
33-
"The chosen payment method is not a credit card. Please try again.";
31+
public static final String INVALID_PAYMENT = "The chosen payment method is not a credit card. Please try again.";
3432
public static final String INVALID_WEBHOOK_SIGNATURE = "Webhook does not contain a valid HMAC signature.";
3533
public static final String MISSING_REQUIRED_PARAMETER = "Missing required parameter: %s.";
3634
public static final String NO_OBJECT_FOUND = "No %s found.";
37-
public static final String NO_PAYMENT_METHODS =
38-
"No payment methods are set up. Please add a payment method and try again.";
35+
public static final String NO_PAYMENT_METHODS = "No payment methods are set up. Please add a payment method and try again.";
3936
public static final String API_DID_NOT_RETURN_ERROR_DETAILS = "API did not return error details.";
40-
public static final String WEBHOOK_DOES_NOT_MATCH =
41-
"Webhook received did not originate from EasyPost or had a webhook secret mismatch.";
37+
public static final String WEBHOOK_DOES_NOT_MATCH = "Webhook received did not originate from EasyPost or had a webhook secret mismatch.";
4238

4339
public static final String NO_MORE_PAGES_TO_RETRIEVE = "There are no more pages to retrieve.";
4440
}
@@ -62,16 +58,13 @@ public abstract static class ErrorCodes {
6258

6359
public abstract static class CarrierAccountTypes {
6460
public static final List<String> CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOW = ImmutableList.of(
65-
"FedexAccount", "FedexSmartpostAccount"
66-
);
61+
"FedexAccount", "FedexSmartpostAccount");
6762

6863
public static final List<String> UPS_OAUTH_CARRIER_ACCOUNT_TYPES = ImmutableList.of(
69-
"UpsAccount", "UpsMailInnovationsAccount", "UpsSurepostAccount"
70-
);
64+
"UpsAccount", "UpsMailInnovationsAccount", "UpsSurepostAccount");
7165

7266
public static final List<String> CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = ImmutableList.of(
73-
"AmazonShippingAccount"
74-
);
67+
"AmazonShippingAccount");
7568
}
7669

7770
public abstract static class Http {
@@ -83,7 +76,7 @@ public abstract static class Http {
8376
public static final Gson GSON = new GsonBuilder()
8477
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
8578
.registerTypeAdapter(HashMap.class, new HashMapSerializer())
86-
.registerTypeAdapter(SmartrateCollection.class, new SmartrateCollectionDeserializer())
79+
.registerTypeAdapter(SmartRateCollection.class, new SmartRateCollectionDeserializer())
8780
.registerTypeAdapter(APIException.class, new ErrorDeserializer())
8881
.registerTypeAdapter(AddressVerification.class, new AddressVerificationDeserializer())
8982
.registerTypeAdapter(StatelessRate[].class, new StatelessRateDeserializer())

src/main/java/com/easypost/model/AddressVerificationDeserializer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ public final class AddressVerificationDeserializer implements JsonDeserializer<A
1818
* @param typeOfT Type of the object to deserialize.
1919
* @param context Deserialization context.
2020
* @return Deserialized AddressVerification object.
21-
* @throws JsonParseException if the JSON object is not a valid SmartrateCollection.
21+
* @throws JsonParseException if the JSON object is not a valid
22+
* SmartRateCollection.
2223
*/
2324
@Override
2425
public AddressVerification deserialize(final JsonElement json, final Type typeOfT,
25-
final JsonDeserializationContext context) throws JsonParseException {
26+
final JsonDeserializationContext context) throws JsonParseException {
2627
JsonObject jo = json.getAsJsonObject();
2728

2829
AddressVerification addressVerification = new AddressVerification();

src/main/java/com/easypost/model/ErrorDeserializer.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
public final class ErrorDeserializer implements JsonDeserializer<APIException> {
1818
/**
19-
* Recursively traverse an error JSON element and its sub-element(s), and extracts all
19+
* Recursively traverse an error JSON element and its sub-element(s), and
20+
* extracts all
2021
* error string values found into the specified string list.
2122
*
22-
* @param element the JSON element to traverse
23+
* @param element the JSON element to traverse
2324
* @param messagesList the list of strings to append found values to
2425
*/
2526
private void traverseJsonElement(JsonElement element, ArrayList<String> messagesList) {
@@ -45,11 +46,12 @@ private void traverseJsonElement(JsonElement element, ArrayList<String> messages
4546
* @param typeOfT Type of the object to deserialize.
4647
* @param context Deserialization context.
4748
* @return Deserialized APIException object.
48-
* @throws JsonParseException if the JSON object is not a valid SmartrateCollection.
49+
* @throws JsonParseException if the JSON object is not a valid
50+
* SmartRateCollection.
4951
*/
5052
@Override
5153
public APIException deserialize(final JsonElement json, final Type typeOfT,
52-
final JsonDeserializationContext context) throws JsonParseException {
54+
final JsonDeserializationContext context) throws JsonParseException {
5355
JsonObject jo = json.getAsJsonObject();
5456

5557
String message = null;
@@ -83,7 +85,6 @@ public APIException deserialize(final JsonElement json, final Type typeOfT,
8385
}
8486

8587
JsonElement errorsAsJson = errorData.get("errors");
86-
List<Object> errorList = new ArrayList<>();
8788
if (errorsAsJson != null) {
8889
JsonArray errorsAsArray = errorsAsJson.getAsJsonArray();
8990
for (JsonElement errorAsJson : errorsAsArray) {
@@ -106,13 +107,13 @@ public APIException deserialize(final JsonElement json, final Type typeOfT,
106107
fieldError.setSuggestion(suggestion.getAsString());
107108
}
108109

109-
errorList.add(fieldError);
110+
errors.add(fieldError);
110111
} else {
111-
errorList.add(errorAsJson.getAsString());
112+
errors.add(errorAsJson.getAsString());
112113
}
113114
}
114115
}
115116

116-
return new APIException(message, code, errorList);
117+
return new APIException(message, code, errors);
117118
}
118119
}

src/main/java/com/easypost/model/SmartrateAccuracy.java renamed to src/main/java/com/easypost/model/SmartRateAccuracy.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import lombok.Getter;
77

88
@Getter
9-
public enum SmartrateAccuracy {
9+
public enum SmartRateAccuracy {
1010
Percentile50("percentile_50"),
1111
Percentile75("percentile_75"),
1212
Percentile85("percentile_85"),
@@ -22,7 +22,7 @@ public enum SmartrateAccuracy {
2222
*
2323
* @param keyName the internal key name
2424
*/
25-
SmartrateAccuracy(String keyName) {
25+
SmartRateAccuracy(String keyName) {
2626
this.keyName = keyName;
2727
}
2828

@@ -33,8 +33,8 @@ public enum SmartrateAccuracy {
3333
* @return the enum value
3434
* @throws EasyPostException if the key name is not found
3535
*/
36-
public static SmartrateAccuracy getByKeyName(String keyName) throws EasyPostException {
37-
for (SmartrateAccuracy smartrateAccuracy : values()) {
36+
public static SmartRateAccuracy getByKeyName(String keyName) throws EasyPostException {
37+
for (SmartRateAccuracy smartrateAccuracy : values()) {
3838
if (smartrateAccuracy.getKeyName().equals(keyName)) {
3939
return smartrateAccuracy;
4040
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.easypost.model;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public final class SmartRateCollection {
7+
private List<SmartRate> smartRates;
8+
9+
/**
10+
* Get this SmartRateCollection's Smartrate objects.
11+
*
12+
* @return List of Smartrate objects.
13+
*/
14+
public List<SmartRate> getSmartRates() {
15+
return this.smartRates;
16+
}
17+
18+
/**
19+
* Set this SmartRateCollection's Smartrate objects.
20+
*
21+
* @param smartRates List of Smartrate objects.
22+
*/
23+
public void setSmartrates(final List<SmartRate> smartRates) {
24+
this.smartRates = smartRates;
25+
}
26+
27+
/**
28+
* Constructor.
29+
*/
30+
public SmartRateCollection() {
31+
this.smartRates = new ArrayList<SmartRate>();
32+
}
33+
34+
/**
35+
* Create a SmartRateCollection from a list of rates.
36+
*
37+
* @param smartRates List of Smartrate objects
38+
*/
39+
public SmartRateCollection(final List<SmartRate> smartRates) {
40+
setSmartrates(smartRates);
41+
}
42+
43+
/**
44+
* Add a SmartRate object to this SmartRateCollection.
45+
*
46+
* @param rate Rate object
47+
*/
48+
public void addRate(final SmartRate rate) {
49+
smartRates.add(rate);
50+
}
51+
}

src/main/java/com/easypost/model/SmartrateCollectionDeserializer.java renamed to src/main/java/com/easypost/model/SmartRateCollectionDeserializer.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@
88

99
import java.lang.reflect.Type;
1010

11-
public final class SmartrateCollectionDeserializer implements JsonDeserializer<SmartrateCollection> {
11+
public final class SmartRateCollectionDeserializer implements JsonDeserializer<SmartRateCollection> {
1212
/**
13-
* Deserialize a SmartrateCollection from a JSON object.
13+
* Deserialize a SmartRateCollection from a JSON object.
1414
*
1515
* @param json JSON object to deserialize.
1616
* @param typeOfT Type of the object to deserialize.
1717
* @param context Deserialization context.
18-
* @return Deserialized SmartrateCollection object.
19-
* @throws JsonParseException if the JSON object is not a valid SmartrateCollection.
18+
* @return Deserialized SmartRateCollection object.
19+
* @throws JsonParseException if the JSON object is not a valid
20+
* SmartRateCollection.
2021
*/
2122
@Override
22-
public SmartrateCollection deserialize(final JsonElement json, final Type typeOfT,
23-
final JsonDeserializationContext context) throws JsonParseException {
24-
SmartrateCollection smartrateCollection = new SmartrateCollection();
23+
public SmartRateCollection deserialize(final JsonElement json, final Type typeOfT,
24+
final JsonDeserializationContext context) throws JsonParseException {
25+
SmartRateCollection smartrateCollection = new SmartRateCollection();
2526

2627
JsonObject jo = (JsonObject) json;
2728
JsonElement results = jo.get("result");
2829

2930
if (results == null || !results.isJsonArray()) {
3031
return smartrateCollection;
31-
// return empty collection if "results" key does not exist or corresponding value is not an array
32+
// return empty collection if "results" key does not exist or corresponding
33+
// value is not an array
3234
}
3335
// the JsonDeserializationContext should have access to the other type adapters,
3436
// so we can tap into the RateDeserializer from here

src/main/java/com/easypost/model/SmartrateCollection.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/main/java/com/easypost/model/TimeInTransit.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public final class TimeInTransit {
2727
/**
2828
* Get the delivery accuracy of a specific percentile of this TimeInTransit.
2929
*
30-
* @param accuracy the SmartrateAccuracy to find the corresponding accuracy for
30+
* @param accuracy the SmartRateAccuracy to find the corresponding accuracy for
3131
* @return the delivery accuracy of the specified percentile
3232
* @throws EasyPostException when the percentile is not valid
3333
*/
34-
public int getBySmartrateAccuracy(SmartrateAccuracy accuracy) throws EasyPostException {
34+
public int getSmartRateAccuracy(SmartRateAccuracy accuracy) throws EasyPostException {
3535
switch (accuracy) {
3636
case Percentile50:
3737
return this.percentile50;

0 commit comments

Comments
 (0)