first-class-postcodes 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +11 -0
- data/README.md +74 -0
- data/Rakefile +9 -0
- data/first-class-postcodes.gemspec +33 -0
- data/lib/first-class-postcodes.rb +36 -0
- data/lib/first-class-postcodes/api/api_api.rb +66 -0
- data/lib/first-class-postcodes/api/data_api.rb +217 -0
- data/lib/first-class-postcodes/api_client.rb +374 -0
- data/lib/first-class-postcodes/api_error.rb +45 -0
- data/lib/first-class-postcodes/configuration.rb +236 -0
- data/lib/first-class-postcodes/models/address.rb +292 -0
- data/lib/first-class-postcodes/models/error.rb +220 -0
- data/lib/first-class-postcodes/models/error_raw.rb +215 -0
- data/lib/first-class-postcodes/models/error_raw_gateway.rb +206 -0
- data/lib/first-class-postcodes/models/point.rb +205 -0
- data/lib/first-class-postcodes/models/position.rb +242 -0
- data/lib/first-class-postcodes/models/typeahead.rb +221 -0
- data/lib/first-class-postcodes/version.rb +3 -0
- data/spec/api/api_api_spec.rb +46 -0
- data/spec/api/data_api_spec.rb +74 -0
- data/spec/api_client_spec.rb +214 -0
- data/spec/configuration_spec.rb +28 -0
- data/spec/models/address_spec.rb +71 -0
- data/spec/models/error_raw_gateway_spec.rb +35 -0
- data/spec/models/error_raw_spec.rb +41 -0
- data/spec/models/error_spec.rb +41 -0
- data/spec/models/point_spec.rb +35 -0
- data/spec/models/position_spec.rb +59 -0
- data/spec/models/typeahead_spec.rb +41 -0
- data/spec/spec_helper.rb +129 -0
- metadata +267 -0
@@ -0,0 +1,292 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module FCP
|
4
|
+
# Represents an address, including all the numbers associated with it.
|
5
|
+
class Address
|
6
|
+
# The full name of the street.
|
7
|
+
attr_accessor :street
|
8
|
+
|
9
|
+
# All the house, flat and building numbers that belong to the postcode.
|
10
|
+
attr_accessor :numbers
|
11
|
+
|
12
|
+
# City or national locality component, if applicable.
|
13
|
+
attr_accessor :city
|
14
|
+
|
15
|
+
# The postal district corresponding to the postcode.
|
16
|
+
attr_accessor :district
|
17
|
+
|
18
|
+
# The national state, province, prefecture, or region component, if applicable.
|
19
|
+
attr_accessor :county
|
20
|
+
|
21
|
+
# Zip or postal code for the location, if applicable.
|
22
|
+
attr_accessor :postcode
|
23
|
+
|
24
|
+
# The name of the country, ie. \"United Kingdom\"
|
25
|
+
attr_accessor :country
|
26
|
+
|
27
|
+
attr_accessor :position
|
28
|
+
|
29
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
30
|
+
def self.attribute_map
|
31
|
+
{
|
32
|
+
:'street' => :'street',
|
33
|
+
:'numbers' => :'numbers',
|
34
|
+
:'city' => :'city',
|
35
|
+
:'district' => :'district',
|
36
|
+
:'county' => :'county',
|
37
|
+
:'postcode' => :'postcode',
|
38
|
+
:'country' => :'country',
|
39
|
+
:'position' => :'position'
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
# Attribute type mapping.
|
44
|
+
def self.openapi_types
|
45
|
+
{
|
46
|
+
:'street' => :'String',
|
47
|
+
:'numbers' => :'Array<String>',
|
48
|
+
:'city' => :'String',
|
49
|
+
:'district' => :'String',
|
50
|
+
:'county' => :'String',
|
51
|
+
:'postcode' => :'String',
|
52
|
+
:'country' => :'String',
|
53
|
+
:'position' => :'Position'
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
# Initializes the object
|
58
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
59
|
+
def initialize(attributes = {})
|
60
|
+
if (!attributes.is_a?(Hash))
|
61
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `FCP::Address` initialize method"
|
62
|
+
end
|
63
|
+
|
64
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
65
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
66
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
67
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `FCP::Address`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
68
|
+
end
|
69
|
+
h[k.to_sym] = v
|
70
|
+
}
|
71
|
+
|
72
|
+
if attributes.key?(:'street')
|
73
|
+
self.street = attributes[:'street']
|
74
|
+
end
|
75
|
+
|
76
|
+
if attributes.key?(:'numbers')
|
77
|
+
if (value = attributes[:'numbers']).is_a?(Array)
|
78
|
+
self.numbers = value
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
if attributes.key?(:'city')
|
83
|
+
self.city = attributes[:'city']
|
84
|
+
end
|
85
|
+
|
86
|
+
if attributes.key?(:'district')
|
87
|
+
self.district = attributes[:'district']
|
88
|
+
end
|
89
|
+
|
90
|
+
if attributes.key?(:'county')
|
91
|
+
self.county = attributes[:'county']
|
92
|
+
end
|
93
|
+
|
94
|
+
if attributes.key?(:'postcode')
|
95
|
+
self.postcode = attributes[:'postcode']
|
96
|
+
end
|
97
|
+
|
98
|
+
if attributes.key?(:'country')
|
99
|
+
self.country = attributes[:'country']
|
100
|
+
end
|
101
|
+
|
102
|
+
if attributes.key?(:'position')
|
103
|
+
self.position = attributes[:'position']
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
108
|
+
# @return Array for valid properties with the reasons
|
109
|
+
def list_invalid_properties
|
110
|
+
invalid_properties = Array.new
|
111
|
+
if @street.nil?
|
112
|
+
invalid_properties.push('invalid value for "street", street cannot be nil.')
|
113
|
+
end
|
114
|
+
|
115
|
+
if @city.nil?
|
116
|
+
invalid_properties.push('invalid value for "city", city cannot be nil.')
|
117
|
+
end
|
118
|
+
|
119
|
+
if @district.nil?
|
120
|
+
invalid_properties.push('invalid value for "district", district cannot be nil.')
|
121
|
+
end
|
122
|
+
|
123
|
+
if @county.nil?
|
124
|
+
invalid_properties.push('invalid value for "county", county cannot be nil.')
|
125
|
+
end
|
126
|
+
|
127
|
+
if @postcode.nil?
|
128
|
+
invalid_properties.push('invalid value for "postcode", postcode cannot be nil.')
|
129
|
+
end
|
130
|
+
|
131
|
+
if @country.nil?
|
132
|
+
invalid_properties.push('invalid value for "country", country cannot be nil.')
|
133
|
+
end
|
134
|
+
|
135
|
+
if @position.nil?
|
136
|
+
invalid_properties.push('invalid value for "position", position cannot be nil.')
|
137
|
+
end
|
138
|
+
|
139
|
+
invalid_properties
|
140
|
+
end
|
141
|
+
|
142
|
+
# Check to see if the all the properties in the model are valid
|
143
|
+
# @return true if the model is valid
|
144
|
+
def valid?
|
145
|
+
return false if @street.nil?
|
146
|
+
return false if @city.nil?
|
147
|
+
return false if @district.nil?
|
148
|
+
return false if @county.nil?
|
149
|
+
return false if @postcode.nil?
|
150
|
+
return false if @country.nil?
|
151
|
+
return false if @position.nil?
|
152
|
+
true
|
153
|
+
end
|
154
|
+
|
155
|
+
# Checks equality by comparing each attribute.
|
156
|
+
# @param [Object] Object to be compared
|
157
|
+
def ==(o)
|
158
|
+
return true if self.equal?(o)
|
159
|
+
self.class == o.class &&
|
160
|
+
street == o.street &&
|
161
|
+
numbers == o.numbers &&
|
162
|
+
city == o.city &&
|
163
|
+
district == o.district &&
|
164
|
+
county == o.county &&
|
165
|
+
postcode == o.postcode &&
|
166
|
+
country == o.country &&
|
167
|
+
position == o.position
|
168
|
+
end
|
169
|
+
|
170
|
+
# @see the `==` method
|
171
|
+
# @param [Object] Object to be compared
|
172
|
+
def eql?(o)
|
173
|
+
self == o
|
174
|
+
end
|
175
|
+
|
176
|
+
# Calculates hash code according to all attributes.
|
177
|
+
# @return [Integer] Hash code
|
178
|
+
def hash
|
179
|
+
[street, numbers, city, district, county, postcode, country, position].hash
|
180
|
+
end
|
181
|
+
|
182
|
+
# Builds the object from hash
|
183
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
184
|
+
# @return [Object] Returns the model itself
|
185
|
+
def self.build_from_hash(attributes)
|
186
|
+
new.build_from_hash(attributes)
|
187
|
+
end
|
188
|
+
|
189
|
+
# Builds the object from hash
|
190
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
191
|
+
# @return [Object] Returns the model itself
|
192
|
+
def build_from_hash(attributes)
|
193
|
+
return nil unless attributes.is_a?(Hash)
|
194
|
+
self.class.openapi_types.each_pair do |key, type|
|
195
|
+
if type =~ /\AArray<(.*)>/i
|
196
|
+
# check to ensure the input is an array given that the attribute
|
197
|
+
# is documented as an array but the input is not
|
198
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
199
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
200
|
+
end
|
201
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
202
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
203
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
204
|
+
end
|
205
|
+
|
206
|
+
self
|
207
|
+
end
|
208
|
+
|
209
|
+
# Deserializes the data based on type
|
210
|
+
# @param string type Data type
|
211
|
+
# @param string value Value to be deserialized
|
212
|
+
# @return [Object] Deserialized data
|
213
|
+
def _deserialize(type, value)
|
214
|
+
case type.to_sym
|
215
|
+
when :DateTime
|
216
|
+
DateTime.parse(value)
|
217
|
+
when :Date
|
218
|
+
Date.parse(value)
|
219
|
+
when :String
|
220
|
+
value.to_s
|
221
|
+
when :Integer
|
222
|
+
value.to_i
|
223
|
+
when :Float
|
224
|
+
value.to_f
|
225
|
+
when :Boolean
|
226
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
227
|
+
true
|
228
|
+
else
|
229
|
+
false
|
230
|
+
end
|
231
|
+
when :Object
|
232
|
+
# generic object (usually a Hash), return directly
|
233
|
+
value
|
234
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
235
|
+
inner_type = Regexp.last_match[:inner_type]
|
236
|
+
value.map { |v| _deserialize(inner_type, v) }
|
237
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
238
|
+
k_type = Regexp.last_match[:k_type]
|
239
|
+
v_type = Regexp.last_match[:v_type]
|
240
|
+
{}.tap do |hash|
|
241
|
+
value.each do |k, v|
|
242
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
else # model
|
246
|
+
FCP.const_get(type).build_from_hash(value)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
# Returns the string representation of the object
|
251
|
+
# @return [String] String presentation of the object
|
252
|
+
def to_s
|
253
|
+
to_hash.to_s
|
254
|
+
end
|
255
|
+
|
256
|
+
# to_body is an alias to to_hash (backward compatibility)
|
257
|
+
# @return [Hash] Returns the object in the form of hash
|
258
|
+
def to_body
|
259
|
+
to_hash
|
260
|
+
end
|
261
|
+
|
262
|
+
# Returns the object in the form of hash
|
263
|
+
# @return [Hash] Returns the object in the form of hash
|
264
|
+
def to_hash
|
265
|
+
hash = {}
|
266
|
+
self.class.attribute_map.each_pair do |attr, param|
|
267
|
+
value = self.send(attr)
|
268
|
+
next if value.nil?
|
269
|
+
hash[param] = _to_hash(value)
|
270
|
+
end
|
271
|
+
hash
|
272
|
+
end
|
273
|
+
|
274
|
+
# Outputs non-array value in the form of hash
|
275
|
+
# For object, use to_hash. Otherwise, just return the value
|
276
|
+
# @param [Object] value Any valid value
|
277
|
+
# @return [Hash] Returns the value in the form of hash
|
278
|
+
def _to_hash(value)
|
279
|
+
if value.is_a?(Array)
|
280
|
+
value.compact.map { |v| _to_hash(v) }
|
281
|
+
elsif value.is_a?(Hash)
|
282
|
+
{}.tap do |hash|
|
283
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
284
|
+
end
|
285
|
+
elsif value.respond_to? :to_hash
|
286
|
+
value.to_hash
|
287
|
+
else
|
288
|
+
value
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module FCP
|
4
|
+
# An error object, containing a software-level error type and custom error message. The original low-level error is contained inside the __raw property key.
|
5
|
+
class Error
|
6
|
+
# A custom, high-level message that can be exposed to an end-user.
|
7
|
+
attr_accessor :message
|
8
|
+
|
9
|
+
# A software-level error type. Multiple low-level error types are subsumed by fewer error types, with this property.
|
10
|
+
attr_accessor :type
|
11
|
+
|
12
|
+
attr_accessor :__raw
|
13
|
+
|
14
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
15
|
+
def self.attribute_map
|
16
|
+
{
|
17
|
+
:'message' => :'message',
|
18
|
+
:'type' => :'type',
|
19
|
+
:'__raw' => :'__raw'
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
# Attribute type mapping.
|
24
|
+
def self.openapi_types
|
25
|
+
{
|
26
|
+
:'message' => :'String',
|
27
|
+
:'type' => :'String',
|
28
|
+
:'__raw' => :'ErrorRaw'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Initializes the object
|
33
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
34
|
+
def initialize(attributes = {})
|
35
|
+
if (!attributes.is_a?(Hash))
|
36
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `FCP::Error` initialize method"
|
37
|
+
end
|
38
|
+
|
39
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
40
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
41
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
42
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `FCP::Error`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
43
|
+
end
|
44
|
+
h[k.to_sym] = v
|
45
|
+
}
|
46
|
+
|
47
|
+
if attributes.key?(:'message')
|
48
|
+
self.message = attributes[:'message']
|
49
|
+
end
|
50
|
+
|
51
|
+
if attributes.key?(:'type')
|
52
|
+
self.type = attributes[:'type']
|
53
|
+
end
|
54
|
+
|
55
|
+
if attributes.key?(:'__raw')
|
56
|
+
self.__raw = attributes[:'__raw']
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
61
|
+
# @return Array for valid properties with the reasons
|
62
|
+
def list_invalid_properties
|
63
|
+
invalid_properties = Array.new
|
64
|
+
if @message.nil?
|
65
|
+
invalid_properties.push('invalid value for "message", message cannot be nil.')
|
66
|
+
end
|
67
|
+
|
68
|
+
if @type.nil?
|
69
|
+
invalid_properties.push('invalid value for "type", type cannot be nil.')
|
70
|
+
end
|
71
|
+
|
72
|
+
if @__raw.nil?
|
73
|
+
invalid_properties.push('invalid value for "__raw", __raw cannot be nil.')
|
74
|
+
end
|
75
|
+
|
76
|
+
invalid_properties
|
77
|
+
end
|
78
|
+
|
79
|
+
# Check to see if the all the properties in the model are valid
|
80
|
+
# @return true if the model is valid
|
81
|
+
def valid?
|
82
|
+
return false if @message.nil?
|
83
|
+
return false if @type.nil?
|
84
|
+
return false if @__raw.nil?
|
85
|
+
true
|
86
|
+
end
|
87
|
+
|
88
|
+
# Checks equality by comparing each attribute.
|
89
|
+
# @param [Object] Object to be compared
|
90
|
+
def ==(o)
|
91
|
+
return true if self.equal?(o)
|
92
|
+
self.class == o.class &&
|
93
|
+
message == o.message &&
|
94
|
+
type == o.type &&
|
95
|
+
__raw == o.__raw
|
96
|
+
end
|
97
|
+
|
98
|
+
# @see the `==` method
|
99
|
+
# @param [Object] Object to be compared
|
100
|
+
def eql?(o)
|
101
|
+
self == o
|
102
|
+
end
|
103
|
+
|
104
|
+
# Calculates hash code according to all attributes.
|
105
|
+
# @return [Integer] Hash code
|
106
|
+
def hash
|
107
|
+
[message, type, __raw].hash
|
108
|
+
end
|
109
|
+
|
110
|
+
# Builds the object from hash
|
111
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
112
|
+
# @return [Object] Returns the model itself
|
113
|
+
def self.build_from_hash(attributes)
|
114
|
+
new.build_from_hash(attributes)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Builds the object from hash
|
118
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
119
|
+
# @return [Object] Returns the model itself
|
120
|
+
def build_from_hash(attributes)
|
121
|
+
return nil unless attributes.is_a?(Hash)
|
122
|
+
self.class.openapi_types.each_pair do |key, type|
|
123
|
+
if type =~ /\AArray<(.*)>/i
|
124
|
+
# check to ensure the input is an array given that the attribute
|
125
|
+
# is documented as an array but the input is not
|
126
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
127
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
128
|
+
end
|
129
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
130
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
131
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
132
|
+
end
|
133
|
+
|
134
|
+
self
|
135
|
+
end
|
136
|
+
|
137
|
+
# Deserializes the data based on type
|
138
|
+
# @param string type Data type
|
139
|
+
# @param string value Value to be deserialized
|
140
|
+
# @return [Object] Deserialized data
|
141
|
+
def _deserialize(type, value)
|
142
|
+
case type.to_sym
|
143
|
+
when :DateTime
|
144
|
+
DateTime.parse(value)
|
145
|
+
when :Date
|
146
|
+
Date.parse(value)
|
147
|
+
when :String
|
148
|
+
value.to_s
|
149
|
+
when :Integer
|
150
|
+
value.to_i
|
151
|
+
when :Float
|
152
|
+
value.to_f
|
153
|
+
when :Boolean
|
154
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
155
|
+
true
|
156
|
+
else
|
157
|
+
false
|
158
|
+
end
|
159
|
+
when :Object
|
160
|
+
# generic object (usually a Hash), return directly
|
161
|
+
value
|
162
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
163
|
+
inner_type = Regexp.last_match[:inner_type]
|
164
|
+
value.map { |v| _deserialize(inner_type, v) }
|
165
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
166
|
+
k_type = Regexp.last_match[:k_type]
|
167
|
+
v_type = Regexp.last_match[:v_type]
|
168
|
+
{}.tap do |hash|
|
169
|
+
value.each do |k, v|
|
170
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
else # model
|
174
|
+
FCP.const_get(type).build_from_hash(value)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# Returns the string representation of the object
|
179
|
+
# @return [String] String presentation of the object
|
180
|
+
def to_s
|
181
|
+
to_hash.to_s
|
182
|
+
end
|
183
|
+
|
184
|
+
# to_body is an alias to to_hash (backward compatibility)
|
185
|
+
# @return [Hash] Returns the object in the form of hash
|
186
|
+
def to_body
|
187
|
+
to_hash
|
188
|
+
end
|
189
|
+
|
190
|
+
# Returns the object in the form of hash
|
191
|
+
# @return [Hash] Returns the object in the form of hash
|
192
|
+
def to_hash
|
193
|
+
hash = {}
|
194
|
+
self.class.attribute_map.each_pair do |attr, param|
|
195
|
+
value = self.send(attr)
|
196
|
+
next if value.nil?
|
197
|
+
hash[param] = _to_hash(value)
|
198
|
+
end
|
199
|
+
hash
|
200
|
+
end
|
201
|
+
|
202
|
+
# Outputs non-array value in the form of hash
|
203
|
+
# For object, use to_hash. Otherwise, just return the value
|
204
|
+
# @param [Object] value Any valid value
|
205
|
+
# @return [Hash] Returns the value in the form of hash
|
206
|
+
def _to_hash(value)
|
207
|
+
if value.is_a?(Array)
|
208
|
+
value.compact.map { |v| _to_hash(v) }
|
209
|
+
elsif value.is_a?(Hash)
|
210
|
+
{}.tap do |hash|
|
211
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
212
|
+
end
|
213
|
+
elsif value.respond_to? :to_hash
|
214
|
+
value.to_hash
|
215
|
+
else
|
216
|
+
value
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|