From 6b160e81137ae75713017351537994dc86122308 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Mon, 28 Apr 2025 16:10:12 -0600 Subject: [PATCH 1/4] chore: prep v8.0.0 for release --- CHANGELOG.md | 12 +++++++++--- README.md | 4 ++-- UPGRADE_GUIDE.md | 38 ++++++++++++++++++++++++++++++++++++++ VERSION | 2 +- pom.xml | 2 +- 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8bf21543..dc70a6174 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # CHANGELOG -## Next Release +## v8.0.0 (2025-04-28) + +See our [Upgrade Guide](UPGRADE_GUIDE.md#upgrading-from-7x-to-80) for more details. - Adds `WebhookCustomHeader` model, allowing `custom_headers` to be passed when creating/updating a webhook - Adds the following functions to assist ReferralCustomers add credit cards and bank accounts: @@ -11,6 +13,7 @@ - Adds missing tracker props - Adds `tracking_codes` param to tracker index endpoint - Routes `AmazonShippingAccount` to the correct endpoint +- Corrects payload wrapping for updating a webhook - Fixes error parsing - Allows for alternative format of `errors` field (previously we deserialized the `errors` field into a list of `Error` objects; however, sometimes the errors are simply a list of strings. This change make the `errors` field a list of `Object` allowing for either the new `FieldError` object or a list of strings. Users will need to check for the type of error returned and handle appropriately) - Removed the unused `Error` model @@ -23,7 +26,6 @@ - String overload for `shipment.lowestSmartRate`, 3rd param requires a valid `SmartrateAccuracy` - `user.apiKeys` (use `apiKey.retrieveApiKeysForUser` instead) - `utilities.getLowestSmartRate` (use `utilities.findLowestSmartrate` instead) -- Corrects payload wrapping for updating a webhook - Bumps dependencies ## v7.4.4 (2025-01-03) @@ -79,6 +81,8 @@ ## v7.0.0 (2023-12-06) +See our [Upgrade Guide](UPGRADE_GUIDE.md#upgrading-from-6x-to-70) for more details. + - Removes `withCarbonOffset` parameter from `create`, `buy`, and `regenerateRates` functions of the Shipment service as EasyPost now offers Carbon Neutral shipments by default for free - Removes the undocumented `createAndBuy` function from the Batch service. The proper usage is to create a batch first and buy it separately - Changes return type of `all()` in webhook service from `WebhookCollection` to `a list of webhooks` @@ -149,6 +153,8 @@ ## v6.0.0 (2023-01-05) +See our [Upgrade Guide](UPGRADE_GUIDE.md#upgrading-from-5x-to-60) for more details. + Includes all the changes from `v6.0.0-rc1` listed below in addition to the following: - All constants are now defined in the top-level `Constants` class (`com.easypost.Constants`) @@ -292,7 +298,7 @@ Includes all the changes from `v6.0.0-rc1` listed below in addition to the follo ## v5.0.0 (2022-01-14) -Upgrading major versions of this project? Refer to the [Upgrade Guide](UPGRADE_GUIDE.md). +See our [Upgrade Guide](UPGRADE_GUIDE.md#upgrading-from-4x-to-50) for more details. - Bump minimum Java version from 1.5 to 8 - Changed PUT/POST request bodies from url-form encoded to JSON encoded diff --git a/README.md b/README.md index ce8bcbb3f..fd6d2e95d 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Add this to your project's POM: com.easypost easypost-api-client - 7.4.4 + 8.0.0 ``` @@ -25,7 +25,7 @@ Add this to your project's POM: Add this to your project's build file: ```groovy -implementation "com.easypost:easypost-api-client:7.4.4" +implementation "com.easypost:easypost-api-client:8.0.0" ``` **NOTE:** [Google Gson](http://code.google.com/p/google-gson/) is required. diff --git a/UPGRADE_GUIDE.md b/UPGRADE_GUIDE.md index b4a5a3703..9a9bf3652 100644 --- a/UPGRADE_GUIDE.md +++ b/UPGRADE_GUIDE.md @@ -2,12 +2,50 @@ Use the following guide to assist in the upgrade process of the `easypost-java` library between major versions. +- [Upgrading from 7.x to 8.x](#upgrading-from-7x-to-80) - [Upgrading from 6.x to 7.x](#upgrading-from-6x-to-70) - [Upgrading from 5.x to 6.0](#upgrading-from-5x-to-60) - [Upgrading from 4.x to 5.0](#upgrading-from-4x-to-50) +## Upgrading from 7.x to 8.0 + +### 8.0 High Impact Changes + +- [Error Parsing](#80-error-parsing) + +### 8.0 Medium Impact Changes + +- [Deprecations](#80-deprecations) + +## 8.0 Error Parsing + +*Likelihood of Impact: **High*** + +The `errors` key of an error response can return either a list of `FieldError` objects or a list of strings. The error parsing has been expanded to include both formats. As such, you will now need to check for the format of the `errors` field and handle the errors appropriately for the type that is returned. + +The `Error` model has been removed since it is unused and we directly assign properties of an error response to the `ApiError` type. + +The `BetaPaymentRefund` now uses a list of `FieldError` instead of `Error` for the `errors` field. + +See the `CHANGELOG` for more details. + +## 8.0 Deprecations + +*Likelihood of Impact: **Medium*** + +The following deprecated functions have been removed: + +- `TimeInTransit.getSmartRateAccuracy` (use `TimeInTransit.getSmartrateAccuracy` instead) +- `paymentMethod.all` (use `billing.retrievePaymentMethods` instead) +- `shipment.getSmartrates` (use `shipment.smartrates` instead) +- String overload for `shipment.lowestSmartRate`, 3rd param requires a valid `SmartrateAccuracy` +- `user.apiKeys` (use `apiKey.retrieveApiKeysForUser` instead) +- `utilities.getLowestSmartRate` (use `utilities.findLowestSmartrate` instead) + ## Upgrading from 6.x to 7.0 +**NOTICE:** v7 is deprecated. + ### 7.0 High Impact Changes - [Carbon Offset Removed](#70-carbon-offset-removed) diff --git a/VERSION b/VERSION index 4e61aeef9..ae9a76b92 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -7.4.4 +8.0.0 diff --git a/pom.xml b/pom.xml index 6ad2f5ab2..f5d54eef8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.easypost easypost-api-client - 7.4.4 + 8.0.0 jar com.easypost:easypost-api-client From 12aa350167727b2fa670556404377affabe2962d Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Tue, 29 Apr 2025 13:33:08 -0600 Subject: [PATCH 2/4] fix: SmartRate namings --- CHANGELOG.md | 12 ++-- UPGRADE_GUIDE.md | 21 +++--- src/main/java/com/easypost/Constants.java | 27 +++----- .../AddressVerificationDeserializer.java | 5 +- .../com/easypost/model/ErrorDeserializer.java | 17 ++--- ...teAccuracy.java => SmartRateAccuracy.java} | 8 +-- .../easypost/model/SmartRateCollection.java | 51 +++++++++++++++ ...a => SmartRateCollectionDeserializer.java} | 18 ++--- .../easypost/model/SmartrateCollection.java | 51 --------------- .../com/easypost/model/TimeInTransit.java | 4 +- .../com/easypost/service/ShipmentService.java | 65 ++++++++++--------- .../java/com/easypost/utils/Utilities.java | 26 ++++---- src/test/java/com/easypost/ShipmentTest.java | 50 +++++++------- 13 files changed, 185 insertions(+), 170 deletions(-) rename src/main/java/com/easypost/model/{SmartrateAccuracy.java => SmartRateAccuracy.java} (83%) create mode 100644 src/main/java/com/easypost/model/SmartRateCollection.java rename src/main/java/com/easypost/model/{SmartrateCollectionDeserializer.java => SmartRateCollectionDeserializer.java} (68%) delete mode 100644 src/main/java/com/easypost/model/SmartrateCollection.java diff --git a/CHANGELOG.md b/CHANGELOG.md index dc70a6174..7b3c3c79e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,12 +20,16 @@ See our [Upgrade Guide](UPGRADE_GUIDE.md#upgrading-from-7x-to-80) for more detai - Added an explicit `AddressVerificationFieldError` model - The `BetaPaymentRefund` now uses a list of `FieldError` instead of `Error` for the `errors` field - Removes deprecated functions - - `TimeInTransit.getSmartRateAccuracy` (use `TimeInTransit.getSmartrateAccuracy` instead) - `paymentMethod.all` (use `billing.retrievePaymentMethods` instead) - - `shipment.getSmartrates` (use `shipment.smartrates` instead) - - String overload for `shipment.lowestSmartRate`, 3rd param requires a valid `SmartrateAccuracy` - `user.apiKeys` (use `apiKey.retrieveApiKeysForUser` instead) - - `utilities.getLowestSmartRate` (use `utilities.findLowestSmartrate` instead) +- Replaces deprecated functions + - `shipment.lowestSmartRate` (3rd param expects a valid `SmartRateAccuracy`) + - `utilities.findLowestSmartRate` (3rd param expects a valid `SmartRateAccuracy`) +- Renames + - `SmartrateAccuracy` is now `SmartRateAccuracy` + - `SmartrateCollection` is now `SmartRateCollection` + - `shipment.smartrates` is now `shipment.smartRates` + - `TimeInTransit.getBySmartrateAccuracy` is now `TimeInTransit.getSmartRateAccuracy` - Bumps dependencies ## v7.4.4 (2025-01-03) diff --git a/UPGRADE_GUIDE.md b/UPGRADE_GUIDE.md index 9a9bf3652..22efd4799 100644 --- a/UPGRADE_GUIDE.md +++ b/UPGRADE_GUIDE.md @@ -33,14 +33,19 @@ See the `CHANGELOG` for more details. *Likelihood of Impact: **Medium*** -The following deprecated functions have been removed: - -- `TimeInTransit.getSmartRateAccuracy` (use `TimeInTransit.getSmartrateAccuracy` instead) -- `paymentMethod.all` (use `billing.retrievePaymentMethods` instead) -- `shipment.getSmartrates` (use `shipment.smartrates` instead) -- String overload for `shipment.lowestSmartRate`, 3rd param requires a valid `SmartrateAccuracy` -- `user.apiKeys` (use `apiKey.retrieveApiKeysForUser` instead) -- `utilities.getLowestSmartRate` (use `utilities.findLowestSmartrate` instead) +The following functions have changed: + +- Removed deprecated functions + - `paymentMethod.all` (use `billing.retrievePaymentMethods` instead) + - `user.apiKeys` (use `apiKey.retrieveApiKeysForUser` instead) +- Changed deprecated functions + - `shipment.lowestSmartRate` (3rd param expects a valid `SmartRateAccuracy`) + - `utilities.findLowestSmartRate` (3rd param expects a valid `SmartRateAccuracy`) +- Renames + - `SmartrateAccuracy` is now `SmartRateAccuracy` + - `SmartrateCollection` is now `SmartRateCollection` + - `shipment.smartrates` is now `shipment.smartRates` + - `TimeInTransit.getBySmartrateAccuracy` is now `TimeInTransit.getSmartRateAccuracy` ## Upgrading from 6.x to 7.0 diff --git a/src/main/java/com/easypost/Constants.java b/src/main/java/com/easypost/Constants.java index 53a6c68f5..934685d9d 100644 --- a/src/main/java/com/easypost/Constants.java +++ b/src/main/java/com/easypost/Constants.java @@ -5,8 +5,8 @@ import com.easypost.model.AddressVerification; import com.easypost.model.AddressVerificationDeserializer; import com.easypost.model.ErrorDeserializer; -import com.easypost.model.SmartrateCollection; -import com.easypost.model.SmartrateCollectionDeserializer; +import com.easypost.model.SmartRateCollection; +import com.easypost.model.SmartRateCollectionDeserializer; import com.easypost.model.StatelessRate; import com.easypost.model.StatelessRateDeserializer; import com.easypost.model.Webhook; @@ -24,21 +24,17 @@ public abstract class Constants { public static final String EASYPOST_SUPPORT_EMAIL = "support@easypost.com"; public abstract static class ErrorMessages { - public static final String EXTERNAL_API_CALL_FAILED = - "Could not send card details to %s, please try again later"; + public static final String EXTERNAL_API_CALL_FAILED = "Could not send card details to %s, please try again later"; public static final String ENCODED_ERROR = "Encode error for %s"; public static final String INVALID_API_KEY_TYPE = "Invalid API key type."; public static final String INVALID_PARAMETER = "Invalid parameter: %s."; - public static final String INVALID_PAYMENT = - "The chosen payment method is not a credit card. Please try again."; + public static final String INVALID_PAYMENT = "The chosen payment method is not a credit card. Please try again."; public static final String INVALID_WEBHOOK_SIGNATURE = "Webhook does not contain a valid HMAC signature."; public static final String MISSING_REQUIRED_PARAMETER = "Missing required parameter: %s."; public static final String NO_OBJECT_FOUND = "No %s found."; - public static final String NO_PAYMENT_METHODS = - "No payment methods are set up. Please add a payment method and try again."; + public static final String NO_PAYMENT_METHODS = "No payment methods are set up. Please add a payment method and try again."; public static final String API_DID_NOT_RETURN_ERROR_DETAILS = "API did not return error details."; - public static final String WEBHOOK_DOES_NOT_MATCH = - "Webhook received did not originate from EasyPost or had a webhook secret mismatch."; + public static final String WEBHOOK_DOES_NOT_MATCH = "Webhook received did not originate from EasyPost or had a webhook secret mismatch."; public static final String NO_MORE_PAGES_TO_RETRIEVE = "There are no more pages to retrieve."; } @@ -62,16 +58,13 @@ public abstract static class ErrorCodes { public abstract static class CarrierAccountTypes { public static final List CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOW = ImmutableList.of( - "FedexAccount", "FedexSmartpostAccount" - ); + "FedexAccount", "FedexSmartpostAccount"); public static final List UPS_OAUTH_CARRIER_ACCOUNT_TYPES = ImmutableList.of( - "UpsAccount", "UpsMailInnovationsAccount", "UpsSurepostAccount" - ); + "UpsAccount", "UpsMailInnovationsAccount", "UpsSurepostAccount"); public static final List CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = ImmutableList.of( - "AmazonShippingAccount" - ); + "AmazonShippingAccount"); } public abstract static class Http { @@ -83,7 +76,7 @@ public abstract static class Http { public static final Gson GSON = new GsonBuilder() .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .registerTypeAdapter(HashMap.class, new HashMapSerializer()) - .registerTypeAdapter(SmartrateCollection.class, new SmartrateCollectionDeserializer()) + .registerTypeAdapter(SmartRateCollection.class, new SmartRateCollectionDeserializer()) .registerTypeAdapter(APIException.class, new ErrorDeserializer()) .registerTypeAdapter(AddressVerification.class, new AddressVerificationDeserializer()) .registerTypeAdapter(StatelessRate[].class, new StatelessRateDeserializer()) diff --git a/src/main/java/com/easypost/model/AddressVerificationDeserializer.java b/src/main/java/com/easypost/model/AddressVerificationDeserializer.java index 1523fe4c8..2986edd44 100644 --- a/src/main/java/com/easypost/model/AddressVerificationDeserializer.java +++ b/src/main/java/com/easypost/model/AddressVerificationDeserializer.java @@ -18,11 +18,12 @@ public final class AddressVerificationDeserializer implements JsonDeserializer { /** - * Recursively traverse an error JSON element and its sub-element(s), and extracts all + * Recursively traverse an error JSON element and its sub-element(s), and + * extracts all * error string values found into the specified string list. * - * @param element the JSON element to traverse + * @param element the JSON element to traverse * @param messagesList the list of strings to append found values to */ private void traverseJsonElement(JsonElement element, ArrayList messagesList) { @@ -45,11 +46,12 @@ private void traverseJsonElement(JsonElement element, ArrayList messages * @param typeOfT Type of the object to deserialize. * @param context Deserialization context. * @return Deserialized APIException object. - * @throws JsonParseException if the JSON object is not a valid SmartrateCollection. + * @throws JsonParseException if the JSON object is not a valid + * SmartRateCollection. */ @Override public APIException deserialize(final JsonElement json, final Type typeOfT, - final JsonDeserializationContext context) throws JsonParseException { + final JsonDeserializationContext context) throws JsonParseException { JsonObject jo = json.getAsJsonObject(); String message = null; @@ -83,7 +85,6 @@ public APIException deserialize(final JsonElement json, final Type typeOfT, } JsonElement errorsAsJson = errorData.get("errors"); - List errorList = new ArrayList<>(); if (errorsAsJson != null) { JsonArray errorsAsArray = errorsAsJson.getAsJsonArray(); for (JsonElement errorAsJson : errorsAsArray) { @@ -106,13 +107,13 @@ public APIException deserialize(final JsonElement json, final Type typeOfT, fieldError.setSuggestion(suggestion.getAsString()); } - errorList.add(fieldError); + errors.add(fieldError); } else { - errorList.add(errorAsJson.getAsString()); + errors.add(errorAsJson.getAsString()); } } } - return new APIException(message, code, errorList); + return new APIException(message, code, errors); } } diff --git a/src/main/java/com/easypost/model/SmartrateAccuracy.java b/src/main/java/com/easypost/model/SmartRateAccuracy.java similarity index 83% rename from src/main/java/com/easypost/model/SmartrateAccuracy.java rename to src/main/java/com/easypost/model/SmartRateAccuracy.java index ae5b7cc48..c08b6645d 100644 --- a/src/main/java/com/easypost/model/SmartrateAccuracy.java +++ b/src/main/java/com/easypost/model/SmartRateAccuracy.java @@ -6,7 +6,7 @@ import lombok.Getter; @Getter -public enum SmartrateAccuracy { +public enum SmartRateAccuracy { Percentile50("percentile_50"), Percentile75("percentile_75"), Percentile85("percentile_85"), @@ -22,7 +22,7 @@ public enum SmartrateAccuracy { * * @param keyName the internal key name */ - SmartrateAccuracy(String keyName) { + SmartRateAccuracy(String keyName) { this.keyName = keyName; } @@ -33,8 +33,8 @@ public enum SmartrateAccuracy { * @return the enum value * @throws EasyPostException if the key name is not found */ - public static SmartrateAccuracy getByKeyName(String keyName) throws EasyPostException { - for (SmartrateAccuracy smartrateAccuracy : values()) { + public static SmartRateAccuracy getByKeyName(String keyName) throws EasyPostException { + for (SmartRateAccuracy smartrateAccuracy : values()) { if (smartrateAccuracy.getKeyName().equals(keyName)) { return smartrateAccuracy; } diff --git a/src/main/java/com/easypost/model/SmartRateCollection.java b/src/main/java/com/easypost/model/SmartRateCollection.java new file mode 100644 index 000000000..a21d0050b --- /dev/null +++ b/src/main/java/com/easypost/model/SmartRateCollection.java @@ -0,0 +1,51 @@ +package com.easypost.model; + +import java.util.ArrayList; +import java.util.List; + +public final class SmartRateCollection { + private List smartRates; + + /** + * Get this SmartRateCollection's Smartrate objects. + * + * @return List of Smartrate objects. + */ + public List getSmartRates() { + return this.smartRates; + } + + /** + * Set this SmartRateCollection's Smartrate objects. + * + * @param smartRates List of Smartrate objects. + */ + public void setSmartrates(final List smartRates) { + this.smartRates = smartRates; + } + + /** + * Constructor. + */ + public SmartRateCollection() { + this.smartRates = new ArrayList(); + } + + /** + * Create a SmartRateCollection from a list of rates. + * + * @param smartRates List of Smartrate objects + */ + public SmartRateCollection(final List smartRates) { + setSmartrates(smartRates); + } + + /** + * Add a SmartRate object to this SmartRateCollection. + * + * @param rate Rate object + */ + public void addRate(final SmartRate rate) { + smartRates.add(rate); + } +} diff --git a/src/main/java/com/easypost/model/SmartrateCollectionDeserializer.java b/src/main/java/com/easypost/model/SmartRateCollectionDeserializer.java similarity index 68% rename from src/main/java/com/easypost/model/SmartrateCollectionDeserializer.java rename to src/main/java/com/easypost/model/SmartRateCollectionDeserializer.java index e0a98cc87..18715c89e 100644 --- a/src/main/java/com/easypost/model/SmartrateCollectionDeserializer.java +++ b/src/main/java/com/easypost/model/SmartRateCollectionDeserializer.java @@ -8,27 +8,29 @@ import java.lang.reflect.Type; -public final class SmartrateCollectionDeserializer implements JsonDeserializer { +public final class SmartRateCollectionDeserializer implements JsonDeserializer { /** - * Deserialize a SmartrateCollection from a JSON object. + * Deserialize a SmartRateCollection from a JSON object. * * @param json JSON object to deserialize. * @param typeOfT Type of the object to deserialize. * @param context Deserialization context. - * @return Deserialized SmartrateCollection object. - * @throws JsonParseException if the JSON object is not a valid SmartrateCollection. + * @return Deserialized SmartRateCollection object. + * @throws JsonParseException if the JSON object is not a valid + * SmartRateCollection. */ @Override - public SmartrateCollection deserialize(final JsonElement json, final Type typeOfT, - final JsonDeserializationContext context) throws JsonParseException { - SmartrateCollection smartrateCollection = new SmartrateCollection(); + public SmartRateCollection deserialize(final JsonElement json, final Type typeOfT, + final JsonDeserializationContext context) throws JsonParseException { + SmartRateCollection smartrateCollection = new SmartRateCollection(); JsonObject jo = (JsonObject) json; JsonElement results = jo.get("result"); if (results == null || !results.isJsonArray()) { return smartrateCollection; - // return empty collection if "results" key does not exist or corresponding value is not an array + // return empty collection if "results" key does not exist or corresponding + // value is not an array } // the JsonDeserializationContext should have access to the other type adapters, // so we can tap into the RateDeserializer from here diff --git a/src/main/java/com/easypost/model/SmartrateCollection.java b/src/main/java/com/easypost/model/SmartrateCollection.java deleted file mode 100644 index 3113401ec..000000000 --- a/src/main/java/com/easypost/model/SmartrateCollection.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.easypost.model; - -import java.util.ArrayList; -import java.util.List; - -public final class SmartrateCollection { - private List smartrates; - - /** - * Get this SmartrateCollection's Smartrate objects. - * - * @return List of Smartrate objects. - */ - public List getSmartrates() { - return this.smartrates; - } - - /** - * Set this SmartrateCollection's Smartrate objects. - * - * @param smartrates List of Smartrate objects. - */ - public void setSmartrates(final List smartrates) { - this.smartrates = smartrates; - } - - /** - * Constructor. - */ - public SmartrateCollection() { - this.smartrates = new ArrayList(); - } - - /** - * Create a SmartrateCollection from a list of rates. - * - * @param smartrates List of Smartrate objects - */ - public SmartrateCollection(final List smartrates) { - setSmartrates(smartrates); - } - - /** - * Add a SmartRate object to this SmartrateCollection. - * - * @param rate Rate object - */ - public void addRate(final SmartRate rate) { - smartrates.add(rate); - } -} diff --git a/src/main/java/com/easypost/model/TimeInTransit.java b/src/main/java/com/easypost/model/TimeInTransit.java index 8283945f9..927c162a9 100644 --- a/src/main/java/com/easypost/model/TimeInTransit.java +++ b/src/main/java/com/easypost/model/TimeInTransit.java @@ -27,11 +27,11 @@ public final class TimeInTransit { /** * Get the delivery accuracy of a specific percentile of this TimeInTransit. * - * @param accuracy the SmartrateAccuracy to find the corresponding accuracy for + * @param accuracy the SmartRateAccuracy to find the corresponding accuracy for * @return the delivery accuracy of the specified percentile * @throws EasyPostException when the percentile is not valid */ - public int getBySmartrateAccuracy(SmartrateAccuracy accuracy) throws EasyPostException { + public int getSmartRateAccuracy(SmartRateAccuracy accuracy) throws EasyPostException { switch (accuracy) { case Percentile50: return this.percentile50; diff --git a/src/main/java/com/easypost/service/ShipmentService.java b/src/main/java/com/easypost/service/ShipmentService.java index ddc7cbee2..4c6283992 100644 --- a/src/main/java/com/easypost/service/ShipmentService.java +++ b/src/main/java/com/easypost/service/ShipmentService.java @@ -14,8 +14,8 @@ import com.easypost.model.RecommendShipDateResponse; import com.easypost.model.Shipment; import com.easypost.model.SmartRate; -import com.easypost.model.SmartrateAccuracy; -import com.easypost.model.SmartrateCollection; +import com.easypost.model.SmartRateAccuracy; +import com.easypost.model.SmartRateCollection; import com.easypost.utils.InternalUtilities; import lombok.SneakyThrows; @@ -39,7 +39,7 @@ public class ShipmentService { /** * Create a new Shipment object from a map of parameters. * - * @param params The map of parameters. + * @param params The map of parameters. * @return Shipment object * @throws EasyPostException when the request fails. */ @@ -77,7 +77,8 @@ public ShipmentCollection all(final Map params) throws EasyPostE ShipmentCollection shipmentCollection = Requestor.request(RequestMethod.GET, endpoint, params, ShipmentCollection.class, client); - // we store the params in the collection so that we can use them to get the next page + // we store the params in the collection so that we can use them to get the next + // page shipmentCollection.setPurchased(InternalUtilities.getOrDefault(params, "purchased", null)); shipmentCollection.setIncludeChildren(InternalUtilities.getOrDefault(params, "include_children", null)); @@ -106,7 +107,8 @@ public ShipmentCollection getNextPage(ShipmentCollection collection) throws EndO */ public ShipmentCollection getNextPage(ShipmentCollection collection, Integer pageSize) throws EndOfPaginationError { return collection.getNextPage(new Function, ShipmentCollection>() { - @Override @SneakyThrows + @Override + @SneakyThrows public ShipmentCollection apply(Map parameters) { return all(parameters); } @@ -127,8 +129,8 @@ public Shipment newRates(final String id) throws EasyPostException { /** * Get new rates for this Shipment. * - * @param id The ID of shipment. - * @param params The options for the query. + * @param id The ID of shipment. + * @param params The options for the query. * @return Shipment object * @throws EasyPostException when the request fails. */ @@ -145,8 +147,8 @@ public Shipment newRates(final String id, final Map params) thro * @return List of SmartRate objects * @throws EasyPostException when the request fails. */ - public List smartrates(final String id) throws EasyPostException { - return this.smartrates(id, null); + public List smartRates(final String id) throws EasyPostException { + return this.smartRates(id, null); } /** @@ -157,13 +159,13 @@ public List smartrates(final String id) throws EasyPostException { * @return List of SmartRate objects * @throws EasyPostException when the request fails. */ - public List smartrates(final String id, final Map params) throws EasyPostException { + public List smartRates(final String id, final Map params) throws EasyPostException { String endpoint = "shipments/" + id + "/smartrate"; - SmartrateCollection smartrateCollection = Requestor.request(RequestMethod.GET, endpoint, params, - SmartrateCollection.class, client); + SmartRateCollection smartRateCollection = Requestor.request(RequestMethod.GET, endpoint, params, + SmartRateCollection.class, client); - return smartrateCollection.getSmartrates(); + return smartRateCollection.getSmartRates(); } /** @@ -212,9 +214,9 @@ public Shipment buy(final String id, final Rate rate, final String endShipperId) /** * Buy this Shipment. * - * @param id The ID of shipment. - * @param params The options for the query. - * @param endShipperId The id of the end shipper to use for this purchase. + * @param id The ID of shipment. + * @param params The options for the query. + * @param endShipperId The id of the end shipper to use for this purchase. * @return Shipment object * @throws EasyPostException when the request fails. */ @@ -292,13 +294,13 @@ public Shipment insure(final String id, final Map params) throws * @return lowest SmartRate object * @throws EasyPostException when the request fails. */ - public SmartRate lowestSmartRate(final String id, final int deliveryDay, SmartrateAccuracy deliveryAccuracy) + public SmartRate lowestSmartRate(final String id, final int deliveryDay, SmartRateAccuracy deliveryAccuracy) throws EasyPostException { - List smartrates = this.smartrates(id, null); + List smartrates = this.smartRates(id, null); - SmartRate lowestSmartrate = findLowestSmartrate(smartrates, deliveryDay, deliveryAccuracy); + SmartRate lowestSmartRate = findLowestSmartRate(smartrates, deliveryDay, deliveryAccuracy); - return lowestSmartrate; + return lowestSmartRate; } /** @@ -308,28 +310,28 @@ public SmartRate lowestSmartRate(final String id, final int deliveryDay, Smartra * @param deliveryDay Delivery days restriction to use when filtering. * @param deliveryAccuracy Delivery days accuracy restriction to use when * filtering. - * @return lowest Smartrate object + * @return lowest SmartRate object * @throws EasyPostException when the request fails. */ - public SmartRate findLowestSmartrate(final List smartRates, int deliveryDay, - SmartrateAccuracy deliveryAccuracy) throws EasyPostException { - SmartRate lowestSmartrate = null; + public SmartRate findLowestSmartRate(final List smartRates, int deliveryDay, + SmartRateAccuracy deliveryAccuracy) throws EasyPostException { + SmartRate lowestSmartRate = null; for (SmartRate rate : smartRates) { - int smartrateDeliveryDay = rate.getTimeInTransit().getBySmartrateAccuracy(deliveryAccuracy); + int smartrateDeliveryDay = rate.getTimeInTransit().getSmartRateAccuracy(deliveryAccuracy); if (smartrateDeliveryDay > deliveryDay) { continue; - } else if (lowestSmartrate == null || rate.getRate() < lowestSmartrate.getRate()) { - lowestSmartrate = rate; + } else if (lowestSmartRate == null || rate.getRate() < lowestSmartRate.getRate()) { + lowestSmartRate = rate; } } - if (lowestSmartrate == null) { + if (lowestSmartRate == null) { throw new FilteringError(String.format(Constants.ErrorMessages.NO_OBJECT_FOUND, "rate")); } - return lowestSmartrate; + return lowestSmartRate; } /** @@ -388,10 +390,11 @@ public List retrieveEstimatedDeliveryDate(final String id } /** - * Retrieve a recommended ship date for an existing Shipment via the Precision Shipping API, + * Retrieve a recommended ship date for an existing Shipment via the Precision + * Shipping API, * based on a specific desired delivery date. * - * @param id The id of the shipment. + * @param id The id of the shipment. * @param desiredDeliveryDate The desired delivery date. * @return EstimatedDeliveryDate object. * @throws EasyPostException When the request fails. diff --git a/src/main/java/com/easypost/utils/Utilities.java b/src/main/java/com/easypost/utils/Utilities.java index e01848563..80d6545d9 100644 --- a/src/main/java/com/easypost/utils/Utilities.java +++ b/src/main/java/com/easypost/utils/Utilities.java @@ -7,7 +7,7 @@ import com.easypost.model.Event; import com.easypost.model.Rate; import com.easypost.model.SmartRate; -import com.easypost.model.SmartrateAccuracy; +import com.easypost.model.SmartRateAccuracy; import com.easypost.model.StatelessRate; import java.util.List; @@ -139,33 +139,33 @@ public static Event validateWebhook(byte[] eventBody, Map header } /** - * Find the lowest Smartrate from a list of Smartrates. + * Find the lowest SmartRate from a list of SmartRates. * - * @param smartrates List of Smartrates to filter from. + * @param smartRates List of SmartRates to filter from. * @param deliveryDay Delivery days restriction to use when filtering. * @param deliveryAccuracy Delivery days accuracy restriction to use when * filtering. - * @return lowest Smartrate object + * @return lowest SmartRate object * @throws EasyPostException when the request fails. */ - public static SmartRate findLowestSmartrate(final List smartrates, int deliveryDay, - SmartrateAccuracy deliveryAccuracy) throws EasyPostException { - SmartRate lowestSmartrate = null; + public static SmartRate findLowestSmartRate(final List smartRates, int deliveryDay, + SmartRateAccuracy deliveryAccuracy) throws EasyPostException { + SmartRate lowestSmartRate = null; - for (SmartRate rate : smartrates) { - int smartrateDeliveryDay = rate.getTimeInTransit().getBySmartrateAccuracy(deliveryAccuracy); + for (SmartRate rate : smartRates) { + int smartrateDeliveryDay = rate.getTimeInTransit().getSmartRateAccuracy(deliveryAccuracy); if (smartrateDeliveryDay > deliveryDay) { continue; - } else if (lowestSmartrate == null || rate.getRate() < lowestSmartrate.getRate()) { - lowestSmartrate = rate; + } else if (lowestSmartRate == null || rate.getRate() < lowestSmartRate.getRate()) { + lowestSmartRate = rate; } } - if (lowestSmartrate == null) { + if (lowestSmartRate == null) { throw new FilteringError(String.format(Constants.ErrorMessages.NO_OBJECT_FOUND, "rate")); } - return lowestSmartrate; + return lowestSmartRate; } } diff --git a/src/test/java/com/easypost/ShipmentTest.java b/src/test/java/com/easypost/ShipmentTest.java index 8da0cff38..e7be8ee88 100644 --- a/src/test/java/com/easypost/ShipmentTest.java +++ b/src/test/java/com/easypost/ShipmentTest.java @@ -12,7 +12,7 @@ import com.easypost.model.Shipment; import com.easypost.model.ShipmentCollection; import com.easypost.model.SmartRate; -import com.easypost.model.SmartrateAccuracy; +import com.easypost.model.SmartRateAccuracy; import com.easypost.utils.Utilities; import com.google.common.collect.ImmutableList; import org.junit.jupiter.api.BeforeAll; @@ -195,8 +195,10 @@ public void testGetNextPageParameterHandOff() throws EasyPostException { ShipmentCollection shipmentCollection = vcr.client.shipment.all(params); - // Can't access protected method directly, need to make a temporary extended class, yay - // Downside, ShipmentCollection and Shipment are no longer final because they need to be extended + // Can't access protected method directly, need to make a temporary extended + // class, yay + // Downside, ShipmentCollection and Shipment are no longer final because they + // need to be extended final class ExtendedShipmentCollection extends ShipmentCollection { ExtendedShipmentCollection(ShipmentCollection shipmentCollection) { @@ -366,7 +368,7 @@ public void testRefund() throws EasyPostException { } /** - * Test getting Smartrates from a shipment. + * Test getting SmartRates from a shipment. * * @throws EasyPostException when the request fails. */ @@ -379,7 +381,7 @@ public void testSmartRate() throws EasyPostException { assertNotNull(shipment.getRates()); Rate rate = shipment.getRates().get(0); - List smartRates = vcr.client.shipment.smartrates(shipment.getId()); + List smartRates = vcr.client.shipment.smartRates(shipment.getId()); assertInstanceOf(List.class, smartRates); SmartRate smartRate = smartRates.get(0); @@ -455,8 +457,10 @@ public void testCreateTaxIdentifiers() throws EasyPostException { public void testCreateWithIds() throws EasyPostException { vcr.setUpTest("create_with_ids"); - // VCR will overwrite the first address recording if the parameters are the exact same, - // which will cause us to lose the response from the first address creation and cause the replay to fail. + // VCR will overwrite the first address recording if the parameters are the + // exact same, + // which will cause us to lose the response from the first address creation and + // cause the replay to fail. // So wee need to use two different addresses here. Address fromAddress = vcr.client.address.create(Fixtures.caAddress1()); Address toAddress = vcr.client.address.create(Fixtures.caAddress2()); @@ -510,7 +514,7 @@ public void testLowestRate() throws EasyPostException { } /** - * Test getting the lowest Smartrate of a shipment. + * Test getting the lowest SmartRate of a shipment. * * @throws EasyPostException when the request fails. */ @@ -520,7 +524,7 @@ public void testInstanceLowestSmartRate() throws EasyPostException { Shipment shipment = createBasicShipment(); SmartRate lowestSmartRateFilters = vcr.client.shipment.lowestSmartRate(shipment.getId(), 3, - SmartrateAccuracy.Percentile90); + SmartRateAccuracy.Percentile90); // Test lowest smartrate with valid filters assertEquals("GroundAdvantage", lowestSmartRateFilters.getService()); @@ -530,7 +534,7 @@ public void testInstanceLowestSmartRate() throws EasyPostException { // Test lowest smartrate with invalid filters (should error due to strict // delivery days) assertThrows(EasyPostException.class, () -> { - vcr.client.shipment.lowestSmartRate(shipment.getId(), 0, SmartrateAccuracy.Percentile90); + vcr.client.shipment.lowestSmartRate(shipment.getId(), 0, SmartRateAccuracy.Percentile90); }); } @@ -545,7 +549,7 @@ public void testGetSmartRate() throws EasyPostException { Shipment shipment = createBasicShipment(); - List rates = vcr.client.shipment.smartrates(shipment.getId()); + List rates = vcr.client.shipment.smartRates(shipment.getId()); assertInstanceOf(List.class, rates); @@ -560,17 +564,17 @@ public void testGetSmartRate() throws EasyPostException { * @throws EasyPostException if an exception is thrown. */ @Test - public void testGetLowestSmartRate() throws EasyPostException { + public void testFindLowestSmartRate() throws EasyPostException { vcr.setUpTest("get_lowest_smartrate"); Shipment shipment = createBasicShipment(); - List rates = vcr.client.shipment.smartrates(shipment.getId()); - SmartRate lowestSmartrate = vcr.client.shipment.findLowestSmartrate(rates, 3, SmartrateAccuracy.Percentile85); + List rates = vcr.client.shipment.smartRates(shipment.getId()); + SmartRate lowestSmartRate = vcr.client.shipment.findLowestSmartRate(rates, 3, SmartRateAccuracy.Percentile85); - assertEquals("GroundAdvantage", lowestSmartrate.getService()); - assertEquals(5.93, lowestSmartrate.getRate(), 0.01); - assertEquals("USPS", lowestSmartrate.getCarrier()); + assertEquals("GroundAdvantage", lowestSmartRate.getService()); + assertEquals(5.93, lowestSmartRate.getRate(), 0.01); + assertEquals("USPS", lowestSmartRate.getCarrier()); } /** @@ -583,10 +587,10 @@ public void testStaticLowestSmartRates() throws EasyPostException { vcr.setUpTest("lowest_smartrate_list"); Shipment shipment = createBasicShipment(); - List smartRates = vcr.client.shipment.smartrates(shipment.getId()); + List smartRates = vcr.client.shipment.smartRates(shipment.getId()); // Test lowest smartrate with valid filters - SmartRate lowestSmartRate = Utilities.findLowestSmartrate(smartRates, 3, SmartrateAccuracy.Percentile90); + SmartRate lowestSmartRate = Utilities.findLowestSmartRate(smartRates, 3, SmartRateAccuracy.Percentile90); assertEquals("GroundAdvantage", lowestSmartRate.getService()); assertEquals(5.93, lowestSmartRate.getRate(), 0.01); assertEquals("USPS", lowestSmartRate.getCarrier()); @@ -594,7 +598,7 @@ public void testStaticLowestSmartRates() throws EasyPostException { // Test lowest smartrate with invalid filters (should error due to strict // delivery days) assertThrows(EasyPostException.class, () -> { - Utilities.findLowestSmartrate(smartRates, 0, SmartrateAccuracy.Percentile90); + Utilities.findLowestSmartRate(smartRates, 0, SmartRateAccuracy.Percentile90); }); } @@ -682,7 +686,8 @@ public void testBuyShipmentWithEndShipperId() throws EasyPostException { } /** - * Tests that we retrieve time-in-transit data for each of the Rates of a Shipment. + * Tests that we retrieve time-in-transit data for each of the Rates of a + * Shipment. * * @throws EasyPostException when the request fails. */ @@ -703,7 +708,8 @@ public void testRetrieveEstimatedDeliveryDate() throws EasyPostException { } /** - * Test that we retrieve SmartRates when providing a shipment and desired delivery date. + * Test that we retrieve SmartRates when providing a shipment and desired + * delivery date. * * @throws EasyPostException when the request fails. */ From 78571a00c11b23815d43974820bacc39b9d03fa2 Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Tue, 29 Apr 2025 13:34:25 -0600 Subject: [PATCH 3/4] fix: smartrate namings --- src/main/java/com/easypost/model/SmartRateCollection.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/easypost/model/SmartRateCollection.java b/src/main/java/com/easypost/model/SmartRateCollection.java index a21d0050b..60b5eef58 100644 --- a/src/main/java/com/easypost/model/SmartRateCollection.java +++ b/src/main/java/com/easypost/model/SmartRateCollection.java @@ -20,7 +20,7 @@ public List getSmartRates() { * * @param smartRates List of Smartrate objects. */ - public void setSmartrates(final List smartRates) { + public void setSmartRates(final List smartRates) { this.smartRates = smartRates; } @@ -37,7 +37,7 @@ public SmartRateCollection() { * @param smartRates List of Smartrate objects */ public SmartRateCollection(final List smartRates) { - setSmartrates(smartRates); + setSmartRates(smartRates); } /** From 7356672ec60fcd187b4e669038097f6b9cb431bc Mon Sep 17 00:00:00 2001 From: Justintime50 <39606064+Justintime50@users.noreply.github.com> Date: Tue, 29 Apr 2025 14:36:02 -0600 Subject: [PATCH 4/4] fix: lint --- src/main/java/com/easypost/Constants.java | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/easypost/Constants.java b/src/main/java/com/easypost/Constants.java index 934685d9d..5485932de 100644 --- a/src/main/java/com/easypost/Constants.java +++ b/src/main/java/com/easypost/Constants.java @@ -24,17 +24,21 @@ public abstract class Constants { public static final String EASYPOST_SUPPORT_EMAIL = "support@easypost.com"; public abstract static class ErrorMessages { - public static final String EXTERNAL_API_CALL_FAILED = "Could not send card details to %s, please try again later"; + public static final String EXTERNAL_API_CALL_FAILED = + "Could not send card details to %s, please try again later"; public static final String ENCODED_ERROR = "Encode error for %s"; public static final String INVALID_API_KEY_TYPE = "Invalid API key type."; public static final String INVALID_PARAMETER = "Invalid parameter: %s."; - public static final String INVALID_PAYMENT = "The chosen payment method is not a credit card. Please try again."; + public static final String INVALID_PAYMENT = + "The chosen payment method is not a credit card. Please try again."; public static final String INVALID_WEBHOOK_SIGNATURE = "Webhook does not contain a valid HMAC signature."; public static final String MISSING_REQUIRED_PARAMETER = "Missing required parameter: %s."; public static final String NO_OBJECT_FOUND = "No %s found."; - public static final String NO_PAYMENT_METHODS = "No payment methods are set up. Please add a payment method and try again."; + public static final String NO_PAYMENT_METHODS = + "No payment methods are set up. Please add a payment method and try again."; public static final String API_DID_NOT_RETURN_ERROR_DETAILS = "API did not return error details."; - public static final String WEBHOOK_DOES_NOT_MATCH = "Webhook received did not originate from EasyPost or had a webhook secret mismatch."; + public static final String WEBHOOK_DOES_NOT_MATCH = + "Webhook received did not originate from EasyPost or had a webhook secret mismatch."; public static final String NO_MORE_PAGES_TO_RETRIEVE = "There are no more pages to retrieve."; } @@ -58,13 +62,16 @@ public abstract static class ErrorCodes { public abstract static class CarrierAccountTypes { public static final List CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_WORKFLOW = ImmutableList.of( - "FedexAccount", "FedexSmartpostAccount"); + "FedexAccount", "FedexSmartpostAccount" + ); public static final List UPS_OAUTH_CARRIER_ACCOUNT_TYPES = ImmutableList.of( - "UpsAccount", "UpsMailInnovationsAccount", "UpsSurepostAccount"); + "UpsAccount", "UpsMailInnovationsAccount", "UpsSurepostAccount" + ); public static final List CARRIER_ACCOUNT_TYPES_WITH_CUSTOM_OAUTH = ImmutableList.of( - "AmazonShippingAccount"); + "AmazonShippingAccount" + ); } public abstract static class Http {