Skip to content

Commit

Permalink
Merge pull request #253 from EasyPost/payloads
Browse files Browse the repository at this point in the history
feat: adds retrieve event payload and payloads functions
  • Loading branch information
Justintime50 authored Jan 17, 2023
2 parents 152c000 + dc9be65 commit 992598f
Show file tree
Hide file tree
Showing 9 changed files with 792 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Next Release

- Adds `all` function to `Pickup` to retrieve all pickups
- Adds `retrieve_payload` and `retrieve_all_payloads` functions to `Event`

## v7.8.0 (2023-01-11)

Expand Down
1 change: 1 addition & 0 deletions easypost/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from easypost.insurance import Insurance
from easypost.order import Order
from easypost.parcel import Parcel
from easypost.payload import Payload
from easypost.pickup import Pickup
from easypost.pickup_rate import PickupRate
from easypost.postage_label import PostageLabel
Expand Down
3 changes: 2 additions & 1 deletion easypost/easypost_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@


EASYPOST_OBJECT_ID_PREFIX_TO_CLASS_NAME_MAP = {
"ak": "ApiKey",
"adr": "Address",
"ak": "ApiKey",
"batch": "Batch",
"brd": "Brand",
"ca": "CarrierAccount",
Expand All @@ -23,6 +23,7 @@
"hook": "Webhook",
"ins": "Insurance",
"order": "Order",
"payload": "Payload",
"pickup": "Pickup",
"pickuprate": "PickupRate",
"pl": "PostageLabel",
Expand Down
26 changes: 26 additions & 0 deletions easypost/event.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
import json
from typing import (
List,
Optional,
)

import easypost
from easypost.easypost_object import convert_to_easypost_object
from easypost.requestor import (
RequestMethod,
Requestor,
)
from easypost.resource import AllResource


class Event(AllResource):
@classmethod
def receive(cls, values: str) -> "Event":
return convert_to_easypost_object(response=json.loads(s=values), api_key=easypost.api_key)

@classmethod
def retrieve_all_payloads(cls, event_id: str, api_key: Optional[str] = None, **params) -> List["easypost.Payload"]:
"""Retrieve a list of Payloads for an Event."""
requestor = Requestor(local_api_key=api_key)
url = f"{cls.class_url()}/{event_id}/payloads"
response, api_key = requestor.request(method=RequestMethod.GET, url=url, params=params)
return convert_to_easypost_object(response=response, api_key=api_key)

@classmethod
def retrieve_payload(
cls, event_id: str, payload_id: str, api_key: Optional[str] = None, **params
) -> "easypost.Payload":
"""Retrieve a Payload of an Event."""
requestor = Requestor(local_api_key=api_key)
url = f"{cls.class_url()}/{event_id}/payloads/{payload_id}"
response, api_key = requestor.request(method=RequestMethod.GET, url=url, params=params)
return convert_to_easypost_object(response=response, api_key=api_key)
2 changes: 2 additions & 0 deletions easypost/payload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Payload:
pass
Loading

0 comments on commit 992598f

Please sign in to comment.