Class: UspsApi::DomesticPackageDescription

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

Overview

Details of package being shipped

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(weight:, length:, height:, width:, mail_class:, girth: SKIP, has_nonstandard_characteristics: false, extra_services: SKIP, package_value: SKIP, mailing_date: SKIP, additional_properties: nil) ⇒ DomesticPackageDescription

Returns a new instance of DomesticPackageDescription.



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/usps_api/models/domestic_package_description.rb', line 202

def initialize(weight:, length:, height:, width:, mail_class:, girth: SKIP,
               has_nonstandard_characteristics: false, extra_services: SKIP,
               package_value: SKIP, mailing_date: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @weight = weight
  @length = length
  @height = height
  @width = width
  @girth = girth unless girth == SKIP
  unless has_nonstandard_characteristics == SKIP
    @has_nonstandard_characteristics =
      has_nonstandard_characteristics
  end
  @mail_class = mail_class
  @extra_services = extra_services unless extra_services == SKIP
  @package_value = package_value unless package_value == SKIP
  @mailing_date = mailing_date unless mailing_date == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#extra_servicesArray[ShipmentsExtraServiceCodes]

Extra Services requested on the package. The available options are:

  • 365 - Global Direct Entry

  • 415 - USPS Label Delivery

  • 452 - USPS Returns

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



154
155
156
# File 'lib/usps_api/models/domestic_package_description.rb', line 154

def extra_services
  @extra_services
end

#girthFloat

The girth of the container, in dimensionsUOM. 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.

Returns:

  • (Float)


59
60
61
# File 'lib/usps_api/models/domestic_package_description.rb', line 59

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


67
68
69
# File 'lib/usps_api/models/domestic_package_description.rb', line 67

def has_nonstandard_characteristics
  @has_nonstandard_characteristics
end

#heightFloat

The height of the container, in dimensionsUOM. 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.

Returns:

  • (Float)


37
38
39
# File 'lib/usps_api/models/domestic_package_description.rb', line 37

def height
  @height
end

#lengthFloat

The length of the container, in dimensionsUOM. 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.

Returns:

  • (Float)


26
27
28
# File 'lib/usps_api/models/domestic_package_description.rb', line 26

def length
  @length
end

#mail_classMailClass10

Mail classes for the label. 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`.

  • ‘ALL` is deprecated and will convert to `ALL_OUTBOUND`.

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



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

def mail_class
  @mail_class
end

#mailing_dateObject

The local date on which the package will be mailed. If the time is not provided, it will be defaulted to 6:00 p.m. local time. The local time is based on the ‘originZIPCode` provided in the request.

Returns:

  • (Object)


167
168
169
# File 'lib/usps_api/models/domestic_package_description.rb', line 167

def mailing_date
  @mailing_date
end

#package_valueFloat

The merchandise value of the package, in US dollars. Required to receive prices for Insurance and Collect On Delivery extra services. The price of Insurance, Collect On Delivery, and Registered Mail extra services will vary based on the ‘packageValue` requested.

Returns:

  • (Float)


161
162
163
# File 'lib/usps_api/models/domestic_package_description.rb', line 161

def package_value
  @package_value
end

#weightFloat

The package weight, in weightUOM (Unit Of Measure). Items must weigh 70 pounds (1120 ounces) or less.

Returns:

  • (Float)


15
16
17
# File 'lib/usps_api/models/domestic_package_description.rb', line 15

def weight
  @weight
end

#widthFloat

The width of the container, in dimensionsUOM. 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.

Returns:

  • (Float)


48
49
50
# File 'lib/usps_api/models/domestic_package_description.rb', line 48

def width
  @width
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/usps_api/models/domestic_package_description.rb', line 226

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  weight = hash.key?('weight') ? hash['weight'] : nil
  length = hash.key?('length') ? hash['length'] : nil
  height = hash.key?('height') ? hash['height'] : nil
  width = hash.key?('width') ? hash['width'] : nil
  mail_class = hash.key?('mailClass') ? hash['mailClass'] : nil
  girth = hash.key?('girth') ? hash['girth'] : SKIP
  has_nonstandard_characteristics =
    hash['hasNonstandardCharacteristics'] ||= false
  extra_services = hash.key?('extraServices') ? hash['extraServices'] : SKIP
  package_value = hash.key?('packageValue') ? hash['packageValue'] : SKIP
  mailing_date = hash.key?('mailingDate') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:DomesticPackageDescriptionMailingDate), hash['mailingDate']
  ) : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  DomesticPackageDescription.new(weight: weight,
                                 length: length,
                                 height: height,
                                 width: width,
                                 mail_class: mail_class,
                                 girth: girth,
                                 has_nonstandard_characteristics: has_nonstandard_characteristics,
                                 extra_services: extra_services,
                                 package_value: package_value,
                                 mailing_date: mailing_date,
                                 additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/usps_api/models/domestic_package_description.rb', line 170

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['weight'] = 'weight'
  @_hash['length'] = 'length'
  @_hash['height'] = 'height'
  @_hash['width'] = 'width'
  @_hash['girth'] = 'girth'
  @_hash['has_nonstandard_characteristics'] =
    'hasNonstandardCharacteristics'
  @_hash['mail_class'] = 'mailClass'
  @_hash['extra_services'] = 'extraServices'
  @_hash['package_value'] = 'packageValue'
  @_hash['mailing_date'] = 'mailingDate'
  @_hash
end

.nullablesObject

An array for nullable fields



198
199
200
# File 'lib/usps_api/models/domestic_package_description.rb', line 198

def self.nullables
  []
end

.optionalsObject

An array for optional fields



187
188
189
190
191
192
193
194
195
# File 'lib/usps_api/models/domestic_package_description.rb', line 187

def self.optionals
  %w[
    girth
    has_nonstandard_characteristics
    extra_services
    package_value
    mailing_date
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/usps_api/models/domestic_package_description.rb', line 273

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.weight,
                            ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.length,
                              ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.height,
                              ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.width,
                              ->(val) { val.instance_of? Float }) and
        APIHelper.valid_type?(value.mail_class,
                              ->(val) { MailClass10.validate(val) })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['weight'],
                          ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['length'],
                            ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['height'],
                            ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['width'],
                            ->(val) { val.instance_of? Float }) and
      APIHelper.valid_type?(value['mailClass'],
                            ->(val) { MailClass10.validate(val) })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



