Skip to content

Commit 8ffc97e

Browse files
authored
Merge pull request #271 from EasyPost/carrier_metadata_ga
feat: carrier metadata GA
2 parents 0e06716 + 1473603 commit 8ffc97e

File tree

8 files changed

+322
-2
lines changed

8 files changed

+322
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Next Release
44

5+
- Retrieving carrier metadata is now generally available via `client.carrierMetadata.retrieve`
56
- Bump all dependencies
67

78
## v6.6.1 (2023-05-09)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class BetaCarrierMetadataService {
2525
*
2626
* @return CarrierMetadata object
2727
* @throws EasyPostException
28+
* @deprecated Use carrierMetadata.retrieve instead
2829
*/
2930
public CarrierMetadata retrieveCarrierMetadata() throws EasyPostException {
3031
return retrieveCarrierMetadata(null);
@@ -36,6 +37,7 @@ public CarrierMetadata retrieveCarrierMetadata() throws EasyPostException {
3637
* @param carriers The list of carriers in string.
3738
* @return CarrierMetadata object
3839
* @throws EasyPostException
40+
* @deprecated Use carrierMetadata.retrieve instead
3941
*/
4042
public CarrierMetadata retrieveCarrierMetadata(List<String> carriers) throws EasyPostException {
4143
return retrieveCarrierMetadata(carriers, null);
@@ -48,6 +50,7 @@ public CarrierMetadata retrieveCarrierMetadata(List<String> carriers) throws Eas
4850
* @param types The list of types in string.
4951
* @return CarrierMetadata object
5052
* @throws EasyPostException
53+
* @deprecated Use carrierMetadata.retrieve instead
5154
*/
5255
public CarrierMetadata retrieveCarrierMetadata(List<String> carriers, List<String> types) throws EasyPostException {
5356
HashMap<String, Object> params = new HashMap<>();
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.easypost.service;
2+
3+
import java.util.HashMap;
4+
import java.util.List;
5+
6+
import com.easypost.exception.EasyPostException;
7+
import com.easypost.http.Requestor;
8+
import com.easypost.http.Requestor.RequestMethod;
9+
import com.easypost.model.CarrierMetadata;
10+
11+
public class CarrierMetadataService {
12+
private final EasyPostClient client;
13+
14+
/**
15+
* CarrierMetadataService constructor.
16+
*
17+
* @param client The client object.
18+
*/
19+
CarrierMetadataService(EasyPostClient client) {
20+
this.client = client;
21+
}
22+
23+
/**
24+
* Retrieves all carrier metadata.
25+
*
26+
* @return CarrierMetadata object
27+
* @throws EasyPostException
28+
*/
29+
public CarrierMetadata retrieve() throws EasyPostException {
30+
return retrieve(null);
31+
}
32+
33+
/**
34+
* Retrieves carrier metadata for given carriers.
35+
*
36+
* @param carriers The list of carriers in string.
37+
* @return CarrierMetadata object
38+
* @throws EasyPostException
39+
*/
40+
public CarrierMetadata retrieve(List<String> carriers) throws EasyPostException {
41+
return retrieve(carriers, null);
42+
}
43+
44+
/**
45+
* Retrieves carrier metadata for given carriers and types.
46+
*
47+
* @param carriers The list of carriers in string.
48+
* @param types The list of types in string.
49+
* @return CarrierMetadata object
50+
* @throws EasyPostException
51+
*/
52+
public CarrierMetadata retrieve(List<String> carriers, List<String> types) throws EasyPostException {
53+
HashMap<String, Object> params = new HashMap<>();
54+
55+
if (carriers != null && !carriers.isEmpty()) {
56+
params.put("carriers", String.join(",", carriers));
57+
}
58+
59+
if (types != null && !types.isEmpty()) {
60+
params.put("types", String.join(",", types));
61+
}
62+
63+
return Requestor.request(RequestMethod.GET, "metadata/carriers", params,
64+
CarrierMetadata.class, client);
65+
}
66+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class EasyPostClient {
1717
public final BetaRateService betaRate;
1818
public final BillingService billing;
1919
public final CarrierAccountService carrierAccount;
20+
public final CarrierMetadataService carrierMetadata;
2021
public final CarrierTypeService carrierType;
2122
public final CustomsInfoService customsInfo;
2223
public final CustomsItemService customsItem;
@@ -122,6 +123,7 @@ public EasyPostClient(String apiKey, int connectTimeoutMilliseconds, int readTim
122123
this.betaRate = new BetaRateService(this);
123124
this.billing = new BillingService(this);
124125
this.carrierAccount = new CarrierAccountService(this);
126+
this.carrierMetadata = new CarrierMetadataService(this);
125127
this.carrierType = new CarrierTypeService(this);
126128
this.customsInfo = new CustomsInfoService(this);
127129
this.customsItem = new CustomsItemService(this);

src/test/cassettes/carrier_metadata/retrieve_carrier_metadata.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.

src/test/cassettes/carrier_metadata/retrieve_carrier_metadata_with_filter.json

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

src/test/java/com/easypost/BetaCarrierMetadataTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static void setup() throws EasyPostException {
3232
* @throws EasyPostException when the request fails.
3333
*/
3434
@Test
35-
public void testRetrieveStatelessRates() throws EasyPostException {
35+
public void testRetrieveBetaCarrierMetadata() throws EasyPostException {
3636
vcr.setUpTest("retrieve_carrier_metadata");
3737

3838
CarrierMetadata carrierMetadata = vcr.client.betaCarrierMetadata.retrieveCarrierMetadata();
@@ -47,7 +47,7 @@ public void testRetrieveStatelessRates() throws EasyPostException {
4747
* @throws EasyPostException when the request fails.
4848
*/
4949
@Test
50-
public void testRetrieveStatelessRatesWithFilter() throws EasyPostException {
50+
public void testRetrieveBetaCarrierMetadataWithFilter() throws EasyPostException {
5151
vcr.setUpTest("retrieve_carrier_metadata_with_filter");
5252
List<String> carriers = Arrays.asList("usps");
5353
List<String> types = Arrays.asList("service_levels", "predefined_packages");
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.easypost;
2+
3+
import com.easypost.exception.EasyPostException;
4+
import com.easypost.model.CarrierMetadata;
5+
import org.junit.jupiter.api.BeforeAll;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.util.Arrays;
9+
import java.util.List;
10+
11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
import static org.junit.jupiter.api.Assertions.assertNotNull;
13+
import static org.junit.jupiter.api.Assertions.assertNull;
14+
import static org.junit.jupiter.api.Assertions.assertTrue;
15+
16+
public class CarrierMetadataTest {
17+
private static TestUtils.VCR vcr;
18+
19+
/**
20+
* Set up the testing environment for this file.
21+
*
22+
* @throws EasyPostException when the request fails.
23+
*/
24+
@BeforeAll
25+
public static void setup() throws EasyPostException {
26+
vcr = new TestUtils.VCR("carrier_metadata", TestUtils.ApiKey.TEST);
27+
}
28+
29+
/**
30+
* Test retrieving all carrier metadata.
31+
*
32+
* @throws EasyPostException when the request fails.
33+
*/
34+
@Test
35+
public void testRetrieveCarrierMetadata() throws EasyPostException {
36+
vcr.setUpTest("retrieve_carrier_metadata");
37+
38+
CarrierMetadata carrierMetadata = vcr.client.carrierMetadata.retrieve();
39+
40+
assertTrue(carrierMetadata.getCarriers().stream().anyMatch(carrier -> carrier.getName().equals("usps")));
41+
assertTrue(carrierMetadata.getCarriers().stream().anyMatch(carrier -> carrier.getName().equals("fedex")));
42+
}
43+
44+
/**
45+
* Test retrieving carrier metadata for a specific carrier.
46+
*
47+
* @throws EasyPostException when the request fails.
48+
*/
49+
@Test
50+
public void testRetrieveCarrierMetadataWithFilter() throws EasyPostException {
51+
vcr.setUpTest("retrieve_carrier_metadata_with_filter");
52+
List<String> carriers = Arrays.asList("usps");
53+
List<String> types = Arrays.asList("service_levels", "predefined_packages");
54+
CarrierMetadata carrierMetadata = vcr.client.carrierMetadata.retrieve(carriers, types);
55+
56+
assertTrue(carrierMetadata.getCarriers().stream()
57+
.allMatch(carrier -> carrier.getName().equals("usps")));
58+
assertEquals(1, carrierMetadata.getCarriers().size());
59+
assertNotNull(carrierMetadata.getCarriers().get(0).getServiceLevels());
60+
assertNotNull(carrierMetadata.getCarriers().get(0).getPredefinedPackages());
61+
assertNull(carrierMetadata.getCarriers().get(0).getSupportedFeatures());
62+
}
63+
}

0 commit comments

Comments
 (0)