Class: UspsApi::PricesTotalRatesQuery

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/usps_api/models/prices_total_rates_query.rb

Overview

Search parameters for base rate and extra service rate.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(origin_zip_code:, destination_zip_code:, weight:, length:, width:, height:, mail_class: SKIP, mail_classes: SKIP, price_type: SKIP, mailing_date: SKIP, account_type: SKIP, account_number: SKIP, has_nonstandard_characteristics: false, item_value: SKIP, extra_services: SKIP) ⇒ PricesTotalRatesQuery

Returns a new instance of PricesTotalRatesQuery.



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 220

def initialize(origin_zip_code:, destination_zip_code:, weight:, length:,
               width:, height:, mail_class: SKIP, mail_classes: SKIP,
               price_type: SKIP, mailing_date: SKIP, account_type: SKIP,
               account_number: SKIP, has_nonstandard_characteristics: false,
               item_value: SKIP, extra_services: SKIP)
  @origin_zip_code = origin_zip_code
  @destination_zip_code = destination_zip_code
  @weight = weight
  @length = length
  @width = width
  @height = height
  @mail_class = mail_class unless mail_class == SKIP
  @mail_classes = mail_classes unless mail_classes == SKIP
  @price_type = price_type unless price_type == SKIP
  @mailing_date = mailing_date unless mailing_date == SKIP
  @account_type =  unless  == SKIP
  @account_number =  unless  == SKIP
  unless has_nonstandard_characteristics == SKIP
    @has_nonstandard_characteristics =
      has_nonstandard_characteristics
  end
  @item_value = item_value unless item_value == SKIP
  @extra_services = extra_services unless extra_services == SKIP
end

Instance Attribute Details

#account_numberString

The Enterprise Payment Account, Permit number or PC Postage meter number associated with a contract.

Returns:

  • (String)


89
90
91
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 89

def 
  @account_number
end

#account_typeAccountType1

The type of payment account linked to a contract rate.

Returns:



84
85
86
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 84

def 
  @account_type
end

#destination_zip_codeString

The destination ZIP code for the package.

Returns:

  • (String)


18
19
20
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 18

def destination_zip_code
  @destination_zip_code
end

#extra_servicesArray[ExtraService1]

