From 13159e540890fcc99517833251848ab448af71ac Mon Sep 17 00:00:00 2001 From: njmbb8 Date: Sun, 12 Feb 2023 03:20:07 +0000 Subject: [PATCH 1/3] added support for multiple packages --- lib/usps/api/endpoints/rate_v4.rb | 88 +++++++++++++++---------------- 1 file changed, 43 insertions(+), 45 deletions(-) diff --git a/lib/usps/api/endpoints/rate_v4.rb b/lib/usps/api/endpoints/rate_v4.rb index aac73c2..a48fe13 100644 --- a/lib/usps/api/endpoints/rate_v4.rb +++ b/lib/usps/api/endpoints/rate_v4.rb @@ -14,22 +14,22 @@ module RateV4 # @option options [required, Hash] rate_v4_request API=RateV4 This API returns the current USPS postage corresponding to the parameters given. # * *:revision* (String) — Set this value to “2” to return all currently documented response fields. For example: 2 # * *:package* (Hash) — See the RateV4 Service Request chart for valid combinations of the following tags. - # * *:service* (required, ) — [{""=>"", "Description"=>"When = “ALL”, all eligible retail products will return in the API response."}, {""=>"", "Description"=>"When = “ONLINE”, all eligible retail and commercial base products will return in the API response."}, {""=>"", "Description"=>"When = “PLUS”, all eligible retail, commercial base, and commercial plus products will return in the API response."}] + # * *:service* (required, String) — Web Tools validates the entry to one of the service types. For example: PRIORITY MAIL EXPRESS Please see Appendix A for detailed business rules regarding combinations of Service, Container, dimensions and other request values. Note: Mailable matter not required to be mailed as First-Class Mail is permitted with Retail Ground to Zones 5-9. Zones 1-4 items are limited to mailable hazardous materials, live animals, and other “surface-only” items. Retail Ground can only be used for Zones 5-9 unless the shipment is oversized or contains classes of materials. (e.g. certain HAZMAT) For more details, see: http://pe.usps.com/businessmail101/classes/packageServices.htm. Note: The use of = “BPM” is restricted. If access to this service is needed, please reach out to the following email address: webtools@usps.gov. # * *:first_class_mail_type* (String) — Required when: RateV4Request[Service='FIRST CLASS'] or RateV4Request[Service='FIRST CLASS COMMERCIAL’], or RateV4Request[Service='FIRST CLASS HFP COMMERCIAL’] Example: LETTER Note: The tag is returned only if the submitted is “First Class”. If any other is returned (Including “First Class Commercial”) the tag is used. Note: Flats are also known as Large Envelopes # * *:zip_origination* (required, String) — ZIP code must be valid. For example: 20770 # * *:zip_destination* (required, String) — ZIP code must be valid. For example: 54324 # * *:pounds* (required, String) — Value must be numeric. Package weight cannot exceed 70 pounds. For example: 2 2.12345678 # * *:ounces* (required, String) — Value must be numeric. Package weight cannot exceed 70 pounds (1120 ounces). For example: 0 0.12345678 - # * *:container* (required, String) — Use to specify container attributes that may affect postage; otherwise, leave blank. Note: The tag is used instead of the tag only if the submitted is “First Class”. Note: “Cubic Soft Pack” and “Cubic Parcels” are only valid containers for service “Priority Mail Cubic”. Dimensions Length and Height are required when requesting Cubic Soft Pack. Dimensions Length, Height, and Width are required when requesting Cubic Parcels. Note: “VARIABLE” is used to denote that a customer is using packaging other than a USPS-produced Flat Rate Box/Envelope or Regional Rate Box”. Note: enumerations: “SM FLAT RATE BAG”, “LG FLAT RATE BAG”, “FLAT RATE BOX” only applicable when =“Connect Local.” + # * *:container* (required, String) — Use to specify container attributes that may affect postage; otherwise, leave blank. Note: The tag is used instead of the tag only if the submitted is “First Class”. Note: “Cubic Soft Pack” and “Cubic Parcels” are only valid containers for service “Priority Mail Cubic”. Dimensions Length and Height are required when requesting Cubic Soft Pack. Dimensions Length, Height, and Width are required when requesting Cubic Parcels. Note: “VARIABLE” is used to denote that a customer is using packaging other than a USPS-produced Flat Rate Box/Envelope or Regional Rate Box”. # * *:size* (String) — Note: This tag has been deprecated. tag and any values within the tag will not result in an error response and will not impact rates that are returned. - # * *:width* (Decimal) — Value must be numeric. Units are inches. If partial dimensions are provided, an error response will return. Length, Width, Height are required for accurate pricing of a rectangular package when any dimension of the item exceeds 12 inches. In addition, Girth is required only for a non-rectangular package in addition to Length, Width, Height when any dimension of the package exceeds 12 inches. For rectangular packages, the Girth dimension must be left blank as this dimension is to only be used for non-rectangular packages. For more details on dimensional weight pricing or dimension validation reference DMM https://pe.usps.com/text/dmm300/index.htm - # * *:length* (Decimal) — Value must be numeric. Units are inches. If partial dimensions are provided, an error response will return. Length, Width, Height are required for accurate pricing of a rectangular package when any dimension of the item exceeds 12 inches. In addition, Girth is required only for a non-rectangular package in addition to Length, Width, Height when any dimension of the package exceeds 12 inches. For rectangular packages, the Girth dimension must be left blank as this dimension is to only be used for non-rectangular packages. For more details on dimensional weight pricing or dimension validation reference DMM https://pe.usps.com/text/dmm300/index.htm - # * *:height* (Decimal) — Value must be numeric. Units are inches. If partial dimensions are provided, an error response will return. Length, Width, Height are required for accurate pricing of a rectangular package when any dimension of the item exceeds 12 inches. In addition, Girth is required only for a non-rectangular package in addition to Length, Width, Height when any dimension of the package exceeds 12 inches. For rectangular packages, the Girth dimension must be left blank as this dimension is to only be used for non-rectangular packages. For more details on dimensional weight pricing or dimension validation reference DMM https://pe.usps.com/text/dmm300/index.htm - # * *:girth* (Decimal) — Value must be numeric. Units are inches. If partial dimensions are provided, an error response will return. Length, Width, Height are required for accurate pricing of a rectangular package when any dimension of the item exceeds 12 inches. In addition, Girth is required only for a non-rectangular package in addition to Length, Width, Height when any dimension of the package exceeds 12 inches. For rectangular packages, the Girth dimension must be left blank as this dimension is to only be used for non-rectangular packages. For more details on dimensional weight pricing or dimension validation reference DMM https://pe.usps.com/text/dmm300/index.htm + # * *:width* (Decimal) — Value must be numeric. Units are inches. If partial dimensions are provided, an error response will return. Length, Width, Height are required for accurate pricing of a rectangular package when any dimension of the item exceeds 12 inches. In addition, Girth is required only for a non-rectangular package in addition to Length, Width, Height when any dimension of the package exceeds 12 inches. For rectangular packages, the Girth dimension must be left blank as this dimension is to only be used for non-rectangular packages. For more details on dimensional weight pricing, please reference the Domestic Mail Manual Section 123.1.4 for Retail Mail and Section 223.1.6 for Commercial Mail. https://pe.usps.com/text/dmm300/index.htm + # * *:length* (Decimal) — Value must be numeric. Units are inches. If partial dimensions are provided, an error response will return. Length, Width, Height are required for accurate pricing of a rectangular package when any dimension of the item exceeds 12 inches. In addition, Girth is required only for a non-rectangular package in addition to Length, Width, Height when any dimension of the package exceeds 12 inches. For rectangular packages, the Girth dimension must be left blank as this dimension is to only be used for non-rectangular packages. For more details on dimensional weight pricing, please reference the Domestic Mail Manual Section 123.1.4 for Retail Mail and Section 223.1.6 for Commercial Mail. https://pe.usps.com/text/dmm300/index.htm + # * *:height* (Decimal) — Value must be numeric. Units are inches. If partial dimensions are provided, an error response will return. Length, Width, Height are required for accurate pricing of a rectangular package when any dimension of the item exceeds 12 inches. In addition, Girth is required only for a non-rectangular package in addition to Length, Width, Height when any dimension of the package exceeds 12 inches. For rectangular packages, the Girth dimension must be left blank as this dimension is to only be used for non-rectangular packages. For more details on dimensional weight pricing, please reference the Domestic Mail Manual Section 123.1.4 for Retail Mail and Section 223.1.6 for Commercial Mail. https://pe.usps.com/text/dmm300/index.htm + # * *:girth* (Decimal) — Value must be numeric. Units are inches. If partial dimensions are provided, an error response will return. Length, Width, Height are required for accurate pricing of a rectangular package when any dimension of the item exceeds 12 inches. In addition, Girth is required only for a non-rectangular package in addition to Length, Width, Height when any dimension of the package exceeds 12 inches. For rectangular packages, the Girth dimension must be left blank as this dimension is to only be used for non-rectangular packages. For more details on dimensional weight pricing, please reference the Domestic Mail Manual Section 123.1.4 for Retail Mail and Section 223.1.6 for Commercial Mail. https://pe.usps.com/text/dmm300/index.htm # * *:value* (String) — Available when RateV4Request [Revision='2']. Package value. Used to determine availability and cost of extra services. For example: 150.00 # * *:amount_to_collect* (String) — Available when RateV4Request [Revision='2']. Collect on delivery amount. Used to determine availability and cost of extra services. For example: 150.00 # * *:special_services* (Hash) — Available when RateV4Request [Revision='2']. Groups the SpecialServices elements. Special Services prices and availability will not be returned when Service = “ALL”, “ONLINE”, or “PLUS” - # * *:special_service* (Special Service Name) — [{"Special Service Name"=>"Insurance", "ServiceID"=>"100"}, {"Special Service Name"=>"Insurance – Priority Mail Express", "ServiceID"=>"101"}, {"Special Service Name"=>"Return Receipt", "ServiceID"=>"102"}, {"Special Service Name"=>"Collect on Delivery", "ServiceID"=>"103"}, {"Special Service Name"=>"Certificate of Mailing (Form 3665)", "ServiceID"=>"104"}, {"Special Service Name"=>"Certified Mail", "ServiceID"=>"105"}, {"Special Service Name"=>"USPS Tracking", "ServiceID"=>"106"}, {"Special Service Name"=>"Signature Confirmation", "ServiceID"=>"108"}, {"Special Service Name"=>"Registered Mail", "ServiceID"=>"109"}, {"Special Service Name"=>"Return Receipt Electronic", "ServiceID"=>"110"}, {"Special Service Name"=>"Registered mail COD collection Charge", "ServiceID"=>"112"}, {"Special Service Name"=>"Return Receipt – Priority Mail Express", "ServiceID"=>"118"}, {"Special Service Name"=>"Adult Signature Required", "ServiceID"=>"119"}, {"Special Service Name"=>"Adult Signature Restricted Delivery", "ServiceID"=>"120"}, {"Special Service Name"=>"Insurance – Priority Mail", "ServiceID"=>"125"}, {"Special Service Name"=>"USPS Tracking Electronic", "ServiceID"=>"155"}, {"Special Service Name"=>"Signature Confirmation Electronic", "ServiceID"=>"156"}, {"Special Service Name"=>"Certificate of Mailing (Form 3817)", "ServiceID"=>"160"}, {"Special Service Name"=>"Certified Mail Restricted Delivery", "ServiceID"=>"170"}, {"Special Service Name"=>"Certified Mail Adult Signature Required", "ServiceID"=>"171"}, {"Special Service Name"=>"Certified Mail Adult Signature Restricted Delivery", "ServiceID"=>"172"}, {"Special Service Name"=>"Signature Confirm. Restrict. Delivery", "ServiceID"=>"173"}, {"Special Service Name"=>"Signature Confirmation Electronic Restricted Delivery", "ServiceID"=>"174"}, {"Special Service Name"=>"Collect on Delivery Restricted Delivery", "ServiceID"=>"175"}, {"Special Service Name"=>"Registered Mail Restricted Delivery", "ServiceID"=>"176"}, {"Special Service Name"=>"Insurance Restricted Delivery", "ServiceID"=>"177"}, {"Special Service Name"=>"Insurance Restrict. Delivery – Priority Mail", "ServiceID"=>"179"}, {"Special Service Name"=>"Insurance Restrict. Delivery – Priority Mail Express", "ServiceID"=>"178"}, {"Special Service Name"=>"Insurance Restrict. Delivery (Bulk Only)", "ServiceID"=>"180"}, {"Special Service Name"=>"Scan Retention", "ServiceID"=>"181"}, {"Special Service Name"=>"Scan + Signature Retention", "ServiceID"=>"182"}, {"Special Service Name"=>"Special Handling - Fragile", "ServiceID"=>"190"}, {"Special Service Name"=>"USPS Connect Sunday Delivery", "ServiceID"=>"447"}] + # * *:special_service* (Special Service Name) — [{"Special Service Name"=>"Insurance", "ServiceID"=>"100"}, {"Special Service Name"=>"Insurance – Priority Mail Express", "ServiceID"=>"101"}, {"Special Service Name"=>"Return Receipt", "ServiceID"=>"102"}, {"Special Service Name"=>"Collect on Delivery", "ServiceID"=>"103"}, {"Special Service Name"=>"Certificate of Mailing (Form 3665)", "ServiceID"=>"104"}, {"Special Service Name"=>"Certified Mail", "ServiceID"=>"105"}, {"Special Service Name"=>"USPS Tracking", "ServiceID"=>"106"}, {"Special Service Name"=>"Signature Confirmation", "ServiceID"=>"108"}, {"Special Service Name"=>"Registered Mail", "ServiceID"=>"109"}, {"Special Service Name"=>"Return Receipt Electronic", "ServiceID"=>"110"}, {"Special Service Name"=>"Registered mail COD collection Charge", "ServiceID"=>"112"}, {"Special Service Name"=>"Return Receipt – Priority Mail Express", "ServiceID"=>"118"}, {"Special Service Name"=>"Adult Signature Required", "ServiceID"=>"119"}, {"Special Service Name"=>"Adult Signature Restricted Delivery", "ServiceID"=>"120"}, {"Special Service Name"=>"Insurance – Priority Mail", "ServiceID"=>"125"}, {"Special Service Name"=>"USPS Tracking Electronic", "ServiceID"=>"155"}, {"Special Service Name"=>"Signature Confirmation Electronic", "ServiceID"=>"156"}, {"Special Service Name"=>"Certificate of Mailing (Form 3817)", "ServiceID"=>"160"}, {"Special Service Name"=>"Priority Mail Express 1030 AM Delivery", "ServiceID"=>"161"}, {"Special Service Name"=>"Certified Mail Restricted Delivery", "ServiceID"=>"170"}, {"Special Service Name"=>"Certified Mail Adult Signature Required", "ServiceID"=>"171"}, {"Special Service Name"=>"Certified Mail Adult Signature Restricted Delivery", "ServiceID"=>"172"}, {"Special Service Name"=>"Signature Confirm. Restrict. Delivery", "ServiceID"=>"173"}, {"Special Service Name"=>"Signature Confirmation Electronic Restricted Delivery", "ServiceID"=>"174"}, {"Special Service Name"=>"Collect on Delivery Restricted Delivery", "ServiceID"=>"175"}, {"Special Service Name"=>"Registered Mail Restricted Delivery", "ServiceID"=>"176"}, {"Special Service Name"=>"Insurance Restricted Delivery", "ServiceID"=>"177"}, {"Special Service Name"=>"Insurance Restrict. Delivery – Priority Mail", "ServiceID"=>"179"}, {"Special Service Name"=>"Insurance Restrict. Delivery – Priority Mail Express", "ServiceID"=>"178"}, {"Special Service Name"=>"Insurance Restrict. Delivery (Bulk Only)", "ServiceID"=>"180"}, {"Special Service Name"=>"Scan Retention", "ServiceID"=>"181"}, {"Special Service Name"=>"Scan + Signature Retention", "ServiceID"=>"182"}, {"Special Service Name"=>"Special Handling - Fragile", "ServiceID"=>"190"}] # * *:content* (Group) — Available when RateV4Request[Revision='2']. Groups the ContentType and ContentDescription elements. # * *:content_type* (String) — Available when RateV4Request [Revision=’2’]. Defines the type of content of the package. # * *:content_description* (String) — Available when RateV4Request[Revision=’2’]. Describes the content of the package. Optional but required for ContentType ‘LIVES’. @@ -42,10 +42,8 @@ module RateV4 # * *:ship_date* (String) — Date Package Will Be Mailed. Ship date may be today plus 0 to 3 days in advance. Enter the date in format: yyyy-mm-dd, such as 2013-07-28. Inclusion of Ship Date will result in and in the response for Priority Mail and Priority Mail Express variants For example: 2013-07-28 # * *:option* (String) — The value of this attribute specifies how the RateV4Response will structure the Priority Express Mail Commitment data elements. # * *:return_dimensional_weight* (Boolean) — This tag must be explicitly set to “true” for dimensional weight to be returned in the xml response. - # * *:tracking_retention_period* (ServiceID) — [{"ServiceID"=>"181", ""=>"“0.5” (6 Months)"}, {"ServiceID"=>"181", ""=>"“1” (1 Year)"}, {"ServiceID"=>"181", ""=>"“3” (3 Years)"}, {"ServiceID"=>"181", ""=>"“5” (5 Years)"}, {"ServiceID"=>"181", ""=>"“7” (7 Years)"}, {"ServiceID"=>"182", ""=>"“3” (3 Years)"}, {"ServiceID"=>"182", ""=>"“5” (5 Years)"}, {"ServiceID"=>"182", ""=>"“7” (7 Years)"}, {"ServiceID"=>"182", ""=>"“10” (10 Years)"}] - # * *:sortation_level* (Sortation) — [{"Sortation"=>"3D", "Description"=>"3-Digit"}, {"Sortation"=>"5D", "Description"=>"5-Digit"}, {"Sortation"=>"BAS", "Description"=>"Basic"}, {"Sortation"=>"CR", "Description"=>"Carrier Route"}, {"Sortation"=>"MIX", "Description"=>"Mixed NDC"}, {"Sortation"=>"NDC", "Description"=>"NDC"}, {"Sortation"=>"NONE", "Description"=>"None"}, {"Sortation"=>"PST", "Description"=>"Presort"}, {"Sortation"=>"SCF", "Description"=>"SCG"}, {"Sortation"=>"TBE", "Description"=>"EMM Tray Box"}, {"Sortation"=>"TBF", "Description"=>"Full Tray Box"}, {"Sortation"=>"TBH", "Description"=>"Half Tray Box"}, {"Sortation"=>"TBT", "Description"=>"Full Tub Tray Box"}] - # * *:destination_entry_facility_type* (Destination Type) — [{"Destination Type"=>"Destination Delivery Unit", "Value"=>"DDU"}, {"Destination Type"=>"Destination Network Distribution Unit", "Value"=>"DNDC"}, {"Destination Type"=>"Destination Sectional Center Facility", "Value"=>"DSCF"}] - def rate_v4(options = {}) + # * *:tracking_retention_period* (String) — Used to determine period of Retention for tracking data +def rate_v4(options = {}) throw ArgumentError.new('Required arguments :rate_v4_request missing') if options[:rate_v4_request].nil? request = build_request(:rate_v4, options) @@ -63,40 +61,40 @@ def tag_unless_blank(xml, tag_name, data) def build_rate_v4_request(xml, options = {}) tag_unless_blank(xml, 'Revision', options[:rate_v4_request][:revision]) - xml.tag!('Package') do - xml.tag!('Service', options[:rate_v4_request][:package][:service]) - tag_unless_blank(xml, 'FirstClassMailType', options[:rate_v4_request][:package][:first_class_mail_type]) - xml.tag!('ZipOrigination', options[:rate_v4_request][:package][:zip_origination]) - xml.tag!('ZipDestination', options[:rate_v4_request][:package][:zip_destination]) - xml.tag!('Pounds', options[:rate_v4_request][:package][:pounds]) - xml.tag!('Ounces', options[:rate_v4_request][:package][:ounces]) - xml.tag!('Container', options[:rate_v4_request][:package][:container]) - tag_unless_blank(xml, 'Size', options[:rate_v4_request][:package][:size]) - tag_unless_blank(xml, 'Width', options[:rate_v4_request][:package][:width]) - tag_unless_blank(xml, 'Length', options[:rate_v4_request][:package][:length]) - tag_unless_blank(xml, 'Height', options[:rate_v4_request][:package][:height]) - tag_unless_blank(xml, 'Girth', options[:rate_v4_request][:package][:girth]) - tag_unless_blank(xml, 'Value', options[:rate_v4_request][:package][:value]) - tag_unless_blank(xml, 'AmountToCollect', options[:rate_v4_request][:package][:amount_to_collect]) - xml.tag!('SpecialServices') do - tag_unless_blank(xml, 'SpecialService', options[:rate_v4_request][:package][:special_services][:special_service]) - tag_unless_blank(xml, 'Content', options[:rate_v4_request][:package][:special_services][:content]) - tag_unless_blank(xml, 'ContentType', options[:rate_v4_request][:package][:special_services][:content_type]) - tag_unless_blank(xml, 'ContentDescription', options[:rate_v4_request][:package][:special_services][:content_description]) - tag_unless_blank(xml, 'GroundOnly', options[:rate_v4_request][:package][:special_services][:ground_only]) - tag_unless_blank(xml, 'SortBy', options[:rate_v4_request][:package][:special_services][:sort_by]) - tag_unless_blank(xml, 'Machinable', options[:rate_v4_request][:package][:special_services][:machinable]) - tag_unless_blank(xml, 'ReturnLocations', options[:rate_v4_request][:package][:special_services][:return_locations]) - tag_unless_blank(xml, 'ReturnServiceInfo', options[:rate_v4_request][:package][:special_services][:return_service_info]) - tag_unless_blank(xml, 'DropOffTime', options[:rate_v4_request][:package][:special_services][:drop_off_time]) - tag_unless_blank(xml, 'ShipDate', options[:rate_v4_request][:package][:special_services][:ship_date]) - tag_unless_blank(xml, 'Option', options[:rate_v4_request][:package][:special_services][:option]) - tag_unless_blank(xml, 'ReturnDimensionalWeight', options[:rate_v4_request][:package][:special_services][:return_dimensional_weight]) - tag_unless_blank(xml, 'TrackingRetentionPeriod', options[:rate_v4_request][:package][:special_services][:tracking_retention_period]) - tag_unless_blank(xml, 'SortationLevel', options[:rate_v4_request][:package][:special_services][:sortation_level]) - tag_unless_blank(xml, 'DestinationEntryFacilityType', options[:rate_v4_request][:package][:special_services][:destination_entry_facility_type]) - end if options[:rate_v4_request][:package][:special_services].present? - end if options[:rate_v4_request][:package].present? + options[:rate_v4_request][:packages].each do |package| + xml.tag!("Package", {ID: "#{package[:id]}"}) do + tag_unless_blank(xml, 'FirstClassMailType', package[:first_class_mail_type]) + xml.tag!('Service', package[:service]) + xml.tag!('ZipOrigination', package[:zip_origination]) + xml.tag!('ZipDestination', package[:zip_destination]) + xml.tag!('Pounds', package[:pounds]) + xml.tag!('Ounces', package[:ounces]) + xml.tag!('Container', package[:container]) + tag_unless_blank(xml, 'Width', package[:width]) + tag_unless_blank(xml, 'Length', package[:length]) + tag_unless_blank(xml, 'Height', package[:height]) + tag_unless_blank(xml, 'Girth', package[:girth]) + tag_unless_blank(xml, 'Value', package[:value]) + tag_unless_blank(xml, 'Machinable', package[:machinable].to_s.capitalize) + tag_unless_blank(xml, 'AmountToCollect', package[:amount_to_collect]) + xml.tag!('SpecialServices') do + tag_unless_blank(xml, 'SpecialService', package[:special_services][:special_service]) + tag_unless_blank(xml, 'Content', package[:special_services][:content]) + tag_unless_blank(xml, 'ContentType', package[:special_services][:content_type]) + tag_unless_blank(xml, 'ContentDescription', package[:special_services][:content_description]) + tag_unless_blank(xml, 'GroundOnly', package[:special_services][:ground_only]) + tag_unless_blank(xml, 'SortBy', package[:special_services][:sort_by]) + tag_unless_blank(xml, 'Machinable', package[:special_services][:machinable]) + tag_unless_blank(xml, 'ReturnLocations', package[:special_services][:return_locations]) + tag_unless_blank(xml, 'ReturnServiceInfo', package[:special_services][:return_service_info]) + tag_unless_blank(xml, 'DropOffTime', package[:special_services][:drop_off_time]) + tag_unless_blank(xml, 'ShipDate', package[:special_services][:ship_date]) + tag_unless_blank(xml, 'Option', package[:special_services][:option]) + tag_unless_blank(xml, 'ReturnDimensionalWeight', package[:special_services][:return_dimensional_weight]) + tag_unless_blank(xml, 'TrackingRetentionPeriod', package[:special_services][:tracking_retention_period]) + end if package[:special_services].present? + end + end xml.target! end From efa2c74bac320452ce242acd504f88f418addc6c Mon Sep 17 00:00:00 2001 From: Nate McGraw Date: Sun, 12 Feb 2023 19:51:11 -0500 Subject: [PATCH 2/3] Create README.md --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index 39bf207..d7afe08 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,40 @@ +About this fork: +================= +I created this fork to update the ratev4 interface to be more closely aligned with the specifications provided by the usps. Machinable is a required field and takes a boolean value as is an ID for each package which can take an int or a string. Support for multiple packages are also now supported and can be passed to the gem as an array of hashes of the same format as before. + +##Usage: +``` +packages = [ + { + :id => 0, + :service => "ONLINE", + :zip_origination => "12345", + :zip_destination => 67890, + :container => '', + :width => 1, + :length => 2, + :height => 3, + :value => 34, + :pounds => 67, + :ounces => 3, + :machinable => true + }, + { + :id => 1, + :service => "ONLINE", + :zip_origination => "12345", + :zip_destination => 67890, + :container => '', + :width => 12, + :length => 54, + :height => 234, + :value => 123, + :pounds => 78, + :ounces => 234, + :machinable => true + }, +] +``` USPS Ruby Client ================= [![Build Status](https://travis-ci.com/joeyparis/usps-ruby-client.svg?branch=master)](https://travis-ci.com/joeyparis/usps-ruby-client) From a1afd453fba8a39c0f8b50957935854a54003536 Mon Sep 17 00:00:00 2001 From: Nate McGraw Date: Sun, 12 Feb 2023 19:52:27 -0500 Subject: [PATCH 3/3] Update README.md --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d7afe08..ba7f8a1 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,19 @@ packages = [ :pounds => 78, :ounces => 234, :machinable => true - }, + } ] + +usps = Usps::Client.new({ + user_id: Rails.application.credentials.usps[:username] +}) + +rates = usps.rate_v4({ + :rate_v4_request => { + :revision => 2, + :packages => packages + } +}) ``` USPS Ruby Client =================