Skip to content

Commit 21ec55e

Browse files
authored
Merge pull request #265 from EasyPost/carrier_metadata
feat: add carrier metadata beta endpoint
2 parents 5a0d969 + 27f0275 commit 21ec55e

File tree

5 files changed

+1972
-0
lines changed

5 files changed

+1972
-0
lines changed

easypost/beta/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# flake8: noqa
2+
from easypost.beta.carrier_metadata import CarrierMetadata
23
from easypost.beta.rate import Rate
34
from easypost.beta.referral import Referral

easypost/beta/carrier_metadata.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import (
2+
Any,
3+
Dict,
4+
List,
5+
Optional,
6+
)
7+
8+
from easypost.easypost_object import convert_to_easypost_object
9+
from easypost.requestor import (
10+
RequestMethod,
11+
Requestor,
12+
)
13+
14+
15+
class CarrierMetadata:
16+
@classmethod
17+
def retrieve_carrier_metadata(
18+
cls, api_key: Optional[str] = None, carriers: Optional[List[str]] = None, types: Optional[List[str]] = None
19+
) -> List[Dict[str, Any]]:
20+
"""Get carrier metadata for all carriers on the EasyPost platform."""
21+
requestor = Requestor(local_api_key=api_key)
22+
params = {
23+
"carriers": ",".join(carriers) if carriers else None,
24+
"types": ",".join(types) if types else None,
25+
}
26+
response, api_key = requestor.request(method=RequestMethod.GET, url="/metadata", params=params, beta=True)
27+
return convert_to_easypost_object(response=response.get("carriers", []), api_key=api_key)

0 commit comments

Comments
 (0)