airthings 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/exe/airthings_mqtt_bridge +84 -0
- data/lib/airthings/api/devices_api.rb +219 -0
- data/lib/airthings/api/locations_api.rb +151 -0
- data/lib/airthings/api_client.rb +389 -0
- data/lib/airthings/api_error.rb +57 -0
- data/lib/airthings/configuration.rb +275 -0
- data/lib/airthings/models/device_sample_response.rb +237 -0
- data/lib/airthings/models/device_simple_response.rb +237 -0
- data/lib/airthings/models/device_type.rb +69 -0
- data/lib/airthings/models/get_device_detailed_response.rb +255 -0
- data/lib/airthings/models/get_devices_response.rb +218 -0
- data/lib/airthings/models/get_location_response.rb +371 -0
- data/lib/airthings/models/get_locations_response.rb +223 -0
- data/lib/airthings/models/local_time.rb +231 -0
- data/lib/airthings/models/location.rb +239 -0
- data/lib/airthings/models/location_simple_response.rb +221 -0
- data/lib/airthings/models/location_usage.rb +231 -0
- data/lib/airthings/models/segment_simple_response.rb +245 -0
- data/lib/airthings/models/sensor_type.rb +144 -0
- data/lib/airthings/models/single_sample_data.rb +416 -0
- data/lib/airthings/models/single_sample_response.rb +216 -0
- data/lib/airthings/oauth2.rb +24 -0
- data/lib/airthings/version.rb +15 -0
- data/lib/airthings.rb +56 -0
- metadata +209 -0
@@ -0,0 +1,218 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# #Airthings API
|
4
|
+
#
|
5
|
+
# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
6
|
+
#
|
7
|
+
# The version of the OpenAPI document: v1
|
8
|
+
#
|
9
|
+
# Generated by: https://openapi-generator.tech
|
10
|
+
# OpenAPI Generator version: 6.2.0
|
11
|
+
#
|
12
|
+
|
13
|
+
require "date"
|
14
|
+
require "time"
|
15
|
+
|
16
|
+
module Airthings
|
17
|
+
class GetDevicesResponse
|
18
|
+
attr_accessor :devices
|
19
|
+
|
20
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
21
|
+
def self.attribute_map
|
22
|
+
{
|
23
|
+
devices: :devices
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns all the JSON keys this model knows about
|
28
|
+
def self.acceptable_attributes
|
29
|
+
attribute_map.values
|
30
|
+
end
|
31
|
+
|
32
|
+
# Attribute type mapping.
|
33
|
+
def self.openapi_types
|
34
|
+
{
|
35
|
+
devices: :"Array<GetDeviceDetailedResponse>"
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# List of attributes with nullable: true
|
40
|
+
def self.openapi_nullable
|
41
|
+
Set.new([])
|
42
|
+
end
|
43
|
+
|
44
|
+
# Initializes the object
|
45
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
46
|
+
def initialize(attributes = {})
|
47
|
+
unless attributes.is_a?(Hash)
|
48
|
+
raise ArgumentError, "The input argument (attributes) must be a hash in `Airthings::GetDevicesResponse` initialize method"
|
49
|
+
end
|
50
|
+
|
51
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
52
|
+
attributes = attributes.each_with_object({}) do |(k, v), h|
|
53
|
+
unless self.class.attribute_map.key?(k.to_sym)
|
54
|
+
raise ArgumentError, "`#{k}` is not a valid attribute in `Airthings::GetDevicesResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
55
|
+
end
|
56
|
+
|
57
|
+
h[k.to_sym] = v
|
58
|
+
end
|
59
|
+
|
60
|
+
if attributes.key?(:devices) && (value = attributes[:devices]).is_a?(Array)
|
61
|
+
self.devices = value
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
66
|
+
# @return Array for valid properties with the reasons
|
67
|
+
def list_invalid_properties
|
68
|
+
[]
|
69
|
+
end
|
70
|
+
|
71
|
+
# Check to see if the all the properties in the model are valid
|
72
|
+
# @return true if the model is valid
|
73
|
+
def valid?
|
74
|
+
true
|
75
|
+
end
|
76
|
+
|
77
|
+
# Checks equality by comparing each attribute.
|
78
|
+
# @param [Object] Object to be compared
|
79
|
+
def ==(other)
|
80
|
+
return true if equal?(other)
|
81
|
+
|
82
|
+
self.class == other.class &&
|
83
|
+
devices == other.devices
|
84
|
+
end
|
85
|
+
|
86
|
+
# @see the `==` method
|
87
|
+
# @param [Object] Object to be compared
|
88
|
+
def eql?(other)
|
89
|
+
self == other
|
90
|
+
end
|
91
|
+
|
92
|
+
# Calculates hash code according to all attributes.
|
93
|
+
# @return [Integer] Hash code
|
94
|
+
def hash
|
95
|
+
[devices].hash
|
96
|
+
end
|
97
|
+
|
98
|
+
# Builds the object from hash
|
99
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
100
|
+
# @return [Object] Returns the model itself
|
101
|
+
def self.build_from_hash(attributes)
|
102
|
+
new.build_from_hash(attributes)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Builds the object from hash
|
106
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
107
|
+
# @return [Object] Returns the model itself
|
108
|
+
def build_from_hash(attributes)
|
109
|
+
return nil unless attributes.is_a?(Hash)
|
110
|
+
|
111
|
+
attributes = attributes.transform_keys(&:to_sym)
|
112
|
+
self.class.openapi_types.each_pair do |key, type|
|
113
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
114
|
+
send("#{key}=", nil)
|
115
|
+
elsif type =~ /\AArray<(.*)>/i
|
116
|
+
# check to ensure the input is an array given that the attribute
|
117
|
+
# is documented as an array but the input is not
|
118
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
119
|
+
send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
120
|
+
end
|
121
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
122
|
+
send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
self
|
127
|
+
end
|
128
|
+
|
129
|
+
# Deserializes the data based on type
|
130
|
+
# @param string type Data type
|
131
|
+
# @param string value Value to be deserialized
|
132
|
+
# @return [Object] Deserialized data
|
133
|
+
def _deserialize(type, value)
|
134
|
+
case type.to_sym
|
135
|
+
when :Time
|
136
|
+
Time.parse(value)
|
137
|
+
when :Date
|
138
|
+
Date.parse(value)
|
139
|
+
when :String
|
140
|
+
value.to_s
|
141
|
+
when :Integer
|
142
|
+
value.to_i
|
143
|
+
when :Float
|
144
|
+
value.to_f
|
145
|
+
when :Boolean
|
146
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
147
|
+
true
|
148
|
+
else
|
149
|
+
false
|
150
|
+
end
|
151
|
+
when :Object
|
152
|
+
# generic object (usually a Hash), return directly
|
153
|
+
value
|
154
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
155
|
+
inner_type = Regexp.last_match[:inner_type]
|
156
|
+
value.map { |v| _deserialize(inner_type, v) }
|
157
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
158
|
+
k_type = Regexp.last_match[:k_type]
|
159
|
+
v_type = Regexp.last_match[:v_type]
|
160
|
+
{}.tap do |hash|
|
161
|
+
value.each do |k, v|
|
162
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
else # model
|
166
|
+
# models (e.g. Pet) or oneOf
|
167
|
+
klass = Airthings.const_get(type)
|
168
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
# Returns the string representation of the object
|
173
|
+
# @return [String] String presentation of the object
|
174
|
+
def to_s
|
175
|
+
to_hash.to_s
|
176
|
+
end
|
177
|
+
|
178
|
+
# to_body is an alias to to_hash (backward compatibility)
|
179
|
+
# @return [Hash] Returns the object in the form of hash
|
180
|
+
def to_body
|
181
|
+
to_hash
|
182
|
+
end
|
183
|
+
|
184
|
+
# Returns the object in the form of hash
|
185
|
+
# @return [Hash] Returns the object in the form of hash
|
186
|
+
def to_hash
|
187
|
+
hash = {}
|
188
|
+
self.class.attribute_map.each_pair do |attr, param|
|
189
|
+
value = send(attr)
|
190
|
+
if value.nil?
|
191
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
192
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
193
|
+
end
|
194
|
+
|
195
|
+
hash[param] = _to_hash(value)
|
196
|
+
end
|
197
|
+
hash
|
198
|
+
end
|
199
|
+
|
200
|
+
# Outputs non-array value in the form of hash
|
201
|
+
# For object, use to_hash. Otherwise, just return the value
|
202
|
+
# @param [Object] value Any valid value
|
203
|
+
# @return [Hash] Returns the value in the form of hash
|
204
|
+
def _to_hash(value)
|
205
|
+
if value.is_a?(Array)
|
206
|
+
value.compact.map { |v| _to_hash(v) }
|
207
|
+
elsif value.is_a?(Hash)
|
208
|
+
{}.tap do |hash|
|
209
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
210
|
+
end
|
211
|
+
elsif value.respond_to? :to_hash
|
212
|
+
value.to_hash
|
213
|
+
else
|
214
|
+
value
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,371 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# #Airthings API
|
4
|
+
#
|
5
|
+
# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
6
|
+
#
|
7
|
+
# The version of the OpenAPI document: v1
|
8
|
+
#
|
9
|
+
# Generated by: https://openapi-generator.tech
|
10
|
+
# OpenAPI Generator version: 6.2.0
|
11
|
+
#
|
12
|
+
|
13
|
+
require "date"
|
14
|
+
require "time"
|
15
|
+
|
16
|
+
module Airthings
|
17
|
+
class GetLocationResponse
|
18
|
+
attr_accessor :id, :name, :labels, :devices, :address, :country_code, :lat, :lng, :building_type, :building_year, :ventilation_type, :timezone, :usage_hours, :building_height, :building_size, :building_volume, :floors
|
19
|
+
|
20
|
+
class EnumAttributeValidator
|
21
|
+
attr_reader :datatype, :allowable_values
|
22
|
+
|
23
|
+
def initialize(datatype, allowable_values)
|
24
|
+
@allowable_values = allowable_values.map do |value|
|
25
|
+
case datatype.to_s
|
26
|
+
when /Integer/i
|
27
|
+
value.to_i
|
28
|
+
when /Float/i
|
29
|
+
value.to_f
|
30
|
+
else
|
31
|
+
value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def valid?(value)
|
37
|
+
!value || allowable_values.include?(value)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
42
|
+
def self.attribute_map
|
43
|
+
{
|
44
|
+
id: :id,
|
45
|
+
name: :name,
|
46
|
+
labels: :labels,
|
47
|
+
devices: :devices,
|
48
|
+
address: :address,
|
49
|
+
country_code: :countryCode,
|
50
|
+
lat: :lat,
|
51
|
+
lng: :lng,
|
52
|
+
building_type: :buildingType,
|
53
|
+
building_year: :buildingYear,
|
54
|
+
ventilation_type: :ventilationType,
|
55
|
+
timezone: :timezone,
|
56
|
+
usage_hours: :usageHours,
|
57
|
+
building_height: :buildingHeight,
|
58
|
+
building_size: :buildingSize,
|
59
|
+
building_volume: :buildingVolume,
|
60
|
+
floors: :floors
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns all the JSON keys this model knows about
|
65
|
+
def self.acceptable_attributes
|
66
|
+
attribute_map.values
|
67
|
+
end
|
68
|
+
|
69
|
+
# Attribute type mapping.
|
70
|
+
def self.openapi_types
|
71
|
+
{
|
72
|
+
id: :String,
|
73
|
+
name: :String,
|
74
|
+
labels: :"Hash<String, String>",
|
75
|
+
devices: :"Array<DeviceSimpleResponse>",
|
76
|
+
address: :String,
|
77
|
+
country_code: :String,
|
78
|
+
lat: :Float,
|
79
|
+
lng: :Float,
|
80
|
+
building_type: :String,
|
81
|
+
building_year: :Integer,
|
82
|
+
ventilation_type: :String,
|
83
|
+
timezone: :String,
|
84
|
+
usage_hours: :"Hash<String, LocationUsage>",
|
85
|
+
building_height: :Float,
|
86
|
+
building_size: :Float,
|
87
|
+
building_volume: :Float,
|
88
|
+
floors: :Integer
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
# List of attributes with nullable: true
|
93
|
+
def self.openapi_nullable
|
94
|
+
Set.new([])
|
95
|
+
end
|
96
|
+
|
97
|
+
# Initializes the object
|
98
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
99
|
+
def initialize(attributes = {})
|
100
|
+
unless attributes.is_a?(Hash)
|
101
|
+
raise ArgumentError, "The input argument (attributes) must be a hash in `Airthings::GetLocationResponse` initialize method"
|
102
|
+
end
|
103
|
+
|
104
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
105
|
+
attributes = attributes.each_with_object({}) do |(k, v), h|
|
106
|
+
unless self.class.attribute_map.key?(k.to_sym)
|
107
|
+
raise ArgumentError, "`#{k}` is not a valid attribute in `Airthings::GetLocationResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
108
|
+
end
|
109
|
+
|
110
|
+
h[k.to_sym] = v
|
111
|
+
end
|
112
|
+
|
113
|
+
self.id = attributes[:id] if attributes.key?(:id)
|
114
|
+
|
115
|
+
self.name = attributes[:name] if attributes.key?(:name)
|
116
|
+
|
117
|
+
if attributes.key?(:labels) && (value = attributes[:labels]).is_a?(Hash)
|
118
|
+
self.labels = value
|
119
|
+
end
|
120
|
+
|
121
|
+
if attributes.key?(:devices) && (value = attributes[:devices]).is_a?(Array)
|
122
|
+
self.devices = value
|
123
|
+
end
|
124
|
+
|
125
|
+
self.address = attributes[:address] if attributes.key?(:address)
|
126
|
+
|
127
|
+
self.country_code = attributes[:country_code] if attributes.key?(:country_code)
|
128
|
+
|
129
|
+
self.lat = attributes[:lat] if attributes.key?(:lat)
|
130
|
+
|
131
|
+
self.lng = attributes[:lng] if attributes.key?(:lng)
|
132
|
+
|
133
|
+
self.building_type = attributes[:building_type] if attributes.key?(:building_type)
|
134
|
+
|
135
|
+
self.building_year = attributes[:building_year] if attributes.key?(:building_year)
|
136
|
+
|
137
|
+
self.ventilation_type = attributes[:ventilation_type] if attributes.key?(:ventilation_type)
|
138
|
+
|
139
|
+
self.timezone = attributes[:timezone] if attributes.key?(:timezone)
|
140
|
+
|
141
|
+
if attributes.key?(:usage_hours) && (value = attributes[:usage_hours]).is_a?(Hash)
|
142
|
+
self.usage_hours = value
|
143
|
+
end
|
144
|
+
|
145
|
+
self.building_height = attributes[:building_height] if attributes.key?(:building_height)
|
146
|
+
|
147
|
+
self.building_size = attributes[:building_size] if attributes.key?(:building_size)
|
148
|
+
|
149
|
+
self.building_volume = attributes[:building_volume] if attributes.key?(:building_volume)
|
150
|
+
|
151
|
+
self.floors = attributes[:floors] if attributes.key?(:floors)
|
152
|
+
end
|
153
|
+
|
154
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
155
|
+
# @return Array for valid properties with the reasons
|
156
|
+
def list_invalid_properties
|
157
|
+
invalid_properties = []
|
158
|
+
invalid_properties.push('invalid value for "id", id cannot be nil.') if @id.nil?
|
159
|
+
|
160
|
+
invalid_properties.push('invalid value for "name", name cannot be nil.') if @name.nil?
|
161
|
+
|
162
|
+
invalid_properties.push('invalid value for "labels", labels cannot be nil.') if @labels.nil?
|
163
|
+
|
164
|
+
invalid_properties.push('invalid value for "devices", devices cannot be nil.') if @devices.nil?
|
165
|
+
|
166
|
+
invalid_properties.push('invalid value for "lat", lat cannot be nil.') if @lat.nil?
|
167
|
+
|
168
|
+
invalid_properties.push('invalid value for "lng", lng cannot be nil.') if @lng.nil?
|
169
|
+
|
170
|
+
invalid_properties
|
171
|
+
end
|
172
|
+
|
173
|
+
# Check to see if the all the properties in the model are valid
|
174
|
+
# @return true if the model is valid
|
175
|
+
def valid?
|
176
|
+
return false if @id.nil?
|
177
|
+
return false if @name.nil?
|
178
|
+
return false if @labels.nil?
|
179
|
+
return false if @devices.nil?
|
180
|
+
return false if @lat.nil?
|
181
|
+
return false if @lng.nil?
|
182
|
+
|
183
|
+
building_type_validator = EnumAttributeValidator.new("String", %w[SCHOOL RESIDENTIAL APARTMENT KINDERGARTEN HEALTHCENTER OFFICE OTHER])
|
184
|
+
return false unless building_type_validator.valid?(@building_type)
|
185
|
+
|
186
|
+
ventilation_type_validator = EnumAttributeValidator.new("String", %w[NATURAL MECHANICAL BALANCED])
|
187
|
+
return false unless ventilation_type_validator.valid?(@ventilation_type)
|
188
|
+
|
189
|
+
true
|
190
|
+
end
|
191
|
+
|
192
|
+
# Custom attribute writer method checking allowed values (enum).
|
193
|
+
# @param [Object] building_type Object to be assigned
|
194
|
+
def building_type=(building_type)
|
195
|
+
validator = EnumAttributeValidator.new("String", %w[SCHOOL RESIDENTIAL APARTMENT KINDERGARTEN HEALTHCENTER OFFICE OTHER])
|
196
|
+
unless validator.valid?(building_type)
|
197
|
+
raise ArgumentError, "invalid value for \"building_type\", must be one of #{validator.allowable_values}."
|
198
|
+
end
|
199
|
+
|
200
|
+
@building_type = building_type
|
201
|
+
end
|
202
|
+
|
203
|
+
# Custom attribute writer method checking allowed values (enum).
|
204
|
+
# @param [Object] ventilation_type Object to be assigned
|
205
|
+
def ventilation_type=(ventilation_type)
|
206
|
+
validator = EnumAttributeValidator.new("String", %w[NATURAL MECHANICAL BALANCED])
|
207
|
+
unless validator.valid?(ventilation_type)
|
208
|
+
raise ArgumentError, "invalid value for \"ventilation_type\", must be one of #{validator.allowable_values}."
|
209
|
+
end
|
210
|
+
|
211
|
+
@ventilation_type = ventilation_type
|
212
|
+
end
|
213
|
+
|
214
|
+
# Checks equality by comparing each attribute.
|
215
|
+
# @param [Object] Object to be compared
|
216
|
+
def ==(other)
|
217
|
+
return true if equal?(other)
|
218
|
+
|
219
|
+
self.class == other.class &&
|
220
|
+
id == other.id &&
|
221
|
+
name == other.name &&
|
222
|
+
labels == other.labels &&
|
223
|
+
devices == other.devices &&
|
224
|
+
address == other.address &&
|
225
|
+
country_code == other.country_code &&
|
226
|
+
lat == other.lat &&
|
227
|
+
lng == other.lng &&
|
228
|
+
building_type == other.building_type &&
|
229
|
+
building_year == other.building_year &&
|
230
|
+
ventilation_type == other.ventilation_type &&
|
231
|
+
timezone == other.timezone &&
|
232
|
+
usage_hours == other.usage_hours &&
|
233
|
+
building_height == other.building_height &&
|
234
|
+
building_size == other.building_size &&
|
235
|
+
building_volume == other.building_volume &&
|
236
|
+
floors == other.floors
|
237
|
+
end
|
238
|
+
|
239
|
+
# @see the `==` method
|
240
|
+
# @param [Object] Object to be compared
|
241
|
+
def eql?(other)
|
242
|
+
self == other
|
243
|
+
end
|
244
|
+
|
245
|
+
# Calculates hash code according to all attributes.
|
246
|
+
# @return [Integer] Hash code
|
247
|
+
def hash
|
248
|
+
[id, name, labels, devices, address, country_code, lat, lng, building_type, building_year, ventilation_type, timezone, usage_hours, building_height, building_size, building_volume, floors].hash
|
249
|
+
end
|
250
|
+
|
251
|
+
# Builds the object from hash
|
252
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
253
|
+
# @return [Object] Returns the model itself
|
254
|
+
def self.build_from_hash(attributes)
|
255
|
+
new.build_from_hash(attributes)
|
256
|
+
end
|
257
|
+
|
258
|
+
# Builds the object from hash
|
259
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
260
|
+
# @return [Object] Returns the model itself
|
261
|
+
def build_from_hash(attributes)
|
262
|
+
return nil unless attributes.is_a?(Hash)
|
263
|
+
|
264
|
+
attributes = attributes.transform_keys(&:to_sym)
|
265
|
+
self.class.openapi_types.each_pair do |key, type|
|
266
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
267
|
+
send("#{key}=", nil)
|
268
|
+
elsif type =~ /\AArray<(.*)>/i
|
269
|
+
# check to ensure the input is an array given that the attribute
|
270
|
+
# is documented as an array but the input is not
|
271
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
272
|
+
send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
273
|
+
end
|
274
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
275
|
+
send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
self
|
280
|
+
end
|
281
|
+
|
282
|
+
# Deserializes the data based on type
|
283
|
+
# @param string type Data type
|
284
|
+
# @param string value Value to be deserialized
|
285
|
+
# @return [Object] Deserialized data
|
286
|
+
def _deserialize(type, value)
|
287
|
+
case type.to_sym
|
288
|
+
when :Time
|
289
|
+
Time.parse(value)
|
290
|
+
when :Date
|
291
|
+
Date.parse(value)
|
292
|
+
when :String
|
293
|
+
value.to_s
|
294
|
+
when :Integer
|
295
|
+
value.to_i
|
296
|
+
when :Float
|
297
|
+
value.to_f
|
298
|
+
when :Boolean
|
299
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
300
|
+
true
|
301
|
+
else
|
302
|
+
false
|
303
|
+
end
|
304
|
+
when :Object
|
305
|
+
# generic object (usually a Hash), return directly
|
306
|
+
value
|
307
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
308
|
+
inner_type = Regexp.last_match[:inner_type]
|
309
|
+
value.map { |v| _deserialize(inner_type, v) }
|
310
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
311
|
+
k_type = Regexp.last_match[:k_type]
|
312
|
+
v_type = Regexp.last_match[:v_type]
|
313
|
+
{}.tap do |hash|
|
314
|
+
value.each do |k, v|
|
315
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
316
|
+
end
|
317
|
+
end
|
318
|
+
else # model
|
319
|
+
# models (e.g. Pet) or oneOf
|
320
|
+
klass = Airthings.const_get(type)
|
321
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
# Returns the string representation of the object
|
326
|
+
# @return [String] String presentation of the object
|
327
|
+
def to_s
|
328
|
+
to_hash.to_s
|
329
|
+
end
|
330
|
+
|
331
|
+
# to_body is an alias to to_hash (backward compatibility)
|
332
|
+
# @return [Hash] Returns the object in the form of hash
|
333
|
+
def to_body
|
334
|
+
to_hash
|
335
|
+
end
|
336
|
+
|
337
|
+
# Returns the object in the form of hash
|
338
|
+
# @return [Hash] Returns the object in the form of hash
|
339
|
+
def to_hash
|
340
|
+
hash = {}
|
341
|
+
self.class.attribute_map.each_pair do |attr, param|
|
342
|
+
value = send(attr)
|
343
|
+
if value.nil?
|
344
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
345
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
346
|
+
end
|
347
|
+
|
348
|
+
hash[param] = _to_hash(value)
|
349
|
+
end
|
350
|
+
hash
|
351
|
+
end
|
352
|
+
|
353
|
+
# Outputs non-array value in the form of hash
|
354
|
+
# For object, use to_hash. Otherwise, just return the value
|
355
|
+
# @param [Object] value Any valid value
|
356
|
+
# @return [Hash] Returns the value in the form of hash
|
357
|
+
def _to_hash(value)
|
358
|
+
if value.is_a?(Array)
|
359
|
+
value.compact.map { |v| _to_hash(v) }
|
360
|
+
elsif value.is_a?(Hash)
|
361
|
+
{}.tap do |hash|
|
362
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
363
|
+
end
|
364
|
+
elsif value.respond_to? :to_hash
|
365
|
+
value.to_hash
|
366
|
+
else
|
367
|
+
value
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|