Class: UspsApi::DomesticPackageRequest

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

Overview

Destination address of the recipient. Used in pricing as the destination ZIP Code™.

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(to_address:, from_address:, package_description:, image_info: SKIP, sender_address: SKIP, return_address: SKIP, customs_form: SKIP) ⇒ DomesticPackageRequest

Returns a new instance of DomesticPackageRequest.



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/usps_api/models/domestic_package_request.rb', line 98

def initialize(to_address:, from_address:, package_description:,
               image_info: SKIP, sender_address: SKIP, return_address: SKIP,
               customs_form: SKIP)
  @image_info = image_info unless image_info == SKIP
  @to_address = to_address
  @from_address = from_address
  @sender_address = sender_address unless sender_address == SKIP
  @return_address = return_address unless return_address == SKIP
  @package_description = package_description
  @customs_form = customs_form unless customs_form == SKIP
end

Instance Attribute Details

#customs_formLabelsCustomsForm

Domestic Customs Form

Returns:



68
69
70
# File 'lib/usps_api/models/domestic_package_request.rb', line 68

def customs_form
  @customs_form
end

#from_addressInternationalLabelsDomesticLabelAddress

The address where the package is being shipped from. The ZIP Code™ in the ‘fromAddress` object is used to calculate pricing. Notes:

  • The First and Last Name or Firm Name are always required.

  • If the ‘returnAddress` is not provided, the `fromAddress` will be used

as the ‘returnAddress`.

  • If the ‘returnLabel` field is set to “true”, then the `fromAddress` ZIP

Plus 4 is looked up by the API, unless the ‘ignoreBadAddress` field is set to true or the address cannot be found. If `ignoreBadAddress` field is true then ZIP Plus 4 is required.



42
43
44
# File 'lib/usps_api/models/domestic_package_request.rb', line 42

def from_address
  @from_address
end

#image_infoImageInfo1

Image Information

Returns:



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

def image_info
  @image_info
end

#package_descriptionObject

Package description

Returns:

  • (Object)


64
65
66
# File 'lib/usps_api/models/domestic_package_request.rb', line 64

def package_description
  @package_description
end

#return_addressInternationalLabelsDomesticLabelAddress

The address where the package should be returned to if it is deemed undeliverable or returned to sender. This address will be printed in the return address block of the label. Note:

  • The First and Last Name or Firm Name are always required.



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

def return_address
  @return_address
end

#sender_addressInternationalLabelsDomesticLabelSenderAddress

The address of the business involved. The senderAddress can be different from the fromAddress when the business address is not where the package is being shipped from. Notes:

  • The First and Last Name or Firm Name are always required.

  • ‘senderAddress` is required when the `shipperVisibilityMethod` field is

set to ‘SENDER_INFORMATION`.



52
53
54
# File 'lib/usps_api/models/domestic_package_request.rb', line 52

def sender_address
  @sender_address
end

#to_addressDomesticLabelToAddress

The address where the package is being shipped to. The ZIP Code™ in the ‘toAddress` object is used to calculate pricing. Notes:

  • The First and Last Name or Firm are always required.

  • Address elements ‘streetAddress`, `city`, `state`, `ZIPCode` are

required unless a parcel locker is requested in which case the ‘facilityId`, Recipient Email, First and Last Name or Firm are required.

  • If the ‘holdForPickup` field is set to `true` then the `toAddress`

object ‘facilityID`, `email`, and `phone` fields as well as the `fromAddress` object `firstName`, `lastName`, `email`, and `phone` fields are required.



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

def to_address
  @to_address
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/usps_api/models/domestic_package_request.rb', line 111

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  to_address = DomesticLabelToAddress.from_hash(hash['toAddress']) if hash['toAddress']
  from_address = InternationalLabelsDomesticLabelAddress.from_hash(hash['fromAddress']) if
    hash['fromAddress']
  package_description = hash.key?('packageDescription') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:DomesticPackageRequestPackageDescription), hash['packageDescription']
  ) : nil
  image_info = ImageInfo1.from_hash(hash['imageInfo']) if hash['imageInfo']
  if hash['senderAddress']
    sender_address = InternationalLabelsDomesticLabelSenderAddress.from_hash(hash['senderAddress'])
  end
  return_address = InternationalLabelsDomesticLabelAddress.from_hash(hash['returnAddress']) if
    hash['returnAddress']
  customs_form = LabelsCustomsForm.from_hash(hash['customsForm']) if hash['customsForm']

  # Create object from extracted values.
  DomesticPackageRequest.new(to_address: to_address,
                             from_address: from_address,
                             package_description: package_description,
                             image_info: image_info,
                             sender_address: sender_address,
                             return_address: return_address,
                             customs_form: customs_form)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['image_info'] = 'imageInfo'
  @_hash['to_address'] = 'toAddress'
  @_hash['from_address'] = 'fromAddress'
  @_hash['sender_address'] = 'senderAddress'
  @_hash['return_address'] = 'returnAddress'
  @_hash['package_description'] = 'packageDescription'
  @_hash['customs_form'] = 'customsForm'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



84
85
86
87
88
89
90
91
# File 'lib/usps_api/models/domestic_package_request.rb', line 84

def self.optionals
  %w[
    image_info
    sender_address
    return_address
    customs_form
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



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

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.to_address,
                            ->(val) { DomesticLabelToAddress.validate(val) },
                            is_model_hash: true) and
        APIHelper.valid_type?(value.from_address,
                              ->(val) { InternationalLabelsDomesticLabelAddress.validate(val) },
                              is_model_hash: true) and
        UnionTypeLookUp.get(:DomesticPackageRequestPackageDescription)
                       .validate(value.package_description)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['toAddress'],
                          ->(val) { DomesticLabelToAddress.validate(val) },
                          is_model_hash: true) and
      APIHelper.valid_type?(value['fromAddress'],
                            ->(val) { InternationalLabelsDomesticLabelAddress.validate(val) },
                            is_model_hash: true) and
      UnionTypeLookUp.get(:DomesticPackageRequestPackageDescription)
                     .validate(value['packageDescription'])
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



178
179
180
181
182
183
184
# File 'lib/usps_api/models/domestic_package_request.rb', line 178

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} image_info: #{@image_info.inspect}, to_address: #{@to_address.inspect},"\
  " from_address: #{@from_address.inspect}, sender_address: #{@sender_address.inspect},"\
  " return_address: #{@return_address.inspect}, package_description:"\
  " #{@package_description.inspect}, customs_form: #{@customs_form.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



170
171
172
173
174
175
# File 'lib/usps_api/models/domestic_package_request.rb', line 170

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} image_info: #{@image_info}, to_address: #{@to_address}, from_address:"\
  " #{@from_address}, sender_address: #{@sender_address}, return_address: #{@return_address},"\
  " package_description: #{@package_description}, customs_form: #{@customs_form}>"
end