Class: UspsApi::ContainersContainer

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

Overview

containers

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(sort_type:, destination_entry_facility_type:, destination_zip_code:, origin_address:, mailer_name:, processing_category:, mid:, container_id: SKIP, image_info: SKIP, allow_manifested_labels: SKIP, tracking_numbers: SKIP, container_topology: ContainerTopology::NESTED, warnings: SKIP, mailing_date: SKIP) ⇒ ContainersContainer

Returns a new instance of ContainersContainer.



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/usps_api/models/containers_container.rb', line 136

def initialize(sort_type:, destination_entry_facility_type:,
               destination_zip_code:, origin_address:, mailer_name:,
               processing_category:, mid:, container_id: SKIP,
               image_info: SKIP, allow_manifested_labels: SKIP,
               tracking_numbers: SKIP,
               container_topology: ContainerTopology::NESTED,
               warnings: SKIP, mailing_date: SKIP)
  @container_id = container_id unless container_id == SKIP
  @image_info = image_info unless image_info == SKIP
  @allow_manifested_labels = allow_manifested_labels unless allow_manifested_labels == SKIP
  @sort_type = sort_type
  @tracking_numbers = tracking_numbers unless tracking_numbers == SKIP
  @destination_entry_facility_type = destination_entry_facility_type
  @destination_zip_code = destination_zip_code
  @mail_class = 'PARCEL_SELECT'
  @origin_address = origin_address
  @mailer_name = mailer_name
  @processing_category = processing_category
  @container_topology = container_topology unless container_topology == SKIP
  @mid = mid
  @warnings = warnings unless warnings == SKIP
  @mailing_date = mailing_date unless mailing_date == SKIP
end

Instance Attribute Details

#allow_manifested_labelsTrueClass | FalseClass

Allow labels that have manifested to be added to the container.

Returns:

  • (TrueClass | FalseClass)


22
23
24
# File 'lib/usps_api/models/containers_container.rb', line 22

def allow_manifested_labels
  @allow_manifested_labels
end

#container_idString

Unique identifier for a container

Returns:

  • (String)


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

def container_id
  @container_id
end

#container_topologyContainerTopology

The type of packages that will be nested to the container. ‘MIXED` is only available for `DESTINATION_DELIVERY_UNIT` and `DESTINATION_SERVICE_HUB` containers. Note:

  • ‘NON_MACHINABLE` is deprecated and will convert to `NONSTANDARD` as of

01/19/2025.

Returns:



78
79
80
# File 'lib/usps_api/models/containers_container.rb', line 78

def container_topology
  @container_topology
end

#destination_entry_facility_typeDestinationEntryFacilityType

The facility type where the container will be sent to. Note:

  • Effective 01/18/2026: ‘DESTINATION_NETWORK_DISTRIBUTION_CENTER` with

‘PARCEL_SELECT` is no longer eligible.

  • Effective 01/18/2026: (NSA Only)

‘DESTINATION_REGIONAL_PROCESSING_DISTRIBUTION_CENTER` with `PARCEL_SELECT` is available as an option.



40
41
42
# File 'lib/usps_api/models/containers_container.rb', line 40

def destination_entry_facility_type
  @destination_entry_facility_type
end

#destination_zip_codeString

A 5-digit ZIP Code serviced by the ‘destinationEntryFacilityType` the container is being sent to. This is used to identify the Destination Entry Facility.

Returns:

  • (String)


46
47
48
# File 'lib/usps_api/models/containers_container.rb', line 46

def destination_zip_code
  @destination_zip_code
end

#image_infoContainersImageInfo

Additional details used to determine how to generate the label image.

Returns:



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

def image_info
  @image_info
end

#mail_classString (readonly)

The mail class of the items enclosed in the container. The default value is ‘PARCEL_SELECT`

Returns:

  • (String)


51
52
53
# File 'lib/usps_api/models/containers_container.rb', line 51

def mail_class
  @mail_class
end

#mailer_nameString

Name of the firm/business that is shipping the container.

Returns:

  • (String)


60
61
62
# File 'lib/usps_api/models/containers_container.rb', line 60

def mailer_name
  @mailer_name
end

#mailing_dateObject

The mailing date for when the container will be shipped, when included in the request all packages nested to the container will be updated to align with the associated mailingDate. The mailing date may be today plus 0 to 7 days in advance. If it is not provided it will be set as today.

Returns:

  • (Object)


94
95
96
# File 'lib/usps_api/models/containers_container.rb', line 94

def mailing_date
  @mailing_date
end

#midString

Mailer Identifier to use to create the container barcode.

Returns:

  • (String)


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

def mid
  @mid
end

#origin_addressAddressesDomesticAddress

The mail class of the items enclosed in the container. The default value is ‘PARCEL_SELECT`



