Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds new recommend_ship_date and estimate_delivery_date functions #306

Merged
merged 7 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module EasyPost::Models
require_relative 'models/report'
require_relative 'models/scan_form'
require_relative 'models/shipment'
require_relative 'models/smart_rate'
require_relative 'models/tax_identifier'
require_relative 'models/tracker'
require_relative 'models/user'
Expand Down
5 changes: 5 additions & 0 deletions lib/easypost/models/smart_rate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

# The SmartRate object contains details about the SmartRate requests.
class EasyPost::Models::SmartRate < EasyPost::Models::EasyPostObject
jchen293 marked this conversation as resolved.
Show resolved Hide resolved
end
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
21 changes: 21 additions & 0 deletions lib/easypost/services/smart_rate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class EasyPost::Services::SmartRate < EasyPost::Services::Service
MODEL_CLASS = EasyPost::Models::SmartRate

# 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, MODEL_CLASS)
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, MODEL_CLASS)
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
Loading