Class: UspsApi::ScanFormsScanForm1

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

Overview

Information required to generate a SCAN Form.

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(mailing_date:, entry_facility_zip_code:, destination_entry_facility_type:, shipment:, from_address:, image_info: SKIP, form: Form::ENUM_5630, image_type: DeprecatedImageType::PDF, label_type: DeprecatedLabelType::ENUM_85X11LABEL, overwrite_mailing_date: false) ⇒ ScanFormsScanForm1

Returns a new instance of ScanFormsScanForm1.



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 122

def initialize(mailing_date:, entry_facility_zip_code:,
               destination_entry_facility_type:, shipment:, from_address:,
               image_info: SKIP, form: Form::ENUM_5630,
               image_type: DeprecatedImageType::PDF,
               label_type: DeprecatedLabelType::ENUM_85X11LABEL,
               overwrite_mailing_date: false)
  @image_info = image_info unless image_info == SKIP
  @form = form unless form == SKIP
  @image_type = image_type unless image_type == SKIP
  @label_type = label_type unless label_type == SKIP
  @mailing_date = mailing_date
  @overwrite_mailing_date = overwrite_mailing_date unless overwrite_mailing_date == SKIP
  @entry_facility_zip_code = entry_facility_zip_code
  @destination_entry_facility_type = destination_entry_facility_type
  @shipment = shipment
  @from_address = from_address
end

Instance Attribute Details

#destination_entry_facility_typeDestinationEntryFacilityType1

Specifies the type of facility the mailpieces are being entered at. All mailpieces on a single SCAN Form must be entered at the same facility and facility type. A value of ‘NONE` cannot be used when shipping Parcel Select or USPS Connect Local items.



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

def destination_entry_facility_type
  @destination_entry_facility_type
end

#entry_facility_zip_codeString

The ZIP Code™ of the destination entry facility.

Returns:

  • (String)


49
50
51
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 49

def entry_facility_zip_code
  @entry_facility_zip_code
end

#formForm

This field has been deprecated. The type of SCAN Form will be dictated by the ‘imageInfo.labelType` requested.

Returns:



19
20
21
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 19

def form
  @form
end

#from_addressScanFormAddress

Location of the Shipper. Only domestic addresses are supported for this API. Note:

  • The ‘firstName` and `lastName` or `firm` are always required.

Returns:



87
88
89
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 87

def from_address
  @from_address
end

#image_infoScanFormsImageInfo

Characteristics of the type of SCAN Form being requested.

Returns:



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

def image_info
  @image_info
end

#image_typeDeprecatedImageType

This field has been deprecated. ‘imageType` can be updated through `imageInfo.imageType`.

Returns:



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

def image_type
  @image_type
end

#label_typeDeprecatedLabelType

This field has been deprecated. ‘labelType` can be updated through `imageInfo.labelType`.

Returns:



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

def label_type
  @label_type
end

#mailing_dateDate

The date of mailing. The date when the items in the associated SCAN Form will be dropped off at the Entry Facility. All labels associated to the SCAN Form must have the same ‘mailingDate`, unless the `overwriteMailingDate` option is selected.

Returns:

  • (Date)


36
37
38
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 36

def mailing_date
  @mailing_date
end

#overwrite_mailing_dateTrueClass | FalseClass

Label Mailing Date Overwrite option. If this value is set to ‘true`, the mailing dates for the packages contained within the SCAN Form will be overwritten with the `mailingDate` value provided in the SCAN Form request. If this value is set to `false`, the mailing dates for the packages contained within the SCAN Form will not be updated and will use the values initially provided in the Label request.

Returns:

  • (TrueClass | FalseClass)


45
46
47
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 45

def overwrite_mailing_date
  @overwrite_mailing_date
end

#shipmentObject

Method used to generate the SCAN Form. SCAN Forms can be created by providing a list of tracking numbers to be added to the SCAN Form or by automatically pulling eligible labels in via the MID or Manifest MID. **Label Eligibility Rules**:

  • All labels on a single SCAN Form must have the same

‘entryFacilityZIPCode` and `destinationEntryFacilityType`.

  • All labels on a single SCAN Form must have the same ‘mailingDate`. If

unmanifested labels with different mail dates are to be added to the same SCAN Form, use ‘overwriteMailingDate` value of `true` to update the label mail dates.

  • Labels can only be added to a SCAN Form prior to the label being

manifested. For manifest scheduling, refer to the time tables listed in the Domestic Labels and International Labels APIs.

  • Labels that have already been added to a SCAN Form cannot be added to a

second SCAN Form.

  • Labels that were created with the ‘imageType` `LABEL_BROKER` cannot be

added to a SCAN Form.

  • Labels that were created for Smart/Parcel Locker delivery cannot be

added to a SCAN Form.

  • Labels that were created using Extra Service Code ‘415` (USPS Label

Delivery) cannot be added to a SCAN Form.

