Skip to content

Commit 67b8bb6

Browse files
authored
Add EndShipper (#224)
1 parent 354a067 commit 67b8bb6

9 files changed

+556
-0
lines changed

CHANGELOG.md

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

3+
## Next Release
4+
5+
- Adds the `EndShipper` Beta class with `create`, `retrieve`, `all`, and `save` functions
6+
37
## v7.4.0 (2022-08-02)
48

59
- Adds Carbon Offset support

easypost/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from easypost.carrier_account import CarrierAccount
77
from easypost.customs_info import CustomsInfo
88
from easypost.customs_item import CustomsItem
9+
from easypost.endshipper import EndShipper
910
from easypost.error import Error
1011
from easypost.event import Event
1112
from easypost.insurance import Insurance

easypost/easypost_object.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"cfrep": "Report",
1818
"cstinfo": "CustomsInfo",
1919
"cstitem": "CustomsItem",
20+
"es": "EndShipper",
2021
"evt": "Event",
2122
"hook": "Webhook",
2223
"ins": "Insurance",

easypost/endshipper.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import Optional
2+
3+
from easypost.easypost_object import (
4+
EasyPostObject,
5+
convert_to_easypost_object,
6+
)
7+
from easypost.requestor import (
8+
RequestMethod,
9+
Requestor,
10+
)
11+
from easypost.resource import AllResource
12+
13+
14+
class EndShipper(AllResource):
15+
@classmethod
16+
def create(cls, api_key: Optional[str] = None, **params) -> "EndShipper":
17+
"""Create an EndShipper."""
18+
requestor = Requestor(local_api_key=api_key)
19+
url = cls.class_url()
20+
wrapped_params = {"address": params}
21+
response, api_key = requestor.request(method=RequestMethod.POST, url=url, params=wrapped_params)
22+
return convert_to_easypost_object(response=response, api_key=api_key)
23+
24+
def save(self) -> "EndShipper":
25+
"""Update an EndShipper object."""
26+
if self._unsaved_values:
27+
requestor = Requestor(local_api_key=self._api_key)
28+
params = {}
29+
for k in self._unsaved_values:
30+
params[k] = getattr(self, k)
31+
if type(params[k]) is EasyPostObject:
32+
params[k] = params[k].flatten_unsaved()
33+
wrapped_params = {"address": params} # This function is overridden due to the key has to be `address`
34+
url = self.instance_url()
35+
response, api_key = requestor.request(method=RequestMethod.PUT, url=url, params=wrapped_params)
36+
self.refresh_from(values=response, api_key=api_key)
37+
38+
return self

tests/cassettes/test_endshipper_all.yaml

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

tests/cassettes/test_endshipper_create.yaml

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

tests/cassettes/test_endshipper_retrieve.yaml

Lines changed: 146 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)