Skip to content

Commit

Permalink
Adds generate_form function to the Shipment object (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchen293 authored Jul 12, 2022
1 parent ef356bb commit 4bc74f0
Show file tree
Hide file tree
Showing 5 changed files with 400 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## Next Release

- Add `generate_form()` in Shipment class

## v7.2.0 (2022-07-11)

- Adds `Billing.retrieve_payment_methods()`, `Billing.fund_wallet()`, and `Billing.delete_payment_method()` functions
Expand Down
19 changes: 18 additions & 1 deletion easypost/shipment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from typing import List
from typing import (
Any,
Dict,
List,
Optional,
)

from easypost import Rate
from easypost.error import Error
Expand Down Expand Up @@ -74,6 +79,18 @@ def lowest_smartrate(self, delivery_days: int, delivery_accuracy: str) -> Rate:

return lowest_smartrate

def generate_form(self, form_type: str, form_options: Optional[Dict[str, Any]] = {}) -> "Shipment":
"""Generate a form for a Shipment."""
params = {"type": form_type}
params.update(form_options) # type: ignore
wrapped_params = {"form": params}

requestor = Requestor(local_api_key=self._api_key)
url = "%s/%s" % (self.instance_url(), "forms")
response, api_key = requestor.request(method=RequestMethod.POST, url=url, params=wrapped_params)
self.refresh_from(values=response, api_key=api_key)
return self

@staticmethod
def get_lowest_smartrate(smartrates, delivery_days: int, delivery_accuracy: str) -> Rate:
"""Get the lowest smartrate from a list of smartrates."""
Expand Down
Loading

0 comments on commit 4bc74f0

Please sign in to comment.