Class: UspsApi::ExtraServiceRateQuery

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

Overview

Search parameters for an extra service price.

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(mail_class:, price_type:, extra_services: SKIP, item_value: SKIP, weight: SKIP, origin_zip_code: SKIP, destination_zip_code: SKIP, mailing_date: SKIP, account_type: SKIP, account_number: SKIP) ⇒ ExtraServiceRateQuery

Returns a new instance of ExtraServiceRateQuery.



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 183

def initialize(mail_class:, price_type:, extra_services: SKIP,
               item_value: SKIP, weight: SKIP, origin_zip_code: SKIP,
               destination_zip_code: SKIP, mailing_date: SKIP,
               account_type: SKIP, account_number: SKIP)
  @extra_services = extra_services unless extra_services == SKIP
  @mail_class = mail_class
  @price_type = price_type
  @item_value = item_value unless item_value == SKIP
  @weight = weight unless weight == SKIP
  @origin_zip_code = origin_zip_code unless origin_zip_code == SKIP
  @destination_zip_code = destination_zip_code unless destination_zip_code == SKIP
  @mailing_date = mailing_date unless mailing_date == SKIP
  @account_type =  unless  == SKIP
  @account_number =  unless  == SKIP
end

Instance Attribute Details

#account_numberString

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

Returns:

  • (String)


146
147
148
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 146

def 
  @account_number
end

#account_typeAccountType

The type of payment account linked to a contract rate. Note:

  • ‘METER` pricing is only available to PC Postage providers.

  • ‘MID` pricing is only available for return mail classes.

Returns:



141
142
143
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 141

def 
  @account_type
end

#destination_zip_codeString

The destination ZIP code for the package.

Returns:

  • (String)


127
128
129
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 127

def destination_zip_code
  @destination_zip_code
end

#extra_servicesArray[ExtraService1]

Extra Service Codes requested.

  • 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

Note: Entering a single extra service will be removed in the next major revision.

Returns:



82
83
84
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 82

def extra_services
  @extra_services
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)


113
114
115
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 113

def item_value
  @item_value
end

#mail_classPricesMailClass

The mail service requested. 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`.

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

‘USPS_GROUND_ADVANTAGE_RETURN_SERVICE`.

  • ‘GROUND_RETURN_SERVICE` is deprecated and will convert to

‘USPS_GROUND_ADVANTAGE_RETURN_SERVICE`.

  • ‘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:



102
103
104
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 102

def mail_class
  @mail_class
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)


134
135
136
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 134

def mailing_date
  @mailing_date
end

#origin_zip_codeString

The originating ZIP code for the package.

Returns:

  • (String)


123
124
125
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 123

def origin_zip_code
  @origin_zip_code
end

#price_typePricesPriceType

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

Returns:



107
108
109
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 107

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)


119
120
121
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 119

def weight
  @weight
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 200

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  mail_class = hash.key?('mailClass') ? hash['mailClass'] : nil
  price_type = hash.key?('priceType') ? hash['priceType'] : nil
  extra_services = hash.key?('extraServices') ? hash['extraServices'] : SKIP
  item_value = hash.key?('itemValue') ? hash['itemValue'] : SKIP
  weight = hash.key?('weight') ? hash['weight'] : SKIP
  origin_zip_code =
    hash.key?('originZIPCode') ? hash['originZIPCode'] : SKIP
  destination_zip_code =
    hash.key?('destinationZIPCode') ? hash['destinationZIPCode'] : SKIP
  mailing_date = hash.key?('mailingDate') ? hash['mailingDate'] : SKIP
   = hash.key?('accountType') ? hash['accountType'] : SKIP
   = hash.key?('accountNumber') ? hash['accountNumber'] : SKIP

  # Create object from extracted values.
  ExtraServiceRateQuery.new(mail_class: mail_class,
                            price_type: price_type,
                            extra_services: extra_services,
                            item_value: item_value,
                            weight: weight,
                            origin_zip_code: origin_zip_code,
                            destination_zip_code: destination_zip_code,
                            mailing_date: mailing_date,
                            account_type: ,
                            account_number: )
end

.namesObject

A mapping from model property names to API property names.



149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 149

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

.nullablesObject

An array for nullable fields



179
180
181
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 179

def self.nullables
  []
end

.optionalsObject

An array for optional fields



165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 165

def self.optionals
  %w[
    extra_services
    item_value
    weight
    origin_zip_code
    destination_zip_code
    mailing_date
    account_type
    account_number
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 232

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.mail_class,
                            ->(val) { PricesMailClass.validate(val) }) and
        APIHelper.valid_type?(value.price_type,
                              ->(val) { PricesPriceType.validate(val) })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['mailClass'],
                          ->(val) { PricesMailClass.validate(val) }) and
      APIHelper.valid_type?(value['priceType'],
                            ->(val) { PricesPriceType.validate(val) })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



262
263
264
265
266
267
268
269
270
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 262

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

#to_sObject

Provides a human-readable string representation of the object.



253
254
255
256
257
258
259
# File 'lib/usps_api/models/extra_service_rate_query.rb', line 253

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