56
57
58
# File 'lib/usps_api/models/containers_container.rb', line 56

def origin_address
  @origin_address
end

#processing_categoryProcessingCategory2

The type of packages that will be nested to the container. ‘MIXED` is only available for `DESTINATION_DELIVERY_UNIT` and `DESTINATION_SERVICE_HUB` containers. Note:

  • ‘NON_MACHINABLE` is deprecated and will convert to `NONSTANDARD` as of

01/19/2025.

Returns:



69
70
71
# File 'lib/usps_api/models/containers_container.rb', line 69

def processing_category
  @processing_category
end

#sort_typeSortType

The sort type of the container being shipped.

Returns:



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

def sort_type
  @sort_type
end

#tracking_numbersArray[String]

List of tracking numbers for the packages that are in the container.

Returns:

  • (Array[String])


30
31
32
# File 'lib/usps_api/models/containers_container.rb', line 30

def tracking_numbers
  @tracking_numbers
end

#warningsArray[ContainersContainerWarnings]

Mailer Identifier to use to create the container barcode.

Returns:



86
87
88
# File 'lib/usps_api/models/containers_container.rb', line 86

def warnings
  @warnings
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/usps_api/models/containers_container.rb', line 161

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  sort_type = hash.key?('sortType') ? hash['sortType'] : nil
  destination_entry_facility_type =
    hash.key?('destinationEntryFacilityType') ? hash['destinationEntryFacilityType'] : nil
  destination_zip_code =
    hash.key?('destinationZIPCode') ? hash['destinationZIPCode'] : nil
  origin_address = AddressesDomesticAddress.from_hash(hash['originAddress']) if
    hash['originAddress']
  mailer_name = hash.key?('mailerName') ? hash['mailerName'] : nil
  processing_category =
    hash.key?('processingCategory') ? hash['processingCategory'] : nil
  mid = hash.key?('MID') ? hash['MID'] : nil
  container_id = hash.key?('containerID') ? hash['containerID'] : SKIP
  image_info = ContainersImageInfo.from_hash(hash['imageInfo']) if hash['imageInfo']
  allow_manifested_labels =
    hash.key?('allowManifestedLabels') ? hash['allowManifestedLabels'] : SKIP
  tracking_numbers =
    hash.key?('trackingNumbers') ? hash['trackingNumbers'] : SKIP
  container_topology =
    hash['containerTopology'] ||= ContainerTopology::NESTED
  # Parameter is an array, so we need to iterate through it
  warnings = nil
  unless hash['warnings'].nil?
    warnings = []
    hash['warnings'].each do |structure|
      warnings << (ContainersContainerWarnings.from_hash(structure) if structure)
    end
  end

  warnings = SKIP unless hash.key?('warnings')
  mailing_date = hash.key?('mailingDate') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:ContainersContainerMailingDate), hash['mailingDate']
  ) : SKIP

  # Create object from extracted values.
  ContainersContainer.new(sort_type: sort_type,
                          destination_entry_facility_type: destination_entry_facility_type,
                          destination_zip_code: destination_zip_code,
                          origin_address: origin_address,
                          mailer_name: mailer_name,
                          processing_category: processing_category,
                          mid: mid,
                          container_id: container_id,
                          image_info: image_info,
                          allow_manifested_labels: allow_manifested_labels,
                          tracking_numbers: tracking_numbers,
                          container_topology: container_topology,
                          warnings: warnings,
                          mailing_date: mailing_date)
end

.namesObject

