Class: UspsApi::ShipmentsPackageDescription

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

Overview

Package Definitions

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:, girth: SKIP, has_nonstandard_characteristics: false, additional_properties: nil) ⇒ ShipmentsPackageDescription

Returns a new instance of ShipmentsPackageDescription.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/usps_api/models/shipments_package_description.rb', line 95

def initialize(weight:, length:, height:, width:, girth: SKIP,
               has_nonstandard_characteristics: false,
               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
  @additional_properties = additional_properties
end

Instance Attribute Details

#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/shipments_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/shipments_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/shipments_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/shipments_package_description.rb', line 26

def length
  @length
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/shipments_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/shipments_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.



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/usps_api/models/shipments_package_description.rb', line 114

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
  girth = hash.key?('girth') ? hash['girth'] : SKIP
  has_nonstandard_characteristics =
    hash['hasNonstandardCharacteristics'] ||= false

  # 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.
  ShipmentsPackageDescription.new(weight: weight,
                                  length: length,
                                  height: height,
                                  width: width,
                                  girth: girth,
                                  has_nonstandard_characteristics: has_nonstandard_characteristics,
                                  additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/usps_api/models/shipments_package_description.rb', line 70

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
end

.nullablesObject

An array for nullable fields



91
92
93
# File 'lib/usps_api/models/shipments_package_description.rb', line 91

def self.nullables
  []
end

.optionalsObject

An array for optional fields



83
84
85
86
87
88
# File 'lib/usps_api/models/shipments_package_description.rb', line 83

def self.optionals
  %w[
    girth
    has_nonstandard_characteristics
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



152
153
154
155
156
157
158
# File 'lib/usps_api/models/shipments_package_description.rb', line 152

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},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



144
145
146
147
148
149
# File 'lib/usps_api/models/shipments_package_description.rb', line 144

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}, additional_properties: #{@additional_properties}>"
end