316
317
318
319
320
321
322
323
324
# File 'lib/usps_api/models/domestic_package_description.rb', line 316

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} weight: #{@weight.inspect}, length: #{@length.inspect}, height:"\
  " #{@height.inspect}, width: #{@width.inspect}, girth: #{@girth.inspect},"\
  " has_nonstandard_characteristics: #{@has_nonstandard_characteristics.inspect}, mail_class:"\
  " #{@mail_class.inspect}, extra_services: #{@extra_services.inspect}, package_value:"\
  " #{@package_value.inspect}, mailing_date: #{@mailing_date.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



306
307
308
309
310
311
312
313
# File 'lib/usps_api/models/domestic_package_description.rb', line 306

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} weight: #{@weight}, length: #{@length}, height: #{@height}, width:"\
  " #{@width}, girth: #{@girth}, has_nonstandard_characteristics:"\
  " #{@has_nonstandard_characteristics}, mail_class: #{@mail_class}, extra_services:"\
  " #{@extra_services}, package_value: #{@package_value}, mailing_date: #{@mailing_date},"\
  " additional_properties: #{@additional_properties}>"
end

#to_union_type_mailing_dateObject



265
266
267
268
269
# File 'lib/usps_api/models/domestic_package_description.rb', line 265

def to_union_type_mailing_date
  UnionTypeLookUp.get(:DomesticPackageDescriptionMailingDate)
                 .validate(mailing_date)
                 .serialize(mailing_date)
end