Extra Service Codes requested. If omitted, all available extra services will be returned. To narrow the results, provide a specific set of extra service codes. For convenience, use ‘986` for `PRIORITY_MAIL_EXPRESS` or `920` for all other `mailClasses`.

  • 415 - USPS Label Delivery

  • 480 - Tracking Plus 6 Months

  • 481 - Tracking Plus 1 Year

  • 482 - Tracking Plus 3 Years

  • 483 - Tracking Plus 5 Years

  • 484 - Tracking Plus 7 Years

  • 485 - Tracking Plus 10 Years

  • 486 - Tracking Plus Signature 3 Years

  • 487 - Tracking Plus Signature 5 Years

  • 488 - Tracking Plus Signature 7 Years

  • 489 - Tracking Plus Signature 10 Years

  • 498 - PO Box Locker – Stocking Fee (NSA Only)

  • 500 - PO Box Locker – Self-Service Pickup Fee (NSA Only)

  • 501 - PO Box Locker – Clerk-Assisted Pickup Fee (NSA Only)

  • 502 - PO Box Locker – Local Delivery Fee (NSA Only)

  • 810 - HAZMAT Air Eligible Ethanol Package

  • 811 - HAZMAT Class 1 - Toy Propellant/Safety Fuse Package

  • 812 - HAZMAT Class 3 – Flammable Liquid Package

  • 813 - HAZMAT Class 7 - Radioactive Materials Package

  • 814 - HAZMAT Class 8 - Corrosive Materials Package

  • 815 - HAZMAT Class 8 - Nonspillable Wet Battery Package

  • 816 - HAZMAT Class 9 - Lithium Battery Marked - Ground Only Package

  • 817 - HAZMAT Class 9 - Lithium Battery - Returns Package

  • 818 - HAZMAT Class 9 - Lithium batteries, marked package

  • 819 - HAZMAT Class 9 - Dry Ice Package

  • 820 - HAZMAT Class 9 - Lithium batteries, unmarked package

  • 821 - HAZMAT Class 9 - Magnetized Materials Package

  • 822 - HAZMAT Division 4.1 – Flammable Solids or Safety Matches Package

  • 823 - HAZMAT Division 5.1 - Oxidizers Package

  • 824 - HAZMAT Division 5.2 - Organic Peroxides Package

  • 825 - HAZMAT Division 6.1 – Toxic Materials Package

  • 826 - HAZMAT Division 6.2 – Infectious Substances Package

  • 827 - HAZMAT Excepted Quantity Provision Package

  • 828 - HAZMAT Ground Only

  • 829 - HAZMAT ID8000 Consumer Commodity Package

  • 830 - HAZMAT Lighters Package

  • 831 - HAZMAT LTD QTY Ground Package

  • 832 - HAZMAT Small Quantity Provision Package

  • 853 - Perishable Material

  • 856 - Live Animals Transportation Fee

  • 857 - Hazardous Material

  • 858 - Cremated Remains

  • 910 - Certified Mail

  • 911 - Certified Mail Restricted Delivery

  • 912 - Certified Mail Adult Signature Required

  • 913 - Certified Mail Adult Signature Restricted Delivery

  • 915 - Collect on Delivery (COD)

  • 917 - COD Restricted Delivery

  • 920 - USPS Tracking

  • 921 - Signature Confirmation

  • 922 - Adult Signature Required 21 or Over

  • 923 - Adult Signature Restricted Delivery 21 or Over

  • 924 - Signature Confirmation Restricted Delivery

  • 925 - Priority Mail Express Merchandise Insurance

  • 930 - Insurance <= $500

  • 931 - Insurance > $500

  • 934 - Insurance Restricted Delivery

  • 940 - Registered Mail

  • 941 - Registered Mail Restricted Delivery

  • 955 - Return Receipt

  • 957 - Return Receipt Electronic

  • 972 - Live Animal and Perishable Handling Fee

  • 981 - Signature Requested (PRIORITY_MAIL_EXPRESS only)

  • 984 - Parcel Locker Delivery

  • 986 - PO to Addressee (PRIORITY_MAIL_EXPRESS only)

  • 991 - Sunday Delivery

Returns:



176
177
178
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 176

def extra_services
  @extra_services
end

#has_nonstandard_characteristicsTrueClass | FalseClass

Package is nonstandard. Nonstandard packages include cylindrical tubes and rolls, certain high-density items, cartons containing more than 24 ounces of liquids in one or more glass containers, cartons containing 1 gallon or more of liquid in metal or plastic containers, and items in [201.7.6.2](pe.usps.com/text/dmm300/201.htm#7.6.2).

Returns:

  • (TrueClass | FalseClass)


97
98
99
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 97

def has_nonstandard_characteristics
  @has_nonstandard_characteristics
end

#heightFloat

This is the package height in inches.

Returns:

  • (Float)


38
39
40
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 38

def height
  @height
end

#item_valueFloat

The value of the item. Required for Insurance and Collect On Delivery. The price for Insurance, Registered Mail, and Collect On Delivery extra services will vary based on this value.

Returns:

  • (Float)


103
104
105
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 103

def item_value
  @item_value
end

#lengthFloat

This is the package length in inches. The maximum dimension is always length.

Returns:

  • (Float)


29
30
31
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 29

def length
  @length
end

#mail_classMailClassOutboundOnly

The mail service requested.

Note:
- A single mail class option is deprecated and will be removed in the

next major revision. This attribute will be replaced with the list of mail classes.

- `PARCEL_SELECT_LIGHTWEIGHT` is deprecated and will convert to

‘PARCEL_SELECT`

- `FIRST-CLASS_PACKAGE_SERVICE` is deprecated and will convert to

‘USPS_GROUND_ADVANTAGE`

- `USPS_RETAIL_GROUND` is no longer supported and will return a 400 if

used



52
53
54
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 52

def mail_class
  @mail_class
end

#mail_classesArray[MailClassOutboundOnly]

A list of mail classes. Note:

  • ‘PARCEL_SELECT_LIGHTWEIGHT` is deprecated and will convert to

‘PARCEL_SELECT`.

  • ‘FIRST-CLASS_PACKAGE_SERVICE` is deprecated and will convert to

‘USPS_GROUND_ADVANTAGE`.

  • ‘USPS_RETAIL_GROUND` is no longer supported and will return a 400 if

used.

  • Certain mail classes, such as ‘MEDIA_MAIL`, `BOUND_PRINTED_MATTER`, and

‘LIBRARY_MAIL`, have eligibility rules on what can be mailed using that service. For more details on these mail classes, please visit [What are Package Services?](faq.usps.com/s/article/What-are-Package-Services).

Returns:



68
69
70
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 68

def mail_classes
  @mail_classes
end

#mailing_dateDate

