airthings 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,216 @@
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 SingleSampleResponse
18
+ attr_accessor :data
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ data: :data
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
+ data: :SingleSampleData
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::SingleSampleResponse` 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::SingleSampleResponse`. 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
+ self.data = attributes[:data] if attributes.key?(:data)
61
+ end
62
+
63
+ # Show invalid properties with the reasons. Usually used together with valid?
64
+ # @return Array for valid properties with the reasons
65
+ def list_invalid_properties
66
+ []
67
+ end
68
+
69
+ # Check to see if the all the properties in the model are valid
70
+ # @return true if the model is valid
71
+ def valid?
72
+ true
73
+ end
74
+
75
+ # Checks equality by comparing each attribute.
76
+ # @param [Object] Object to be compared
77
+ def ==(other)
78
+ return true if equal?(other)
79
+
80
+ self.class == other.class &&
81
+ data == other.data
82
+ end
83
+
84
+ # @see the `==` method
85
+ # @param [Object] Object to be compared
86
+ def eql?(other)
87
+ self == other
88
+ end
89
+
90
+ # Calculates hash code according to all attributes.
91
+ # @return [Integer] Hash code
92
+ def hash
93
+ [data].hash
94
+ end
95
+
96
+ # Builds the object from hash
97
+ # @param [Hash] attributes Model attributes in the form of hash
98
+ # @return [Object] Returns the model itself
99
+ def self.build_from_hash(attributes)
100
+ new.build_from_hash(attributes)
101
+ end
102
+
103
+ # Builds the object from hash
104
+ # @param [Hash] attributes Model attributes in the form of hash
105
+ # @return [Object] Returns the model itself
106
+ def build_from_hash(attributes)
107
+ return nil unless attributes.is_a?(Hash)
108
+
109
+ attributes = attributes.transform_keys(&:to_sym)
110
+ self.class.openapi_types.each_pair do |key, type|
111
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
112
+ send("#{key}=", nil)
113
+ elsif type =~ /\AArray<(.*)>/i
114
+ # check to ensure the input is an array given that the attribute
115
+ # is documented as an array but the input is not
116
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
117
+ send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
118
+ end
119
+ elsif !attributes[self.class.attribute_map[key]].nil?
120
+ send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
121
+ end
122
+ end
123
+
124
+ self
125
+ end
126
+
127
+ # Deserializes the data based on type
128
+ # @param string type Data type
129
+ # @param string value Value to be deserialized
130
+ # @return [Object] Deserialized data
131
+ def _deserialize(type, value)
132
+ case type.to_sym
133
+ when :Time
134
+ Time.parse(value)
135
+ when :Date
136
+ Date.parse(value)
137
+ when :String
138
+ value.to_s
139
+ when :Integer
140
+ value.to_i
141
+ when :Float
142
+ value.to_f
143
+ when :Boolean
144
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
145
+ true
146
+ else
147
+ false
148
+ end
149
+ when :Object
150
+ # generic object (usually a Hash), return directly
151
+ value
152
+ when /\AArray<(?<inner_type>.+)>\z/
153
+ inner_type = Regexp.last_match[:inner_type]
154
+ value.map { |v| _deserialize(inner_type, v) }
155
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
156
+ k_type = Regexp.last_match[:k_type]
157
+ v_type = Regexp.last_match[:v_type]
158
+ {}.tap do |hash|
159
+ value.each do |k, v|
160
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
161
+ end
162
+ end
163
+ else # model
164
+ # models (e.g. Pet) or oneOf
165
+ klass = Airthings.const_get(type)
166
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
167
+ end
168
+ end
169
+
170
+ # Returns the string representation of the object
171
+ # @return [String] String presentation of the object
172
+ def to_s
173
+ to_hash.to_s
174
+ end
175
+
176
+ # to_body is an alias to to_hash (backward compatibility)
177
+ # @return [Hash] Returns the object in the form of hash
178
+ def to_body
179
+ to_hash
180
+ end
181
+
182
+ # Returns the object in the form of hash
183
+ # @return [Hash] Returns the object in the form of hash
184
+ def to_hash
185
+ hash = {}
186
+ self.class.attribute_map.each_pair do |attr, param|
187
+ value = send(attr)
188
+ if value.nil?
189
+ is_nullable = self.class.openapi_nullable.include?(attr)
190
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
191
+ end
192
+
193
+ hash[param] = _to_hash(value)
194
+ end
195
+ hash
196
+ end
197
+
198
+ # Outputs non-array value in the form of hash
199
+ # For object, use to_hash. Otherwise, just return the value
200
+ # @param [Object] value Any valid value
201
+ # @return [Hash] Returns the value in the form of hash
202
+ def _to_hash(value)
203
+ if value.is_a?(Array)
204
+ value.compact.map { |v| _to_hash(v) }
205
+ elsif value.is_a?(Hash)
206
+ {}.tap do |hash|
207
+ value.each { |k, v| hash[k] = _to_hash(v) }
208
+ end
209
+ elsif value.respond_to? :to_hash
210
+ value.to_hash
211
+ else
212
+ value
213
+ end
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "oauth2"
4
+
5
+ module Airthings
6
+ module OAuth2
7
+ module ClientCredentials
8
+ def self.prepended(klass)
9
+ super
10
+ klass.attr_accessor :id, :secret
11
+ end
12
+
13
+ def access_token
14
+ @access_token = nil if @access_token&.expired?
15
+ @access_token ||= begin
16
+ client = ::OAuth2::Client.new(id, secret, token_url: "https://accounts-api.airthings.com/v1/token")
17
+ client.client_credentials.get_token
18
+ end
19
+ @access_token.token
20
+ end
21
+ end
22
+ Configuration.prepend(ClientCredentials)
23
+ end
24
+ end
@@ -0,0 +1,15 @@
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
+ VERSION = "1.0.0"
15
+ end
data/lib/airthings.rb ADDED
@@ -0,0 +1,56 @@
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
+ # Common files
14
+ require "airthings/api_client"
15
+ require "airthings/api_error"
16
+ require "airthings/version"
17
+ require "airthings/configuration"
18
+
19
+ # Models
20
+ Airthings.autoload :DeviceSampleResponse, "airthings/models/device_sample_response"
21
+ Airthings.autoload :DeviceSimpleResponse, "airthings/models/device_simple_response"
22
+ Airthings.autoload :DeviceType, "airthings/models/device_type"
23
+ Airthings.autoload :GetDeviceDetailedResponse, "airthings/models/get_device_detailed_response"
24
+ Airthings.autoload :GetDevicesResponse, "airthings/models/get_devices_response"
25
+ Airthings.autoload :GetLocationResponse, "airthings/models/get_location_response"
26
+ Airthings.autoload :GetLocationsResponse, "airthings/models/get_locations_response"
27
+ Airthings.autoload :LocalTime, "airthings/models/local_time"
28
+ Airthings.autoload :Location, "airthings/models/location"
29
+ Airthings.autoload :LocationSimpleResponse, "airthings/models/location_simple_response"
30
+ Airthings.autoload :LocationUsage, "airthings/models/location_usage"
31
+ Airthings.autoload :SegmentSimpleResponse, "airthings/models/segment_simple_response"
32
+ Airthings.autoload :SensorType, "airthings/models/sensor_type"
33
+ Airthings.autoload :SingleSampleData, "airthings/models/single_sample_data"
34
+ Airthings.autoload :SingleSampleResponse, "airthings/models/single_sample_response"
35
+
36
+ # APIs
37
+ Airthings.autoload :DevicesApi, "airthings/api/devices_api"
38
+ Airthings.autoload :LocationsApi, "airthings/api/locations_api"
39
+
40
+ module Airthings
41
+ class << self
42
+ # Customize default settings for the SDK using block.
43
+ # Airthings.configure do |config|
44
+ # config.username = "xxx"
45
+ # config.password = "xxx"
46
+ # end
47
+ # If no block given, return the default Configuration object.
48
+ def configure
49
+ if block_given?
50
+ yield(Configuration.default)
51
+ else
52
+ Configuration.default
53
+ end
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: airthings
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Cody Cutrer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: homie-mqtt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: typhoeus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: irb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.11'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.11'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.23'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.23'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-performance
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.12'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.12'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.6'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.6'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.11'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.11'
153
+ description:
154
+ email:
155
+ - cody@cutrer.us
156
+ executables:
157
+ - airthings_mqtt_bridge
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - exe/airthings_mqtt_bridge
162
+ - lib/airthings.rb
163
+ - lib/airthings/api/devices_api.rb
164
+ - lib/airthings/api/locations_api.rb
165
+ - lib/airthings/api_client.rb
166
+ - lib/airthings/api_error.rb
167
+ - lib/airthings/configuration.rb
168
+ - lib/airthings/models/device_sample_response.rb
169
+ - lib/airthings/models/device_simple_response.rb
170
+ - lib/airthings/models/device_type.rb
171
+ - lib/airthings/models/get_device_detailed_response.rb
172
+ - lib/airthings/models/get_devices_response.rb
173
+ - lib/airthings/models/get_location_response.rb
174
+ - lib/airthings/models/get_locations_response.rb
175
+ - lib/airthings/models/local_time.rb
176
+ - lib/airthings/models/location.rb
177
+ - lib/airthings/models/location_simple_response.rb
178
+ - lib/airthings/models/location_usage.rb
179
+ - lib/airthings/models/segment_simple_response.rb
180
+ - lib/airthings/models/sensor_type.rb
181
+ - lib/airthings/models/single_sample_data.rb
182
+ - lib/airthings/models/single_sample_response.rb
183
+ - lib/airthings/oauth2.rb
184
+ - lib/airthings/version.rb
185
+ homepage: https://github.com/ccutrer/ruby-airthings
186
+ licenses:
187
+ - MIT
188
+ metadata:
189
+ rubygems_mfa_required: 'true'
190
+ post_install_message:
191
+ rdoc_options: []
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '2.5'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubygems_version: 3.3.7
206
+ signing_key:
207
+ specification_version: 4
208
+ summary: Airthings Consumer API Ruby Gem
209
+ test_files: []