Returns:

  • (Object)


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

def shipment
  @shipment
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 141

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  mailing_date = hash.key?('mailingDate') ? hash['mailingDate'] : nil
  entry_facility_zip_code =
    hash.key?('entryFacilityZIPCode') ? hash['entryFacilityZIPCode'] : nil
  destination_entry_facility_type =
    hash.key?('destinationEntryFacilityType') ? hash['destinationEntryFacilityType'] : nil
  shipment = hash.key?('shipment') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:ScanFormsScanForm1Shipment), hash['shipment']
  ) : nil
  from_address = ScanFormAddress.from_hash(hash['fromAddress']) if hash['fromAddress']
  image_info = ScanFormsImageInfo.from_hash(hash['imageInfo']) if hash['imageInfo']
  form = hash['form'] ||= Form::ENUM_5630
  image_type = hash['imageType'] ||= DeprecatedImageType::PDF
  label_type = hash['labelType'] ||= DeprecatedLabelType::ENUM_85X11LABEL
  overwrite_mailing_date = hash['overwriteMailingDate'] ||= false

  # Create object from extracted values.
  ScanFormsScanForm1.new(mailing_date: mailing_date,
                         entry_facility_zip_code: entry_facility_zip_code,
                         destination_entry_facility_type: destination_entry_facility_type,
                         shipment: shipment,
                         from_address: from_address,
                         image_info: image_info,
                         form: form,
                         image_type: image_type,
                         label_type: label_type,
                         overwrite_mailing_date: overwrite_mailing_date)
end

.namesObject

A mapping from model property names to API property names.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 90

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['image_info'] = 'imageInfo'
  @_hash['form'] = 'form'
  @_hash['image_type'] = 'imageType'
  @_hash['label_type'] = 'labelType'
  @_hash['mailing_date'] = 'mailingDate'
  @_hash['overwrite_mailing_date'] = 'overwriteMailingDate'
  @_hash['entry_facility_zip_code'] = 'entryFacilityZIPCode'
  @_hash['destination_entry_facility_type'] =
    'destinationEntryFacilityType'
  @_hash['shipment'] = 'shipment'
  @_hash['from_address'] = 'fromAddress'
  @_hash
end

.nullablesObject

An array for nullable fields



118
119
120
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 118

def self.nullables
  []
end

.optionalsObject

An array for optional fields



107
108
109
110
111
112
113
114
115
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 107

def self.optionals
  %w[
    image_info
    form
    image_type
    label_type
    overwrite_mailing_date
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 175

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.mailing_date,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.entry_facility_zip_code,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.destination_entry_facility_type,
                              ->(val) { DestinationEntryFacilityType1.validate(val) }) and
        UnionTypeLookUp.get(:ScanFormsScanForm1Shipment)
                       .validate(value.shipment) and
        APIHelper.valid_type?(value.from_address,
                              ->(val) { ScanFormAddress.validate(val) },
                              is_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['mailingDate'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['entryFacilityZIPCode'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['destinationEntryFacilityType'],
                            ->(val) { DestinationEntryFacilityType1.validate(val) }) and
      UnionTypeLookUp.get(:ScanFormsScanForm1Shipment)
                     .validate(value['shipment']) and
      APIHelper.valid_type?(value['fromAddress'],
                            ->(val) { ScanFormAddress.validate(val) },
                            is_model_hash: true)
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



220
221
222
223
224
225
226
227
228
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 220

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} image_info: #{@image_info.inspect}, form: #{@form.inspect}, image_type:"\
  " #{@image_type.inspect}, label_type: #{@label_type.inspect}, mailing_date:"\
  " #{@mailing_date.inspect}, overwrite_mailing_date: #{@overwrite_mailing_date.inspect},"\
  " entry_facility_zip_code: #{@entry_facility_zip_code.inspect},"\
  " destination_entry_facility_type: #{@destination_entry_facility_type.inspect}, shipment:"\
  " #{@shipment.inspect}, from_address: #{@from_address.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



210
211
212
213
214
215
216
217
# File 'lib/usps_api/models/scan_forms_scan_form1.rb', line 210

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} image_info: #{@image_info}, form: #{@form}, image_type: #{@image_type},"\
  " label_type: #{@label_type}, mailing_date: #{@mailing_date}, overwrite_mailing_date:"\
  " #{@overwrite_mailing_date}, entry_facility_zip_code: #{@entry_facility_zip_code},"\
  " destination_entry_facility_type: #{@destination_entry_facility_type}, shipment:"\
  " #{@shipment}, from_address: #{@from_address}>"
end