A mapping from model property names to API property names.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/usps_api/models/containers_container.rb', line 97

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['container_id'] = 'containerID'
  @_hash['image_info'] = 'imageInfo'
  @_hash['allow_manifested_labels'] = 'allowManifestedLabels'
  @_hash['sort_type'] = 'sortType'
  @_hash['tracking_numbers'] = 'trackingNumbers'
  @_hash['destination_entry_facility_type'] =
    'destinationEntryFacilityType'
  @_hash['destination_zip_code'] = 'destinationZIPCode'
  @_hash['mail_class'] = 'mailClass'
  @_hash['origin_address'] = 'originAddress'
  @_hash['mailer_name'] = 'mailerName'
  @_hash['processing_category'] = 'processingCategory'
  @_hash['container_topology'] = 'containerTopology'
  @_hash['mid'] = 'MID'
  @_hash['warnings'] = 'warnings'
  @_hash['mailing_date'] = 'mailingDate'
  @_hash
end

.nullablesObject

An array for nullable fields



132
133
134
# File 'lib/usps_api/models/containers_container.rb', line 132

def self.nullables
  []
end

.optionalsObject

An array for optional fields



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/usps_api/models/containers_container.rb', line 119

def self.optionals
  %w[
    container_id
    image_info
    allow_manifested_labels
    tracking_numbers
    container_topology
    warnings
    mailing_date
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



223
224
225
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
264
265
266
267
# File 'lib/usps_api/models/containers_container.rb', line 223

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.sort_type,
                            ->(val) { SortType.validate(val) }) and
        APIHelper.valid_type?(value.destination_entry_facility_type,
                              ->(val) { DestinationEntryFacilityType.validate(val) }) and
        APIHelper.valid_type?(value.destination_zip_code,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.mail_class,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.origin_address,
                              ->(val) { AddressesDomesticAddress.validate(val) },
                              is_model_hash: true) and
        APIHelper.valid_type?(value.mailer_name,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.processing_category,
                              ->(val) { ProcessingCategory2.validate(val) }) and
        APIHelper.valid_type?(value.mid,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['sortType'],
                          ->(val) { SortType.validate(val) }) and
      APIHelper.valid_type?(value['destinationEntryFacilityType'],
                            ->(val) { DestinationEntryFacilityType.validate(val) }) and
      APIHelper.valid_type?(value['destinationZIPCode'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['mailClass'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['originAddress'],
                            ->(val) { AddressesDomesticAddress.validate(val) },
                            is_model_hash: true) and
      APIHelper.valid_type?(value['mailerName'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['processingCategory'],
                            ->(val) { ProcessingCategory2.validate(val) }) and
      APIHelper.valid_type?(value['MID'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/usps_api/models/containers_container.rb', line 283

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} container_id: #{@container_id.inspect}, image_info: #{@image_info.inspect},"\
  " allow_manifested_labels: #{@allow_manifested_labels.inspect}, sort_type:"\
  " #{@sort_type.inspect}, tracking_numbers: #{@tracking_numbers.inspect},"\
  " destination_entry_facility_type: #{@destination_entry_facility_type.inspect},"\
  " destination_zip_code: #{@destination_zip_code.inspect}, mail_class:"\
  " #{@mail_class.inspect}, origin_address: #{@origin_address.inspect}, mailer_name:"\
  " #{@mailer_name.inspect}, processing_category: #{@processing_category.inspect},"\
  " container_topology: #{@container_topology.inspect}, mid: #{@mid.inspect}, warnings:"\
  " #{@warnings.inspect}, mailing_date: #{@mailing_date.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



270
271
272
273
274
275
276
277
278
279
280
# File 'lib/usps_api/models/containers_container.rb', line 270

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} container_id: #{@container_id}, image_info: #{@image_info},"\
  " allow_manifested_labels: #{@allow_manifested_labels}, sort_type: #{@sort_type},"\
  " tracking_numbers: #{@tracking_numbers}, destination_entry_facility_type:"\
  " #{@destination_entry_facility_type}, destination_zip_code: #{@destination_zip_code},"\
  " mail_class: #{@mail_class}, origin_address: #{@origin_address}, mailer_name:"\
  " #{@mailer_name}, processing_category: #{@processing_category}, container_topology:"\
  " #{@container_topology}, mid: #{@mid}, warnings: #{@warnings}, mailing_date:"\
  " #{@mailing_date}>"
end

#to_union_type_mailing_dateObject



215
216
217
218
219
# File 'lib/usps_api/models/containers_container.rb', line 215

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