Class: UspsApi::QrCodeResponse

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

Overview

QR Code and associated meta data

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(tracking_number:, zip_code:, qr_code:, pickup_code: SKIP, locker_removal_date: SKIP, po_name: SKIP, street_address: SKIP, city: SKIP, state: SKIP, pozip_code: SKIP, pozip_code_plus4: SKIP, additional_properties: nil) ⇒ QrCodeResponse

Returns a new instance of QrCodeResponse.



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

def initialize(tracking_number:, zip_code:, qr_code:, pickup_code: SKIP,
               locker_removal_date: SKIP, po_name: SKIP,
               street_address: SKIP, city: SKIP, state: SKIP,
               pozip_code: SKIP, pozip_code_plus4: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @tracking_number = tracking_number
  @zip_code = zip_code
  @pickup_code = pickup_code unless pickup_code == SKIP
  @qr_code = qr_code
  @locker_removal_date = locker_removal_date unless locker_removal_date == SKIP
  @po_name = po_name unless po_name == SKIP
  @street_address = street_address unless street_address == SKIP
  @city = city unless city == SKIP
  @state = state unless state == SKIP
  @pozip_code = pozip_code unless pozip_code == SKIP
  @pozip_code_plus4 = pozip_code_plus4 unless pozip_code_plus4 == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#cityString

The Post Office city.

Returns:

  • (String)


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

def city
  @city
end

#locker_removal_dateDate

The last day to pick up the package before it is removed from the USPS Locker.

Returns:

  • (Date)


33
34
35
# File 'lib/usps_api/models/qr_code_response.rb', line 33

def locker_removal_date
  @locker_removal_date
end

#pickup_codeString

The one-time, six-digit access code to retrieve the package from a USPS Locker.

Returns:

  • (String)


23
24
25
# File 'lib/usps_api/models/qr_code_response.rb', line 23

def pickup_code
  @pickup_code
end

#po_nameString

The name of the Post Office where the USPS Locker is located.

Returns:

  • (String)


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

def po_name
  @po_name
end

#pozip_codeString

The Post Office 5-digit ZIP Code.

Returns:

  • (String)


53
54
55
# File 'lib/usps_api/models/qr_code_response.rb', line 53

def pozip_code
  @pozip_code
end

#pozip_code_plus4String

The Post Office ZIP+4 Code.

Returns:

  • (String)


57
58
59
# File 'lib/usps_api/models/qr_code_response.rb', line 57

def pozip_code_plus4
  @pozip_code_plus4
end

#qr_codeString

The QR code to retrieve the package from a USPS Locker, in Base64 encoded format.

Returns:

  • (String)


28
29
30
# File 'lib/usps_api/models/qr_code_response.rb', line 28

def qr_code
  @qr_code
end

#stateString

The Post Office state.

Returns:

  • (String)


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

def state
  @state
end

#street_addressString

The Post Office street address.

Returns:

  • (String)


41
42
43
# File 'lib/usps_api/models/qr_code_response.rb', line 41

def street_address
  @street_address
end

#tracking_numberString

The package tracking Number.

Returns:

  • (String)


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

def tracking_number
  @tracking_number
end

#zip_codeString

The 11-digit delivery ZIP Code.

Returns:

  • (String)


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

def zip_code
  @zip_code
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/usps_api/models/qr_code_response.rb', line 118

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  tracking_number =
    hash.key?('trackingNumber') ? hash['trackingNumber'] : nil
  zip_code = hash.key?('ZIPCode') ? hash['ZIPCode'] : nil
  qr_code = hash.key?('QRCode') ? hash['QRCode'] : nil
  pickup_code = hash.key?('pickupCode') ? hash['pickupCode'] : SKIP
  locker_removal_date =
    hash.key?('lockerRemovalDate') ? hash['lockerRemovalDate'] : SKIP
  po_name = hash.key?('POName') ? hash['POName'] : SKIP
  street_address = hash.key?('streetAddress') ? hash['streetAddress'] : SKIP
  city = hash.key?('city') ? hash['city'] : SKIP
  state = hash.key?('state') ? hash['state'] : SKIP
  pozip_code = hash.key?('POZIPCode') ? hash['POZIPCode'] : SKIP
  pozip_code_plus4 =
    hash.key?('POZIPCodePlus4') ? hash['POZIPCodePlus4'] : 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.
  QrCodeResponse.new(tracking_number: tracking_number,
                     zip_code: zip_code,
                     qr_code: qr_code,
                     pickup_code: pickup_code,
                     locker_removal_date: locker_removal_date,
                     po_name: po_name,
                     street_address: street_address,
                     city: city,
                     state: state,
                     pozip_code: pozip_code,
                     pozip_code_plus4: pozip_code_plus4,
                     additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/usps_api/models/qr_code_response.rb', line 60

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['tracking_number'] = 'trackingNumber'
  @_hash['zip_code'] = 'ZIPCode'
  @_hash['pickup_code'] = 'pickupCode'
  @_hash['qr_code'] = 'QRCode'
  @_hash['locker_removal_date'] = 'lockerRemovalDate'
  @_hash['po_name'] = 'POName'
  @_hash['street_address'] = 'streetAddress'
  @_hash['city'] = 'city'
  @_hash['state'] = 'state'
  @_hash['pozip_code'] = 'POZIPCode'
  @_hash['pozip_code_plus4'] = 'POZIPCodePlus4'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/usps_api/models/qr_code_response.rb', line 77

def self.optionals
  %w[
    pickup_code
    locker_removal_date
    po_name
    street_address
    city
    state
    pozip_code
    pozip_code_plus4
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (QrCodeResponse | Hash)

    value against the validation is performed.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/usps_api/models/qr_code_response.rb', line 161

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.tracking_number,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.zip_code,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.qr_code,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['trackingNumber'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['ZIPCode'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['QRCode'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



196
197
198
199
200
201
202
203
204
# File 'lib/usps_api/models/qr_code_response.rb', line 196

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} tracking_number: #{@tracking_number.inspect}, zip_code:"\
  " #{@zip_code.inspect}, pickup_code: #{@pickup_code.inspect}, qr_code: #{@qr_code.inspect},"\
  " locker_removal_date: #{@locker_removal_date.inspect}, po_name: #{@po_name.inspect},"\
  " street_address: #{@street_address.inspect}, city: #{@city.inspect}, state:"\
  " #{@state.inspect}, pozip_code: #{@pozip_code.inspect}, pozip_code_plus4:"\
  " #{@pozip_code_plus4.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



186
187
188
189
190
191
192
193
# File 'lib/usps_api/models/qr_code_response.rb', line 186

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} tracking_number: #{@tracking_number}, zip_code: #{@zip_code}, pickup_code:"\
  " #{@pickup_code}, qr_code: #{@qr_code}, locker_removal_date: #{@locker_removal_date},"\
  " po_name: #{@po_name}, street_address: #{@street_address}, city: #{@city}, state:"\
  " #{@state}, pozip_code: #{@pozip_code}, pozip_code_plus4: #{@pozip_code_plus4},"\
  " additional_properties: #{@additional_properties}>"
end