Skip to content

Commit cec89df

Browse files
committed
feat: adds luma functions
1 parent 5b04689 commit cec89df

File tree

16 files changed

+600
-3
lines changed

16 files changed

+600
-3
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+
- Adds the following functions
4+
- `shipment.createAndBuyLuma`
5+
- `shipment.buyLuma`
6+
- `luma.getPromise`
7+
38
## v8.1.0 (2025-05-29)
49

510
- Adds `reference` to Claims

examples

Submodule examples updated 1556 files
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.easypost.model;
2+
3+
import lombok.Getter;
4+
5+
@Getter
6+
public final class AiResults {
7+
private String carrier;
8+
private Boolean meetsRulesetRequirements;
9+
private String predictedDeliverByDate;
10+
private Integer predictedDeliverDays;
11+
private String rateId;
12+
private String rateUsd;
13+
private String service;
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.easypost.model;
2+
3+
import java.util.List;
4+
import lombok.Getter;
5+
6+
@Getter
7+
public final class LumaInfo {
8+
private List<AiResults> aiResults;
9+
private Integer matchingRuleIdx;
10+
private String rulesetDescription;
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.easypost.model;
2+
3+
import java.util.List;
4+
import lombok.Getter;
5+
6+
@Getter
7+
public class LumaPromiseResponse {
8+
private LumaInfo lumaInfo;
9+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class EasyPostClient {
3232
public final EndShipperService endShipper;
3333
public final EventService event;
3434
public final InsuranceService insurance;
35+
public final LumaService luma;
3536
public final OrderService order;
3637
public final ParcelService parcel;
3738
public final PaymentMethodService paymentMethod;
@@ -143,6 +144,7 @@ public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, int readTim
143144
this.endShipper = new EndShipperService(this);
144145
this.event = new EventService(this);
145146
this.insurance = new InsuranceService(this);
147+
this.luma = new LumaService(this);
146148
this.order = new OrderService(this);
147149
this.parcel = new ParcelService(this);
148150
this.paymentMethod = new PaymentMethodService(this);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.easypost.service;
2+
3+
import com.easypost.exception.EasyPostException;
4+
import com.easypost.http.Requestor;
5+
import com.easypost.http.Requestor.RequestMethod;
6+
import com.easypost.model.LumaPromiseResponse;
7+
import com.easypost.model.LumaInfo;
8+
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
public class LumaService {
13+
private final EasyPostClient client;
14+
15+
/**
16+
* LumaService constructor.
17+
*
18+
* @param client The client object.
19+
*/
20+
LumaService(EasyPostClient client) {
21+
this.client = client;
22+
}
23+
24+
/**
25+
* Get service recommendations from Luma that meet the criteria of your ruleset.
26+
*
27+
* @param params The map of parameters.
28+
* @return LumaInfo object.
29+
* @throws EasyPostException When the request fails.
30+
*/
31+
public LumaInfo getPromise(final Map<String, Object> params)
32+
throws EasyPostException {
33+
Map<String, Object> wrappedParams = new HashMap<>();
34+
wrappedParams.put("shipment", params);
35+
String endpoint = "luma/promise";
36+
37+
LumaPromiseResponse response = Requestor.request(RequestMethod.POST, endpoint, wrappedParams,
38+
LumaPromiseResponse.class, client);
39+
return response.getLumaInfo();
40+
}
41+
}

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ public Shipment generateForm(final String id, final String formType, final Map<S
375375
*
376376
* @param id The id of the shipment.
377377
* @param plannedShipDate The planned shipment date.
378-
* @return EstimatedDeliveryDate object.
378+
* @return List of EstimatedDeliveryDate objects.
379379
* @throws EasyPostException When the request fails.
380380
*/
381381
public List<EstimatedDeliveryDate> retrieveEstimatedDeliveryDate(final String id, final String plannedShipDate)
@@ -396,7 +396,7 @@ public List<EstimatedDeliveryDate> retrieveEstimatedDeliveryDate(final String id
396396
*
397397
* @param id The id of the shipment.
398398
* @param desiredDeliveryDate The desired delivery date.
399-
* @return EstimatedDeliveryDate object.
399+
* @return List of RecommendShipDateForShipmentResult objects.
400400
* @throws EasyPostException When the request fails.
401401
*/
402402
public List<RecommendShipDateForShipmentResult> recommendShipDate(final String id, final String desiredDeliveryDate)
@@ -409,4 +409,39 @@ public List<RecommendShipDateForShipmentResult> recommendShipDate(final String i
409409
RecommendShipDateResponse.class, client);
410410
return response.getRates();
411411
}
412+
413+
/**
414+
* Create and buy a Luma Shipment in one call.
415+
*
416+
* @param params The map of parameters.
417+
* @return Shipment object.
418+
* @throws EasyPostException When the request fails.
419+
*/
420+
public Shipment createAndBuyLuma(final Map<String, Object> params)
421+
throws EasyPostException {
422+
Map<String, Object> wrappedParams = new HashMap<>();
423+
wrappedParams.put("shipment", params);
424+
String endpoint = "shipments/luma";
425+
426+
Shipment response = Requestor.request(RequestMethod.POST, endpoint, wrappedParams,
427+
Shipment.class, client);
428+
return response;
429+
}
430+
431+
/**
432+
* Buy a Shipment with Luma.
433+
*
434+
* @param id The ID of shipment.
435+
* @param params The map of parameters.
436+
* @return Shipment object.
437+
* @throws EasyPostException When the request fails.
438+
*/
439+
public Shipment buyLuma(final String id, final Map<String, Object> params)
440+
throws EasyPostException {
441+
String endpoint = "shipments/" + id + "/luma";
442+
443+
Shipment response = Requestor.request(RequestMethod.POST, endpoint, params,
444+
Shipment.class, client);
445+
return response;
446+
}
412447
}

src/test/cassettes/shipment/buy_luma.json

Lines changed: 183 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/test/cassettes/shipment/create_and_buy_luma.json

Lines changed: 91 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)