airthings 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,275 @@
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
+ module Airthings
14
+ class Configuration
15
+ # Defines url scheme
16
+ attr_accessor :scheme
17
+
18
+ # Defines url host
19
+ attr_accessor :host
20
+
21
+ # Defines url base path
22
+ attr_accessor :base_path
23
+
24
+ # Define server configuration index
25
+ attr_accessor :server_index
26
+
27
+ # Define server operation configuration index
28
+ attr_accessor :server_operation_index
29
+
30
+ # Default server variables
31
+ attr_accessor :server_variables
32
+
33
+ # Default server operation variables
34
+ attr_accessor :server_operation_variables
35
+
36
+ # Defines API keys used with API Key authentications.
37
+ #
38
+ # @return [Hash] key: parameter name, value: parameter value (API key)
39
+ #
40
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
41
+ # config.api_key['api_key'] = 'xxx'
42
+ attr_accessor :api_key
43
+
44
+ # Defines API key prefixes used with API Key authentications.
45
+ #
46
+ # @return [Hash] key: parameter name, value: API key prefix
47
+ #
48
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
49
+ # config.api_key_prefix['api_key'] = 'Token'
50
+ attr_accessor :api_key_prefix
51
+
52
+ # Defines the username used with HTTP basic authentication.
53
+ #
54
+ # @return [String]
55
+ attr_accessor :username
56
+
57
+ # Defines the password used with HTTP basic authentication.
58
+ #
59
+ # @return [String]
60
+ attr_accessor :password
61
+
62
+ # Defines the access token (Bearer) used with OAuth2.
63
+ attr_accessor :access_token
64
+
65
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
66
+ # details will be logged with `logger.debug` (see the `logger` attribute).
67
+ # Default to false.
68
+ #
69
+ # @return [true, false]
70
+ attr_accessor :debugging
71
+
72
+ # Defines the logger used for debugging.
73
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
74
+ #
75
+ # @return [#debug]
76
+ attr_accessor :logger
77
+
78
+ # Defines the temporary folder to store downloaded files
79
+ # (for API endpoints that have file response).
80
+ # Default to use `Tempfile`.
81
+ #
82
+ # @return [String]
83
+ attr_accessor :temp_folder_path
84
+
85
+ # The time limit for HTTP request in seconds.
86
+ # Default to 0 (never times out).
87
+ attr_accessor :timeout
88
+
89
+ # Set this to false to skip client side validation in the operation.
90
+ # Default to true.
91
+ # @return [true, false]
92
+ attr_accessor :client_side_validation
93
+
94
+ ### TLS/SSL setting
95
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
96
+ # Default to true.
97
+ #
98
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
99
+ #
100
+ # @return [true, false]
101
+ attr_accessor :verify_ssl
102
+
103
+ ### TLS/SSL setting
104
+ # Set this to false to skip verifying SSL host name
105
+ # Default to true.
106
+ #
107
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
108
+ #
109
+ # @return [true, false]
110
+ attr_accessor :verify_ssl_host
111
+
112
+ ### TLS/SSL setting
113
+ # Set this to customize the certificate file to verify the peer.
114
+ #
115
+ # @return [String] the path to the certificate file
116
+ #
117
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
118
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
119
+ attr_accessor :ssl_ca_cert
120
+
121
+ ### TLS/SSL setting
122
+ # Client certificate file (for client certificate)
123
+ attr_accessor :cert_file
124
+
125
+ ### TLS/SSL setting
126
+ # Client private key file (for client certificate)
127
+ attr_accessor :key_file
128
+
129
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
130
+ # Default to nil.
131
+ #
132
+ # @see The params_encoding option of Ethon. Related source code:
133
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
134
+ attr_accessor :params_encoding
135
+
136
+ attr_accessor :inject_format, :force_ending_format
137
+
138
+ def initialize
139
+ @scheme = "https"
140
+ @host = "ext-api.airthings.com"
141
+ @base_path = "/v1"
142
+ @server_index = 0
143
+ @server_operation_index = {}
144
+ @server_variables = {}
145
+ @server_operation_variables = {}
146
+ @api_key = {}
147
+ @api_key_prefix = {}
148
+ @client_side_validation = true
149
+ @verify_ssl = true
150
+ @verify_ssl_host = true
151
+ @cert_file = nil
152
+ @key_file = nil
153
+ @timeout = 0
154
+ @params_encoding = nil
155
+ @debugging = false
156
+ @inject_format = false
157
+ @force_ending_format = false
158
+ @logger = defined?(Rails) ? Rails.logger : Logger.new($stdout)
159
+
160
+ yield(self) if block_given?
161
+ end
162
+
163
+ # The default Configuration object.
164
+ def self.default
165
+ @@default ||= Configuration.new
166
+ end
167
+
168
+ def configure
169
+ yield(self) if block_given?
170
+ end
171
+
172
+ def scheme=(scheme)
173
+ # remove :// from scheme
174
+ @scheme = scheme.sub(%r{://}, "")
175
+ end
176
+
177
+ def host=(host)
178
+ # remove http(s):// and anything after a slash
179
+ @host = host.sub(%r{https?://}, "").split("/").first
180
+ end
181
+
182
+ def base_path=(base_path)
183
+ # Add leading and trailing slashes to base_path
184
+ @base_path = "/#{base_path}".squeeze("/")
185
+ @base_path = "" if @base_path == "/"
186
+ end
187
+
188
+ # Returns base URL for specified operation based on server settings
189
+ def base_url(operation = nil)
190
+ index = server_operation_index.fetch(operation, server_index)
191
+ return "#{scheme}://#{[host, base_path].join("/").squeeze("/")}".sub(%r{/+\z}, "") if index.nil?
192
+
193
+ server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
194
+ end
195
+
196
+ # Gets API key (with prefix if set).
197
+ # @param [String] param_name the parameter name of API key auth
198
+ def api_key_with_prefix(param_name, param_alias = nil)
199
+ key = @api_key[param_name]
200
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
201
+ if @api_key_prefix[param_name]
202
+ "#{@api_key_prefix[param_name]} #{key}"
203
+ else
204
+ key
205
+ end
206
+ end
207
+
208
+ # Gets Basic Auth token string
209
+ def basic_auth_token
210
+ "Basic #{["#{username}:#{password}"].pack("m").delete("\r\n")}"
211
+ end
212
+
213
+ # Returns Auth Settings hash for api client.
214
+ def auth_settings
215
+ {
216
+ "AirthingsAccounts" =>
217
+ {
218
+ type: "oauth2",
219
+ in: "header",
220
+ key: "Authorization",
221
+ value: "Bearer #{access_token}"
222
+ }
223
+ }
224
+ end
225
+
226
+ # Returns an array of Server setting
227
+ def server_settings
228
+ [
229
+ {
230
+ url: "https://ext-api.airthings.com/v1",
231
+ description: "No description provided"
232
+ }
233
+ ]
234
+ end
235
+
236
+ def operation_server_settings
237
+ {
238
+ }
239
+ end
240
+
241
+ # Returns URL based on server settings
242
+ #
243
+ # @param index array index of the server settings
244
+ # @param variables hash of variable and the corresponding value
245
+ def server_url(index, variables = {}, servers = nil)
246
+ servers = server_settings if servers.nil?
247
+
248
+ # check array index out of bound
249
+ if index.negative? || index >= servers.size
250
+ raise ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
251
+ end
252
+
253
+ server = servers[index]
254
+ url = server[:url]
255
+
256
+ return url unless server.key? :variables
257
+
258
+ # go through variable and assign a value
259
+ server[:variables].each do |name, _variable|
260
+ if variables.key?(name)
261
+ if !server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name])
262
+ url.gsub! "{#{name}}", variables[name]
263
+ else
264
+ raise ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
265
+ end
266
+ else
267
+ # use default value
268
+ url.gsub! "{#{name}}", server[:variables][name][:default_value]
269
+ end
270
+ end
271
+
272
+ url
273
+ end
274
+ end
275
+ end
@@ -0,0 +1,237 @@
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 DeviceSampleResponse
18
+ attr_accessor :id, :data, :segment
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ id: :id,
24
+ data: :data,
25
+ segment: :segment
26
+ }
27
+ end
28
+
29
+ # Returns all the JSON keys this model knows about
30
+ def self.acceptable_attributes
31
+ attribute_map.values
32
+ end
33
+
34
+ # Attribute type mapping.
35
+ def self.openapi_types
36
+ {
37
+ id: :String,
38
+ data: :SingleSampleData,
39
+ segment: :SegmentSimpleResponse
40
+ }
41
+ end
42
+
43
+ # List of attributes with nullable: true
44
+ def self.openapi_nullable
45
+ Set.new([])
46
+ end
47
+
48
+ # Initializes the object
49
+ # @param [Hash] attributes Model attributes in the form of hash
50
+ def initialize(attributes = {})
51
+ unless attributes.is_a?(Hash)
52
+ raise ArgumentError, "The input argument (attributes) must be a hash in `Airthings::DeviceSampleResponse` initialize method"
53
+ end
54
+
55
+ # check to see if the attribute exists and convert string to symbol for hash key
56
+ attributes = attributes.each_with_object({}) do |(k, v), h|
57
+ unless self.class.attribute_map.key?(k.to_sym)
58
+ raise ArgumentError, "`#{k}` is not a valid attribute in `Airthings::DeviceSampleResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
59
+ end
60
+
61
+ h[k.to_sym] = v
62
+ end
63
+
64
+ self.id = attributes[:id] if attributes.key?(:id)
65
+
66
+ self.data = attributes[:data] if attributes.key?(:data)
67
+
68
+ self.segment = attributes[:segment] if attributes.key?(:segment)
69
+ end
70
+
71
+ # Show invalid properties with the reasons. Usually used together with valid?
72
+ # @return Array for valid properties with the reasons
73
+ def list_invalid_properties
74
+ invalid_properties = []
75
+ invalid_properties.push('invalid value for "id", id cannot be nil.') if @id.nil?
76
+
77
+ invalid_properties.push('invalid value for "data", data cannot be nil.') if @data.nil?
78
+
79
+ invalid_properties.push('invalid value for "segment", segment cannot be nil.') if @segment.nil?
80
+
81
+ invalid_properties
82
+ end
83
+
84
+ # Check to see if the all the properties in the model are valid
85
+ # @return true if the model is valid
86
+ def valid?
87
+ return false if @id.nil?
88
+ return false if @data.nil?
89
+ return false if @segment.nil?
90
+
91
+ true
92
+ end
93
+
94
+ # Checks equality by comparing each attribute.
95
+ # @param [Object] Object to be compared
96
+ def ==(other)
97
+ return true if equal?(other)
98
+
99
+ self.class == other.class &&
100
+ id == other.id &&
101
+ data == other.data &&
102
+ segment == other.segment
103
+ end
104
+
105
+ # @see the `==` method
106
+ # @param [Object] Object to be compared
107
+ def eql?(other)
108
+ self == other
109
+ end
110
+
111
+ # Calculates hash code according to all attributes.
112
+ # @return [Integer] Hash code
113
+ def hash
114
+ [id, data, segment].hash
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 self.build_from_hash(attributes)
121
+ new.build_from_hash(attributes)
122
+ end
123
+
124
+ # Builds the object from hash
125
+ # @param [Hash] attributes Model attributes in the form of hash
126
+ # @return [Object] Returns the model itself
127
+ def build_from_hash(attributes)
128
+ return nil unless attributes.is_a?(Hash)
129
+
130
+ attributes = attributes.transform_keys(&:to_sym)
131
+ self.class.openapi_types.each_pair do |key, type|
132
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
133
+ send("#{key}=", nil)
134
+ elsif type =~ /\AArray<(.*)>/i
135
+ # check to ensure the input is an array given that the attribute
136
+ # is documented as an array but the input is not
137
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
138
+ send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
139
+ end
140
+ elsif !attributes[self.class.attribute_map[key]].nil?
141
+ send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
142
+ end
143
+ end
144
+
145
+ self
146
+ end
147
+
148
+ # Deserializes the data based on type
149
+ # @param string type Data type
150
+ # @param string value Value to be deserialized
151
+ # @return [Object] Deserialized data
152
+ def _deserialize(type, value)
153
+ case type.to_sym
154
+ when :Time
155
+ Time.parse(value)
156
+ when :Date
157
+ Date.parse(value)
158
+ when :String
159
+ value.to_s
160
+ when :Integer
161
+ value.to_i
162
+ when :Float
163
+ value.to_f
164
+ when :Boolean
165
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
166
+ true
167
+ else
168
+ false
169
+ end
170
+ when :Object
171
+ # generic object (usually a Hash), return directly
172
+ value
173
+ when /\AArray<(?<inner_type>.+)>\z/
174
+ inner_type = Regexp.last_match[:inner_type]
175
+ value.map { |v| _deserialize(inner_type, v) }
176
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
177
+ k_type = Regexp.last_match[:k_type]
178
+ v_type = Regexp.last_match[:v_type]
179
+ {}.tap do |hash|
180
+ value.each do |k, v|
181
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
182
+ end
183
+ end
184
+ else # model
185
+ # models (e.g. Pet) or oneOf
186
+ klass = Airthings.const_get(type)
187
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
188
+ end
189
+ end
190
+
191
+ # Returns the string representation of the object
192
+ # @return [String] String presentation of the object
193
+ def to_s
194
+ to_hash.to_s
195
+ end
196
+
197
+ # to_body is an alias to to_hash (backward compatibility)
198
+ # @return [Hash] Returns the object in the form of hash
199
+ def to_body
200
+ to_hash
201
+ end
202
+
203
+ # Returns the object in the form of hash
204
+ # @return [Hash] Returns the object in the form of hash
205
+ def to_hash
206
+ hash = {}
207
+ self.class.attribute_map.each_pair do |attr, param|
208
+ value = send(attr)
209
+ if value.nil?
210
+ is_nullable = self.class.openapi_nullable.include?(attr)
211
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
212
+ end
213
+
214
+ hash[param] = _to_hash(value)
215
+ end
216
+ hash
217
+ end
218
+
219
+ # Outputs non-array value in the form of hash
220
+ # For object, use to_hash. Otherwise, just return the value
221
+ # @param [Object] value Any valid value
222
+ # @return [Hash] Returns the value in the form of hash
223
+ def _to_hash(value)
224
+ if value.is_a?(Array)
225
+ value.compact.map { |v| _to_hash(v) }
226
+ elsif value.is_a?(Hash)
227
+ {}.tap do |hash|
228
+ value.each { |k, v| hash[k] = _to_hash(v) }
229
+ end
230
+ elsif value.respond_to? :to_hash
231
+ value.to_hash
232
+ else
233
+ value
234
+ end
235
+ end
236
+ end
237
+ end