Skip to content

Commit 9f6562d

Browse files
author
jchen293
authored
add endshipper id in shipment buy and remove unnecessary buy functions (#183)
1 parent 1204c9e commit 9f6562d

File tree

2 files changed

+62
-33
lines changed

2 files changed

+62
-33
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## Next Release
4+
5+
- Can indicate an EndShipper ID when buying a shipment
6+
- Removes unusable shipment `buy` functions that did not contain a rate parameter
7+
38
## v5.9.0 (2022-08-25)
49

510
- Moves EndShipper out of beta into the general library namespace

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

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -912,123 +912,147 @@ public List<Smartrate> smartrates(final String apiKey) throws EasyPostException
912912
/**
913913
* Buy this Shipment.
914914
*
915+
* @param params the options for the query.
915916
* @return Shipment object
916917
* @throws EasyPostException when the request fails.
917918
*/
918-
public Shipment buy() throws EasyPostException {
919-
return this.buy(new HashMap<String, Object>() {}, false, null);
919+
public Shipment buy(final Map<String, Object> params) throws EasyPostException {
920+
return this.buy(params, false, null);
920921
}
921922

922923
/**
923924
* Buy this Shipment.
924925
*
925-
* @param withCarbonOffset whether to include a carbon offset when buying the shipment.
926+
* @param rate the Rate to use for this Shipment.
926927
* @return Shipment object
927928
* @throws EasyPostException when the request fails.
928929
*/
929-
public Shipment buy(final boolean withCarbonOffset) throws EasyPostException {
930-
return this.buy(new HashMap<String, Object>() {}, withCarbonOffset, null);
930+
public Shipment buy(final Rate rate) throws EasyPostException {
931+
Map<String, Object> params = new HashMap<>();
932+
params.put("rate", rate);
933+
934+
return this.buy(params, false, null);
931935
}
932936

933937
/**
934938
* Buy this Shipment.
935939
*
936-
* @param params the options for the query.
940+
* @param rate the Rate to use for this Shipment.
941+
* @param withCarbonOffset whether to include a carbon offset when buying the shipment.
937942
* @return Shipment object
938943
* @throws EasyPostException when the request fails.
939944
*/
940-
public Shipment buy(final Map<String, Object> params) throws EasyPostException {
941-
return this.buy(params, false, null);
945+
public Shipment buy(final Rate rate, final boolean withCarbonOffset) throws EasyPostException {
946+
Map<String, Object> params = new HashMap<>();
947+
params.put("rate", rate);
948+
949+
return this.buy(params, withCarbonOffset, null, null);
942950
}
943951

944952
/**
945953
* Buy this Shipment.
946954
*
947-
* @param params the options for the query.
948-
* @param withCarbonOffset whether to include a carbon offset when buying the shipment.
955+
* @param rate the Rate to use for this Shipment.
956+
* @param endShipperId the id of the end shipper to use for this purchase.
949957
* @return Shipment object
950958
* @throws EasyPostException when the request fails.
951959
*/
952-
public Shipment buy(final Map<String, Object> params, final boolean withCarbonOffset) throws EasyPostException {
953-
return this.buy(params, withCarbonOffset, null);
960+
public Shipment buy(final Rate rate, final String endShipperId) throws EasyPostException {
961+
Map<String, Object> params = new HashMap<>();
962+
params.put("rate", rate);
963+
964+
return this.buy(params, false, endShipperId, null);
954965
}
955966

956967
/**
957968
* Buy this Shipment.
958969
*
970+
* @param params the options for the query.
959971
* @param apiKey API key to use in request (overrides default API key).
960972
* @return Shipment object
961973
* @throws EasyPostException when the request fails.
962974
*/
963-
public Shipment buy(final String apiKey) throws EasyPostException {
964-
return this.buy(new HashMap<String, Object>() {}, false, apiKey);
975+
public Shipment buy(final Map<String, Object> params, final String apiKey) throws EasyPostException {
976+
// TODO: When Java Client Library rewrite happens, the apiKey param will be replaced with endShipperId
977+
return this.buy(params, false, null, apiKey);
965978
}
966979

967980
/**
968981
* Buy this Shipment.
969982
*
983+
* @param params the options for the query.
970984
* @param withCarbonOffset whether to include a carbon offset when buying the shipment.
971-
* @param apiKey API key to use in request (overrides default API key).
972985
* @return Shipment object
973986
* @throws EasyPostException when the request fails.
974987
*/
975-
public Shipment buy(final boolean withCarbonOffset, final String apiKey) throws EasyPostException {
976-
return this.buy(new HashMap<String, Object>() {}, withCarbonOffset, apiKey);
988+
public Shipment buy(final Map<String, Object> params, final boolean withCarbonOffset) throws EasyPostException {
989+
return this.buy(params, withCarbonOffset, null);
977990
}
978991

979992
/**
980993
* Buy this Shipment.
981994
*
982995
* @param rate the Rate to use for this Shipment.
996+
* @param withCarbonOffset whether to include a carbon offset when buying the shipment.
997+
* @param endShipperId the id of the end shipper to use for this purchase.
998+
* @param apiKey API key to use in request (overrides default API key).
983999
* @return Shipment object
9841000
* @throws EasyPostException when the request fails.
9851001
*/
986-
public Shipment buy(final Rate rate) throws EasyPostException {
987-
Map<String, Object> params = new HashMap<>();
988-
params.put("rate", rate);
1002+
public Shipment buy(final Rate rate, final boolean withCarbonOffset, final String endShipperId, final String apiKey)
1003+
throws EasyPostException {
1004+
Map<String, Object> params = new HashMap<>();
1005+
params.put("rate", rate);
9891006

990-
return this.buy(params, false, null);
1007+
return this.buy(params, withCarbonOffset, endShipperId, apiKey);
9911008
}
9921009

9931010
/**
9941011
* Buy this Shipment.
9951012
*
996-
* @param rate the Rate to use for this Shipment.
1013+
* @param params the options for the query.
9971014
* @param withCarbonOffset whether to include a carbon offset when buying the shipment.
1015+
* @param apiKey API key to use in request (overrides default API key).
9981016
* @return Shipment object
9991017
* @throws EasyPostException when the request fails.
10001018
*/
1001-
public Shipment buy(final Rate rate, final boolean withCarbonOffset) throws EasyPostException {
1002-
Map<String, Object> params = new HashMap<>();
1003-
params.put("rate", rate);
1004-
1005-
return this.buy(params, withCarbonOffset, null);
1019+
public Shipment buy(final Map<String, Object> params, final boolean withCarbonOffset, final String apiKey)
1020+
throws EasyPostException {
1021+
return this.buy(params, withCarbonOffset, null, apiKey);
10061022
}
10071023

10081024
/**
10091025
* Buy this Shipment.
10101026
*
1011-
* @param params the options for the query.
1012-
* @param apiKey API key to use in request (overrides default API key).
1027+
* @param params the options for the query.
1028+
* @param endShipperId the id of the end shipper to use for this purchase.
1029+
* @param apiKey API key to use in request (overrides default API key).
10131030
* @return Shipment object
10141031
* @throws EasyPostException when the request fails.
10151032
*/
1016-
public Shipment buy(final Map<String, Object> params, final String apiKey) throws EasyPostException {
1017-
return this.buy(params, false, apiKey);
1033+
public Shipment buy(final Map<String, Object> params, final String endShipperId, final String apiKey)
1034+
throws EasyPostException {
1035+
return this.buy(params, false, endShipperId, apiKey);
10181036
}
10191037

10201038
/**
10211039
* Buy this Shipment.
10221040
*
10231041
* @param params the options for the query.
10241042
* @param withCarbonOffset whether to include a carbon offset when buying the shipment.
1043+
* @param endShipperId the id of the end shipper to use for this purchase.
10251044
* @param apiKey API key to use in request (overrides default API key).
10261045
* @return Shipment object
10271046
* @throws EasyPostException when the request fails.
10281047
*/
1029-
public Shipment buy(final Map<String, Object> params, final boolean withCarbonOffset, final String apiKey)
1030-
throws EasyPostException {
1048+
public Shipment buy(final Map<String, Object> params, final boolean withCarbonOffset,
1049+
final String endShipperId, final String apiKey) throws EasyPostException {
10311050
params.put("carbon_offset", withCarbonOffset);
1051+
1052+
if (endShipperId != null && !endShipperId.isEmpty()) {
1053+
params.put("end_shipper_id", endShipperId);
1054+
}
1055+
10321056
Shipment response =
10331057
request(RequestMethod.POST, String.format("%s/buy", instanceURL(Shipment.class, this.getId())), params,
10341058
Shipment.class, apiKey);

0 commit comments

Comments
 (0)