Skip to content

Commit

Permalink
Merge pull request #266 from EasyPost/retrieve_estimated_delivery_date
Browse files Browse the repository at this point in the history
feat: adds retrieve_estimated_delivery_date function
  • Loading branch information
Justintime50 authored Apr 26, 2023
2 parents ca9aa2b + 00135ed commit 0f3a2ef
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 0 deletions.
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

- Adds `retrieve_estimated_delivery_date` function to the Shipment class

## v7.12.0 (2023-04-18)

- Adds beta `retrieve_carrier_metadata` function
Expand Down
10 changes: 10 additions & 0 deletions easypost/shipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,13 @@ def get_lowest_smartrate(smartrates, delivery_days: int, delivery_accuracy: str)
raise Error(message="No rates found.")

return lowest_smartrate

def retrieve_estimated_delivery_date(self, planned_ship_date: str) -> List[Dict[str, Any]]:
"""Retrieves the estimated delivery date of each Rate via SmartRate."""
requestor = Requestor(local_api_key=self._api_key)
url = "%s/%s" % (self.instance_url(), "smartrate/delivery_date")
params = {
"planned_ship_date": planned_ship_date,
}
response, api_key = requestor.request(method=RequestMethod.GET, url=url, params=params)
return convert_to_easypost_object(response=response.get("rates", []), api_key=api_key)
244 changes: 244 additions & 0 deletions tests/cassettes/test_retrieve_estimated_delivery_date.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions tests/test_shipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,13 @@ def test_shipment_buy_with_end_shipper_id(ca_address_1, basic_shipment):
shipment.buy(rate=shipment.lowest_rate(), end_shipper_id=end_shipper["id"])

assert shipment.postage_label is not None


@pytest.mark.vcr()
def test_retrieve_estimated_delivery_date(basic_shipment):
"""Tests that we retrieve time-in-transit data for each of the Rates of a Shipment."""
shipment = easypost.Shipment.create(**basic_shipment)

rates = shipment.retrieve_estimated_delivery_date(planned_ship_date="2023-04-28")

assert all(entry.get("easypost_time_in_transit_data") for entry in rates)

0 comments on commit 0f3a2ef

Please sign in to comment.