Skip to content

Commit

Permalink
Adds new recommend_ship_date and estimate_delivery_date functions (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchen293 committed Jul 12, 2024
1 parent deffee3 commit 4caf5c7
Show file tree
Hide file tree
Showing 13 changed files with 554 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next Release

- Adds new `shipment.recommend_ship_date`, `smartrate.recommend_ship_date`, and `smartrate.estimate_delivery_date` functions
- Routes `UpsAccount`, `UpsMailInnovationsAccount`, and `UpsSurepostAccount` create/update requests to the new `/ups_oauth_registrations` endpoint
- 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

Expand Down
1 change: 1 addition & 0 deletions lib/easypost/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def initialize(api_key:, read_timeout: 60, open_timeout: 30, api_base: 'https://
EasyPost::Services::Report,
EasyPost::Services::ScanForm,
EasyPost::Services::Shipment,
EasyPost::Services::SmartRate,
EasyPost::Services::Tracker,
EasyPost::Services::User,
EasyPost::Services::Webhook,
Expand Down
1 change: 1 addition & 0 deletions lib/easypost/services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module EasyPost::Services
require_relative 'services/report'
require_relative 'services/scan_form'
require_relative 'services/shipment'
require_relative 'services/smart_rate'
require_relative 'services/tracker'
require_relative 'services/user'
require_relative 'services/webhook'
9 changes: 9 additions & 0 deletions lib/easypost/services/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,13 @@ def retrieve_estimated_delivery_date(id, planned_ship_date)

EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS).rates
end

# Retrieve a recommended ship date for an existing Shipment via the Precision Shipping API, based on a specific desired delivery date.
def recommend_ship_date(id, desired_delivery_date)
url = "shipments/#{id}/smartrate/precision_shipping"
params = { desired_delivery_date: desired_delivery_date }
response = @client.make_request(:get, url, params)

EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS).rates
end
end
19 changes: 19 additions & 0 deletions lib/easypost/services/smart_rate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class EasyPost::Services::SmartRate < EasyPost::Services::Service
# Retrieve the estimated delivery date of each carrier-service level combination via the
# Smart Deliver By API, based on a specific ship date and origin-destination postal code pair.
def estimate_delivery_date(params = {})
url = 'smartrate/deliver_by'

response = @client.make_request(:post, url, params)
EasyPost::InternalUtilities::Json.convert_json_to_object(response, EasyPost::Models::EasyPostObject)
end

# Retrieve a recommended ship date for each carrier-service level combination via the
# Smart Deliver On API, based on a specific delivery date and origin-destination postal code pair.
def recommend_ship_date(params = {})
url = 'smartrate/deliver_on'

response = @client.make_request(:post, url, params)
EasyPost::InternalUtilities::Json.convert_json_to_object(response, EasyPost::Models::EasyPostObject)
end
end

Large diffs are not rendered by default.

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

Loading

0 comments on commit 4caf5c7

Please sign in to comment.