Class: UspsApi::Records

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

Overview

List of Records returned from found Old and New Address Information

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(change_of_address_information:, old_address_information:, new_address_information: SKIP, additional_properties: nil) ⇒ Records

Returns a new instance of Records.



45
46
47
48
49
50
51
52
53
54
# File 'lib/usps_api/models/records.rb', line 45

def initialize(change_of_address_information:, old_address_information:,
               new_address_information: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @change_of_address_information = change_of_address_information
  @old_address_information = old_address_information
  @new_address_information = new_address_information unless new_address_information == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#change_of_address_informationChangeOfAddress

Information pertaining to the Change of address

Returns:



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

def change_of_address_information
  @change_of_address_information
end

#new_address_informationAddressInformation

The Address Information of the request user.

Returns:



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

def new_address_information
  @new_address_information
end

#old_address_informationAddressInformation

The Address Information of the request user.

Returns:



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

def old_address_information
  @old_address_information
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/usps_api/models/records.rb', line 57

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  if hash['changeOfAddressInformation']
    change_of_address_information = ChangeOfAddress.from_hash(hash['changeOfAddressInformation'])
  end
  old_address_information = AddressInformation.from_hash(hash['oldAddressInformation']) if
    hash['oldAddressInformation']
  new_address_information = AddressInformation.from_hash(hash['newAddressInformation']) if
    hash['newAddressInformation']

  # 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.
  Records.new(change_of_address_information: change_of_address_information,
              old_address_information: old_address_information,
              new_address_information: new_address_information,
              additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



25
26
27
28
29
30
31
# File 'lib/usps_api/models/records.rb', line 25

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['change_of_address_information'] = 'changeOfAddressInformation'
  @_hash['old_address_information'] = 'oldAddressInformation'
  @_hash['new_address_information'] = 'newAddressInformation'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



34
35
36
37
38
# File 'lib/usps_api/models/records.rb', line 34

def self.optionals
  %w[
    new_address_information
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



92
93
94
95
96
97
# File 'lib/usps_api/models/records.rb', line 92

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} change_of_address_information: #{@change_of_address_information.inspect},"\
  " old_address_information: #{@old_address_information.inspect}, new_address_information:"\
  " #{@new_address_information.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



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

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} change_of_address_information: #{@change_of_address_information},"\
  " old_address_information: #{@old_address_information}, new_address_information:"\
  " #{@new_address_information}, additional_properties: #{@additional_properties}>"
end