Class: UspsApi::RecordsResponse

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

Overview

The Returned List of records

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(number_of_months: SKIP, record_count: SKIP, coa_beyond_months_count: SKIP, coa_match_count: SKIP, coa_no_match_count: SKIP, coa_found_count: SKIP, coa_not_allowed_match_count: SKIP, records: SKIP, additional_properties: nil) ⇒ RecordsResponse

Returns a new instance of RecordsResponse.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/usps_api/models/records_response.rb', line 81

def initialize(number_of_months: SKIP, record_count: SKIP,
               coa_beyond_months_count: SKIP, coa_match_count: SKIP,
               coa_no_match_count: SKIP, coa_found_count: SKIP,
               coa_not_allowed_match_count: SKIP, records: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @number_of_months = number_of_months unless number_of_months == SKIP
  @record_count = record_count unless record_count == SKIP
  @coa_beyond_months_count = coa_beyond_months_count unless coa_beyond_months_count == SKIP
  @coa_match_count = coa_match_count unless coa_match_count == SKIP
  @coa_no_match_count = coa_no_match_count unless coa_no_match_count == SKIP
  @coa_found_count = coa_found_count unless coa_found_count == SKIP
  unless coa_not_allowed_match_count == SKIP
    @coa_not_allowed_match_count =
      coa_not_allowed_match_count
  end
  @records = records unless records == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#coa_beyond_months_countInteger

Number of Records matched with a new address but outside requested number of Months.

Returns:

  • (Integer)


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

def coa_beyond_months_count
  @coa_beyond_months_count
end

#coa_found_countInteger

Number of Records matched but no new address was available (e.g., MLNA, BCNO, new side wouldn’t +4 code).

Returns:

  • (Integer)


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

def coa_found_count
  @coa_found_count
end

#coa_match_countInteger

Number of Records returning a new address (within requested number of Months).

Returns:

  • (Integer)


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

def coa_match_count
  @coa_match_count
end

#coa_no_match_countInteger

Number of Records with no COA found on file.

Returns:

  • (Integer)


32
33
34
# File 'lib/usps_api/models/records_response.rb', line 32

def coa_no_match_count
  @coa_no_match_count
end

#coa_not_allowed_match_countInteger

Number of Records returned for COA match not allowed (e.g., middle name mismatch, conflicting directions, etc).

Returns:

  • (Integer)


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

def coa_not_allowed_match_count
  @coa_not_allowed_match_count
end

#number_of_monthsInteger

Number of months passed for MED for Change of Address

Returns:

  • (Integer)


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

def number_of_months
  @number_of_months
end

#record_countInteger

Number of Records in records Array returned to customer.

Returns:

  • (Integer)


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

def record_count
  @record_count
end

#recordsArray[Records]

Contains the records

Returns:



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

def records
  @records
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



104
105
106
107
108
109
110
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
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/usps_api/models/records_response.rb', line 104

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  number_of_months =
    hash.key?('numberOfMonths') ? hash['numberOfMonths'] : SKIP
  record_count = hash.key?('recordCount') ? hash['recordCount'] : SKIP
  coa_beyond_months_count =
    hash.key?('COABeyondMonthsCount') ? hash['COABeyondMonthsCount'] : SKIP
  coa_match_count =
    hash.key?('COAMatchCount') ? hash['COAMatchCount'] : SKIP
  coa_no_match_count =
    hash.key?('COANoMatchCount') ? hash['COANoMatchCount'] : SKIP
  coa_found_count =
    hash.key?('COAFoundCount') ? hash['COAFoundCount'] : SKIP
  coa_not_allowed_match_count =
    hash.key?('COANotAllowedMatchCount') ? hash['COANotAllowedMatchCount'] : SKIP
  # Parameter is an array, so we need to iterate through it
  records = nil
  unless hash['records'].nil?
    records = []
    hash['records'].each do |structure|
      records << (Records.from_hash(structure) if structure)
    end
  end

  records = SKIP unless hash.key?('records')

  # 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.
  RecordsResponse.new(number_of_months: number_of_months,
                      record_count: record_count,
                      coa_beyond_months_count: coa_beyond_months_count,
                      coa_match_count: coa_match_count,
                      coa_no_match_count: coa_no_match_count,
                      coa_found_count: coa_found_count,
                      coa_not_allowed_match_count: coa_not_allowed_match_count,
                      records: records,
                      additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/usps_api/models/records_response.rb', line 49

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['number_of_months'] = 'numberOfMonths'
  @_hash['record_count'] = 'recordCount'
  @_hash['coa_beyond_months_count'] = 'COABeyondMonthsCount'
  @_hash['coa_match_count'] = 'COAMatchCount'
  @_hash['coa_no_match_count'] = 'COANoMatchCount'
  @_hash['coa_found_count'] = 'COAFoundCount'
  @_hash['coa_not_allowed_match_count'] = 'COANotAllowedMatchCount'
  @_hash['records'] = 'records'
  @_hash
end

.nullablesObject

An array for nullable fields



77
78
79
# File 'lib/usps_api/models/records_response.rb', line 77

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    number_of_months
    record_count
    coa_beyond_months_count
    coa_match_count
    coa_no_match_count
    coa_found_count
    coa_not_allowed_match_count
    records
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



162
163
164
165
166
167
168
169
170
# File 'lib/usps_api/models/records_response.rb', line 162

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} number_of_months: #{@number_of_months.inspect}, record_count:"\
  " #{@record_count.inspect}, coa_beyond_months_count: #{@coa_beyond_months_count.inspect},"\
  " coa_match_count: #{@coa_match_count.inspect}, coa_no_match_count:"\
  " #{@coa_no_match_count.inspect}, coa_found_count: #{@coa_found_count.inspect},"\
  " coa_not_allowed_match_count: #{@coa_not_allowed_match_count.inspect}, records:"\
  " #{@records.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



152
153
154
155
156
157
158
159
# File 'lib/usps_api/models/records_response.rb', line 152

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} number_of_months: #{@number_of_months}, record_count: #{@record_count},"\
  " coa_beyond_months_count: #{@coa_beyond_months_count}, coa_match_count:"\
  " #{@coa_match_count}, coa_no_match_count: #{@coa_no_match_count}, coa_found_count:"\
  " #{@coa_found_count}, coa_not_allowed_match_count: #{@coa_not_allowed_match_count},"\
  " records: #{@records}, additional_properties: #{@additional_properties}>"
end