Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove carbon offset parameter and batch create_and_buy function #292

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## Next Major Release

- Removed `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

## v6.9.1 (2023-11-16)

- Fixes a bug where address verification errors were not being properly deserialized
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/com/easypost/service/BatchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,6 @@ public BatchCollection all(final Map<String, Object> params) throws EasyPostExce

// TODO: Add getNextPage function when Batches are sorted newest to oldest.

/**
* Create and buy a Batch object in one step.
*
* @param params Map of parameters.
* @return Batch object.
* @throws EasyPostException when the request fails.
*/
public Batch createAndBuy(final Map<String, Object> params) throws EasyPostException {
Map<String, Object> wrappedParams = new HashMap<String, Object>();
wrappedParams.put("batch", params);

String endpoint = "batches";

return Requestor.request(RequestMethod.POST, endpoint, wrappedParams, Batch.class, client);
}

/**
* Label this Batch object.
*
Expand Down
108 changes: 7 additions & 101 deletions src/main/java/com/easypost/service/ShipmentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,16 @@ public class ShipmentService {
this.client = client;
}

/**
* Create a new Shipment object from a map of parameters.
*
* @param params The map of parameters.
* @return Shipment object
* @throws EasyPostException when the request fails.
*/
public Shipment create(final Map<String, Object> params) throws EasyPostException {
return this.create(params, false);
}

/**
* Create a new Shipment object from a map of parameters.
*
* @param params The map of parameters.
* @param withCarbonOffset Whether to include a carbon offset when creating the
* shipment.
* @return Shipment object
* @throws EasyPostException when the request fails.
*/
public Shipment create(final Map<String, Object> params, boolean withCarbonOffset) throws EasyPostException {
public Shipment create(final Map<String, Object> params) throws EasyPostException {
Map<String, Object> wrappedParams = new HashMap<>();
wrappedParams.put("shipment", params);
wrappedParams.put("carbon_offset", withCarbonOffset);

String endpoint = "shipments";

Expand Down Expand Up @@ -137,45 +123,15 @@ public Shipment newRates(final String id) throws EasyPostException {
return this.newRates(id, new HashMap<String, Object>());
}

/**
* Get new rates for this Shipment.
*
* @param id The ID of shipment.
* @param withCarbonOffset Whether to include a carbon offset when re-rating the
* shipment.
* @return Shipment object
* @throws EasyPostException when the request fails.
*/
public Shipment newRates(final String id, final boolean withCarbonOffset) throws EasyPostException {
return this.newRates(id, new HashMap<String, Object>() {}, withCarbonOffset);
}

/**
* Get new rates for this Shipment.
*
* @param id The ID of shipment.
* @param params The options for the query.
* @return Shipment object
* @throws EasyPostException when the request fails.
*/
public Shipment newRates(final String id, final Map<String, Object> params) throws EasyPostException {
return this.newRates(id, params, false);
}

/**
* Get new rates for this Shipment.
*
* @param id The ID of shipment.
* @param params The options for the query.
* @param withCarbonOffset Whether to include a carbon offset when re-rating the
* shipment.
* @return Shipment object
* @throws EasyPostException when the request fails.
*/
public Shipment newRates(final String id, final Map<String, Object> params, final boolean withCarbonOffset)
throws EasyPostException {
params.put("carbon_offset", withCarbonOffset);

public Shipment newRates(final String id, final Map<String, Object> params) throws EasyPostException {
String endpoint = "shipments/" + id + "/rerate";

return Requestor.request(RequestMethod.POST, endpoint, params, Shipment.class, client);
Expand Down Expand Up @@ -235,7 +191,7 @@ public List<SmartRate> smartrates(final String id, final Map<String, Object> par
* @throws EasyPostException when the request fails.
*/
public Shipment buy(final String id, final Map<String, Object> params) throws EasyPostException {
return this.buy(id, params, false);
return this.buy(id, params, null);
}

/**
Expand All @@ -250,24 +206,7 @@ public Shipment buy(final String id, final Rate rate) throws EasyPostException {
Map<String, Object> params = new HashMap<>();
params.put("rate", rate);

return this.buy(id, params, false, null);
}

/**
* Buy this Shipment.
*
* @param id The ID of shipment.
* @param rate The Rate to use for this Shipment.
* @param withCarbonOffset Whether to include a carbon offset when buying the
* shipment.
* @return Shipment object
* @throws EasyPostException when the request fails.
*/
public Shipment buy(final String id, final Rate rate, final boolean withCarbonOffset) throws EasyPostException {
Map<String, Object> params = new HashMap<>();
params.put("rate", rate);

return this.buy(id, params, withCarbonOffset, null);
return this.buy(id, params, null);
}

/**
Expand All @@ -283,53 +222,20 @@ public Shipment buy(final String id, final Rate rate, final String endShipperId)
Map<String, Object> params = new HashMap<>();
params.put("rate", rate);

return this.buy(id, params, false, endShipperId);
}

/**
* Buy this Shipment.
*
* @param id The ID of shipment.
* @param params The options for the query.
* @param endShipperId The ID of the endshipper.
* @return Shipment object
* @throws EasyPostException when the request fails.
*/
public Shipment buy(final String id, final Map<String, Object> params, final String endShipperId)
throws EasyPostException {
return this.buy(id, params, false, endShipperId);
return this.buy(id, params, endShipperId);
}

/**
* Buy this Shipment.
*
* @param id The ID of shipment.
* @param params The options for the query.
* @param withCarbonOffset Whether to include a carbon offset when buying the
* shipment.
* @return Shipment object
* @throws EasyPostException when the request fails.
*/
public Shipment buy(final String id, final Map<String, Object> params, final boolean withCarbonOffset)
throws EasyPostException {
return this.buy(id, params, withCarbonOffset, null);
}

/**
* Buy this Shipment.
*
* @param id The ID of shipment.
* @param params The options for the query.
* @param withCarbonOffset Whether to include a carbon offset when buying the
* shipment.
* @param endShipperId The id of the end shipper to use for this purchase.
* @return Shipment object
* @throws EasyPostException when the request fails.
*/
public Shipment buy(final String id, final Map<String, Object> params, final boolean withCarbonOffset,
final String endShipperId) throws EasyPostException {
params.put("carbon_offset", withCarbonOffset);

public Shipment buy(final String id, final Map<String, Object> params, final String endShipperId)
throws EasyPostException {
if (endShipperId != null && !endShipperId.isEmpty()) {
params.put("end_shipper_id", endShipperId);
}
Expand Down
Loading