The date the package or letter/flat/card will be mailed. The mailing date may be today plus 0 to 7 days in advance. Enter the date in the full-date notation as defined by [RFC 3339, section 5.6](datatracker.ietf.org/doc/html/rfc3339#section-5.6).

Returns:

  • (Date)


80
81
82
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 80

def mailing_date
  @mailing_date
end

#origin_zip_codeString

The originating ZIP code for the package.

Returns:

  • (String)


14
15
16
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 14

def origin_zip_code
  @origin_zip_code
end

#price_typePricesPriceType

Price type can be * ‘RETAIL’ * ‘COMMERCIAL’ * ‘CONTRACT’ * ‘NSA’ (deprecated)

Returns:



73
74
75
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 73

def price_type
  @price_type
end

#weightFloat

This is the calculated weight for the package based on user input. The greater of dimWeight and weight will be used to calculated the rate. Weight unit of measurement is in pounds.

Returns:

  • (Float)


24
25
26
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 24

def weight
  @weight
end

#widthFloat

This is the package width in inches. The second longest dimension is always width.

Returns:

  • (Float)


34
35
36
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 34

def width
  @width
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 246

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  origin_zip_code = hash.key?('originZIPCode') ? hash['originZIPCode'] : nil
  destination_zip_code =
    hash.key?('destinationZIPCode') ? hash['destinationZIPCode'] : nil
  weight = hash.key?('weight') ? hash['weight'] : nil
  length = hash.key?('length') ? hash['length'] : nil
  width = hash.key?('width') ? hash['width'] : nil
  height = hash.key?('height') ? hash['height'] : nil
  mail_class = hash.key?('mailClass') ? hash['mailClass'] : SKIP
  mail_classes = hash.key?('mailClasses') ? hash['mailClasses'] : SKIP
  price_type = hash.key?('priceType') ? hash['priceType'] : SKIP
  mailing_date = hash.key?('mailingDate') ? hash['mailingDate'] : SKIP
   = hash.key?('accountType') ? hash['accountType'] : SKIP
   = hash.key?('accountNumber') ? hash['accountNumber'] : SKIP
  has_nonstandard_characteristics =
    hash['hasNonstandardCharacteristics'] ||= false
  item_value = hash.key?('itemValue') ? hash['itemValue'] : SKIP
  extra_services = hash.key?('extraServices') ? hash['extraServices'] : SKIP

  # Create object from extracted values.
  PricesTotalRatesQuery.new(origin_zip_code: origin_zip_code,
                            destination_zip_code: destination_zip_code,
                            weight: weight,
                            length: length,
                            width: width,
                            height: height,
                            mail_class: mail_class,
                            mail_classes: mail_classes,
                            price_type: price_type,
                            mailing_date: mailing_date,
                            account_type: ,
                            account_number: ,
                            has_nonstandard_characteristics: has_nonstandard_characteristics,
                            item_value: item_value,
                            extra_services: extra_services)
end

.namesObject

A mapping from model property names to API property names.



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 179

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['origin_zip_code'] = 'originZIPCode'
  @_hash['destination_zip_code'] = 'destinationZIPCode'
  @_hash['weight'] = 'weight'
  @_hash['length'] = 'length'
  @_hash['width'] = 'width'
  @_hash['height'] = 'height'
  @_hash['mail_class'] = 'mailClass'
  @_hash['mail_classes'] = 'mailClasses'
  @_hash['price_type'] = 'priceType'
  @_hash['mailing_date'] = 'mailingDate'
  @_hash['account_type'] = 'accountType'
  @_hash['account_number'] = 'accountNumber'
  @_hash['has_nonstandard_characteristics'] =
    'hasNonstandardCharacteristics'
  @_hash['item_value'] = 'itemValue'
  @_hash['extra_services'] = 'extraServices'
  @_hash
end

.nullablesObject

An array for nullable fields



216
217
218
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 216

def self.nullables
  []
end

.optionalsObject

An array for optional fields



201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 201

def self.optionals
  %w[
    mail_class
    mail_classes
    price_type
    mailing_date
    account_type
    account_number
    has_nonstandard_characteristics
    item_value
    extra_services
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



299
300
301
302
303
304
305
306
307
308
309
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 299

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} origin_zip_code: #{@origin_zip_code.inspect}, destination_zip_code:"\
  " #{@destination_zip_code.inspect}, weight: #{@weight.inspect}, length: #{@length.inspect},"\
  " width: #{@width.inspect}, height: #{@height.inspect}, mail_class: #{@mail_class.inspect},"\
  " mail_classes: #{@mail_classes.inspect}, price_type: #{@price_type.inspect}, mailing_date:"\
  " #{@mailing_date.inspect}, account_type: #{@account_type.inspect}, account_number:"\
  " #{@account_number.inspect}, has_nonstandard_characteristics:"\
  " #{@has_nonstandard_characteristics.inspect}, item_value: #{@item_value.inspect},"\
  " extra_services: #{@extra_services.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



287
288
289
290
291
292
293
294
295
296
# File 'lib/usps_api/models/prices_total_rates_query.rb', line 287

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} origin_zip_code: #{@origin_zip_code}, destination_zip_code:"\
  " #{@destination_zip_code}, weight: #{@weight}, length: #{@length}, width: #{@width},"\
  " height: #{@height}, mail_class: #{@mail_class}, mail_classes: #{@mail_classes},"\
  " price_type: #{@price_type}, mailing_date: #{@mailing_date}, account_type:"\
  " #{@account_type}, account_number: #{@account_number}, has_nonstandard_characteristics:"\
  " #{@has_nonstandard_characteristics}, item_value: #{@item_value}, extra_services:"\
  " #{@extra_services}>"
end