Skip to content

Commit 4caf5c7

Browse files
authored
Adds new recommend_ship_date and estimate_delivery_date functions (#306)
1 parent deffee3 commit 4caf5c7

13 files changed

+554
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Next Release
44

5+
- Adds new `shipment.recommend_ship_date`, `smartrate.recommend_ship_date`, and `smartrate.estimate_delivery_date` functions
56
- Routes `UpsAccount`, `UpsMailInnovationsAccount`, and `UpsSurepostAccount` create/update requests to the new `/ups_oauth_registrations` endpoint
67
- Starting `2024-08-05`, UPS accounts will require a new payload to register or update. See [UPS OAuth 2.0 Update](https://support.easypost.com/hc/en-us/articles/26635027512717-UPS-OAuth-2-0-Update?utm_medium=email&_hsenc=p2ANqtz-96MmFtWICOzy9sKRbbcZSiMovZSrY3MSX1_bgY9N3f9yLVfWQdLhjAGq-SmNcOnDIS6GYhZ0OApjDBrGkKyLLMx1z6_TFOVp6-wllhEFQINrkuRuc&_hsmi=313130292&utm_content=313130292&utm_source=hs_email) for more details
78

lib/easypost/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def initialize(api_key:, read_timeout: 60, open_timeout: 30, api_base: 'https://
5656
EasyPost::Services::Report,
5757
EasyPost::Services::ScanForm,
5858
EasyPost::Services::Shipment,
59+
EasyPost::Services::SmartRate,
5960
EasyPost::Services::Tracker,
6061
EasyPost::Services::User,
6162
EasyPost::Services::Webhook,

lib/easypost/services.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module EasyPost::Services
2828
require_relative 'services/report'
2929
require_relative 'services/scan_form'
3030
require_relative 'services/shipment'
31+
require_relative 'services/smart_rate'
3132
require_relative 'services/tracker'
3233
require_relative 'services/user'
3334
require_relative 'services/webhook'

lib/easypost/services/shipment.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,13 @@ def retrieve_estimated_delivery_date(id, planned_ship_date)
118118

119119
EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS).rates
120120
end
121+
122+
# Retrieve a recommended ship date for an existing Shipment via the Precision Shipping API, based on a specific desired delivery date.
123+
def recommend_ship_date(id, desired_delivery_date)
124+
url = "shipments/#{id}/smartrate/precision_shipping"
125+
params = { desired_delivery_date: desired_delivery_date }
126+
response = @client.make_request(:get, url, params)
127+
128+
EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS).rates
129+
end
121130
end

lib/easypost/services/smart_rate.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class EasyPost::Services::SmartRate < EasyPost::Services::Service
2+
# Retrieve the estimated delivery date of each carrier-service level combination via the
3+
# Smart Deliver By API, based on a specific ship date and origin-destination postal code pair.
4+
def estimate_delivery_date(params = {})
5+
url = 'smartrate/deliver_by'
6+
7+
response = @client.make_request(:post, url, params)
8+
EasyPost::InternalUtilities::Json.convert_json_to_object(response, EasyPost::Models::EasyPostObject)
9+
end
10+
11+
# Retrieve a recommended ship date for each carrier-service level combination via the
12+
# Smart Deliver On API, based on a specific delivery date and origin-destination postal code pair.
13+
def recommend_ship_date(params = {})
14+
url = 'smartrate/deliver_on'
15+
16+
response = @client.make_request(:post, url, params)
17+
EasyPost::InternalUtilities::Json.convert_json_to_object(response, EasyPost::Models::EasyPostObject)
18+
end
19+
end

spec/cassettes/shipment/EasyPost_Services_Shipment_retrieve_estimated_delivery_date_retrieve_time-in-transit_data_for_each_of_the_Rates_of_a_shipment.yml

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

spec/cassettes/shipment/EasyPost_Services_Shipment_retrieve_recommend_ship_date_retrieve_recommend_ship_date_of_a_shipment.yml

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