influxdb-client 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +157 -0
  3. data/.circleci/setup-rubygems.sh +3 -0
  4. data/.codecov.yml +3 -0
  5. data/.github/PULL_REQUEST_TEMPLATE +8 -0
  6. data/.gitignore +16 -0
  7. data/.rubocop.yml +38 -0
  8. data/CHANGELOG.md +37 -0
  9. data/Gemfile +24 -0
  10. data/LICENSE +21 -0
  11. data/README.md +268 -0
  12. data/Rakefile +37 -0
  13. data/bin/generate-sources.sh +23 -0
  14. data/bin/influxdb-onboarding.sh +39 -0
  15. data/bin/influxdb-restart.sh +60 -0
  16. data/bin/pom.xml +34 -0
  17. data/bin/swagger.yml +9867 -0
  18. data/examples/influxdb_18_example.rb +35 -0
  19. data/influxdb-client.gemspec +53 -0
  20. data/lib/influxdb2/client.rb +30 -0
  21. data/lib/influxdb2/client/client.rb +96 -0
  22. data/lib/influxdb2/client/default_api.rb +95 -0
  23. data/lib/influxdb2/client/delete_api.rb +80 -0
  24. data/lib/influxdb2/client/flux_csv_parser.rb +251 -0
  25. data/lib/influxdb2/client/flux_table.rb +99 -0
  26. data/lib/influxdb2/client/health_api.rb +49 -0
  27. data/lib/influxdb2/client/influx_error.rb +31 -0
  28. data/lib/influxdb2/client/models/delete_predicate_request.rb +215 -0
  29. data/lib/influxdb2/client/models/dialect.rb +317 -0
  30. data/lib/influxdb2/client/models/health_check.rb +256 -0
  31. data/lib/influxdb2/client/models/query.rb +284 -0
  32. data/lib/influxdb2/client/point.rb +215 -0
  33. data/lib/influxdb2/client/query_api.rb +93 -0
  34. data/lib/influxdb2/client/version.rb +23 -0
  35. data/lib/influxdb2/client/worker.rb +115 -0
  36. data/lib/influxdb2/client/write_api.rb +243 -0
  37. data/test/influxdb/client_test.rb +92 -0
  38. data/test/influxdb/delete_api_integration_test.rb +100 -0
  39. data/test/influxdb/delete_api_test.rb +121 -0
  40. data/test/influxdb/flux_csv_parser_test.rb +401 -0
  41. data/test/influxdb/point_test.rb +221 -0
  42. data/test/influxdb/query_api_integration_test.rb +58 -0
  43. data/test/influxdb/query_api_stream_test.rb +98 -0
  44. data/test/influxdb/query_api_test.rb +96 -0
  45. data/test/influxdb/write_api_batching_test.rb +292 -0
  46. data/test/influxdb/write_api_integration_test.rb +76 -0
  47. data/test/influxdb/write_api_test.rb +275 -0
  48. data/test/test_helper.rb +39 -0
  49. metadata +217 -0
@@ -0,0 +1,256 @@
1
+ =begin
2
+ #Influx API Service
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ OpenAPI spec version: 0.1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 3.3.4
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module InfluxDB2
16
+ class HealthCheck
17
+ attr_accessor :name
18
+
19
+ attr_accessor :message
20
+
21
+ attr_accessor :checks
22
+
23
+ attr_accessor :status
24
+
25
+ class EnumAttributeValidator
26
+ attr_reader :datatype
27
+ attr_reader :allowable_values
28
+
29
+ def initialize(datatype, allowable_values)
30
+ @allowable_values = allowable_values.map do |value|
31
+ case datatype.to_s
32
+ when /Integer/i
33
+ value.to_i
34
+ when /Float/i
35
+ value.to_f
36
+ else
37
+ value
38
+ end
39
+ end
40
+ end
41
+
42
+ def valid?(value)
43
+ !value || allowable_values.include?(value)
44
+ end
45
+ end
46
+
47
+ # Attribute mapping from ruby-style variable name to JSON key.
48
+ def self.attribute_map
49
+ {
50
+ :'name' => :'name',
51
+ :'message' => :'message',
52
+ :'checks' => :'checks',
53
+ :'status' => :'status'
54
+ }
55
+ end
56
+
57
+ # Attribute type mapping.
58
+ def self.openapi_types
59
+ {
60
+ :'name' => :'String',
61
+ :'message' => :'String',
62
+ :'checks' => :'Array<HealthCheck>',
63
+ :'status' => :'String'
64
+ }
65
+ end
66
+
67
+ # Initializes the object
68
+ # @param [Hash] attributes Model attributes in the form of hash
69
+ def initialize(attributes = {})
70
+ return unless attributes.is_a?(Hash)
71
+
72
+ # convert string to symbol for hash key
73
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
74
+
75
+ if attributes.has_key?(:'name')
76
+ self.name = attributes[:'name']
77
+ end
78
+
79
+ if attributes.has_key?(:'message')
80
+ self.message = attributes[:'message']
81
+ end
82
+
83
+ if attributes.has_key?(:'checks')
84
+ if (value = attributes[:'checks']).is_a?(Array)
85
+ self.checks = value
86
+ end
87
+ end
88
+
89
+ if attributes.has_key?(:'status')
90
+ self.status = attributes[:'status']
91
+ end
92
+ end
93
+
94
+ # Show invalid properties with the reasons. Usually used together with valid?
95
+ # @return Array for valid properties with the reasons
96
+ def list_invalid_properties
97
+ invalid_properties = Array.new
98
+ if @name.nil?
99
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
100
+ end
101
+
102
+ if @status.nil?
103
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
104
+ end
105
+
106
+ invalid_properties
107
+ end
108
+
109
+ # Check to see if the all the properties in the model are valid
110
+ # @return true if the model is valid
111
+ def valid?
112
+ return false if @name.nil?
113
+ return false if @status.nil?
114
+ status_validator = EnumAttributeValidator.new('String', ['pass', 'fail'])
115
+ return false unless status_validator.valid?(@status)
116
+ true
117
+ end
118
+
119
+ # Custom attribute writer method checking allowed values (enum).
120
+ # @param [Object] status Object to be assigned
121
+ def status=(status)
122
+ validator = EnumAttributeValidator.new('String', ['pass', 'fail'])
123
+ unless validator.valid?(status)
124
+ fail ArgumentError, 'invalid value for "status", must be one of #{validator.allowable_values}.'
125
+ end
126
+ @status = status
127
+ end
128
+
129
+ # Checks equality by comparing each attribute.
130
+ # @param [Object] Object to be compared
131
+ def ==(o)
132
+ return true if self.equal?(o)
133
+ self.class == o.class &&
134
+ name == o.name &&
135
+ message == o.message &&
136
+ checks == o.checks &&
137
+ status == o.status
138
+ end
139
+
140
+ # @see the `==` method
141
+ # @param [Object] Object to be compared
142
+ def eql?(o)
143
+ self == o
144
+ end
145
+
146
+ # Calculates hash code according to all attributes.
147
+ # @return [Fixnum] Hash code
148
+ def hash
149
+ [name, message, checks, status].hash
150
+ end
151
+
152
+ # Builds the object from hash
153
+ # @param [Hash] attributes Model attributes in the form of hash
154
+ # @return [Object] Returns the model itself
155
+ def build_from_hash(attributes)
156
+ return nil unless attributes.is_a?(Hash)
157
+ self.class.openapi_types.each_pair do |key, type|
158
+ if type =~ /\AArray<(.*)>/i
159
+ # check to ensure the input is an array given that the the attribute
160
+ # is documented as an array but the input is not
161
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
162
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
163
+ end
164
+ elsif !attributes[self.class.attribute_map[key]].nil?
165
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
166
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
167
+ end
168
+
169
+ self
170
+ end
171
+
172
+ # Deserializes the data based on type
173
+ # @param string type Data type
174
+ # @param string value Value to be deserialized
175
+ # @return [Object] Deserialized data
176
+ def _deserialize(type, value)
177
+ case type.to_sym
178
+ when :DateTime
179
+ DateTime.parse(value)
180
+ when :Date
181
+ Date.parse(value)
182
+ when :String
183
+ value.to_s
184
+ when :Integer
185
+ value.to_i
186
+ when :Float
187
+ value.to_f
188
+ when :BOOLEAN
189
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
190
+ true
191
+ else
192
+ false
193
+ end
194
+ when :Object
195
+ # generic object (usually a Hash), return directly
196
+ value
197
+ when /\AArray<(?<inner_type>.+)>\z/
198
+ inner_type = Regexp.last_match[:inner_type]
199
+ value.map { |v| _deserialize(inner_type, v) }
200
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
201
+ k_type = Regexp.last_match[:k_type]
202
+ v_type = Regexp.last_match[:v_type]
203
+ {}.tap do |hash|
204
+ value.each do |k, v|
205
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
206
+ end
207
+ end
208
+ else # model
209
+ temp_model = InfluxDB2.const_get(type).new
210
+ temp_model.build_from_hash(value)
211
+ end
212
+ end
213
+
214
+ # Returns the string representation of the object
215
+ # @return [String] String presentation of the object
216
+ def to_s
217
+ to_hash.to_s
218
+ end
219
+
220
+ # to_body is an alias to to_hash (backward compatibility)
221
+ # @return [Hash] Returns the object in the form of hash
222
+ def to_body
223
+ to_hash
224
+ end
225
+
226
+ # Returns the object in the form of hash
227
+ # @return [Hash] Returns the object in the form of hash
228
+ def to_hash
229
+ hash = {}
230
+ self.class.attribute_map.each_pair do |attr, param|
231
+ value = self.send(attr)
232
+ next if value.nil?
233
+ hash[param] = _to_hash(value)
234
+ end
235
+ hash
236
+ end
237
+
238
+ # Outputs non-array value in the form of hash
239
+ # For object, use to_hash. Otherwise, just return the value
240
+ # @param [Object] value Any valid value
241
+ # @return [Hash] Returns the value in the form of hash
242
+ def _to_hash(value)
243
+ if value.is_a?(Array)
244
+ value.compact.map { |v| _to_hash(v) }
245
+ elsif value.is_a?(Hash)
246
+ {}.tap do |hash|
247
+ value.each { |k, v| hash[k] = _to_hash(v) }
248
+ end
249
+ elsif value.respond_to? :to_hash
250
+ value.to_hash
251
+ else
252
+ value
253
+ end
254
+ end
255
+ end
256
+ end
@@ -0,0 +1,284 @@
1
+ =begin
2
+ #Influx API Service
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ OpenAPI spec version: 0.1.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 3.3.4
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module InfluxDB2
16
+ # Query influx with specific return formatting.
17
+ class Query
18
+ attr_accessor :extern
19
+
20
+ # Query script to execute.
21
+ attr_accessor :query
22
+
23
+ # The type of query.
24
+ attr_accessor :type
25
+
26
+ # Required for `influxql` type queries.
27
+ attr_accessor :db
28
+
29
+ # Required for `influxql` type queries.
30
+ attr_accessor :rp
31
+
32
+ # Required for `influxql` type queries.
33
+ attr_accessor :cluster
34
+
35
+ attr_accessor :dialect
36
+
37
+ class EnumAttributeValidator
38
+ attr_reader :datatype
39
+ attr_reader :allowable_values
40
+
41
+ def initialize(datatype, allowable_values)
42
+ @allowable_values = allowable_values.map do |value|
43
+ case datatype.to_s
44
+ when /Integer/i
45
+ value.to_i
46
+ when /Float/i
47
+ value.to_f
48
+ else
49
+ value
50
+ end
51
+ end
52
+ end
53
+
54
+ def valid?(value)
55
+ !value || allowable_values.include?(value)
56
+ end
57
+ end
58
+
59
+ # Attribute mapping from ruby-style variable name to JSON key.
60
+ def self.attribute_map
61
+ {
62
+ :'extern' => :'extern',
63
+ :'query' => :'query',
64
+ :'type' => :'type',
65
+ :'db' => :'db',
66
+ :'rp' => :'rp',
67
+ :'cluster' => :'cluster',
68
+ :'dialect' => :'dialect'
69
+ }
70
+ end
71
+
72
+ # Attribute type mapping.
73
+ def self.openapi_types
74
+ {
75
+ :'extern' => :'File',
76
+ :'query' => :'String',
77
+ :'type' => :'String',
78
+ :'db' => :'String',
79
+ :'rp' => :'String',
80
+ :'cluster' => :'String',
81
+ :'dialect' => :'Dialect'
82
+ }
83
+ end
84
+
85
+ # Initializes the object
86
+ # @param [Hash] attributes Model attributes in the form of hash
87
+ def initialize(attributes = {})
88
+ return unless attributes.is_a?(Hash)
89
+
90
+ # convert string to symbol for hash key
91
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
92
+
93
+ if attributes.has_key?(:'extern')
94
+ self.extern = attributes[:'extern']
95
+ end
96
+
97
+ if attributes.has_key?(:'query')
98
+ self.query = attributes[:'query']
99
+ end
100
+
101
+ if attributes.has_key?(:'type')
102
+ self.type = attributes[:'type']
103
+ else
104
+ self.type = 'flux'
105
+ end
106
+
107
+ if attributes.has_key?(:'db')
108
+ self.db = attributes[:'db']
109
+ end
110
+
111
+ if attributes.has_key?(:'rp')
112
+ self.rp = attributes[:'rp']
113
+ end
114
+
115
+ if attributes.has_key?(:'cluster')
116
+ self.cluster = attributes[:'cluster']
117
+ end
118
+
119
+ if attributes.has_key?(:'dialect')
120
+ self.dialect = attributes[:'dialect']
121
+ end
122
+ end
123
+
124
+ # Show invalid properties with the reasons. Usually used together with valid?
125
+ # @return Array for valid properties with the reasons
126
+ def list_invalid_properties
127
+ invalid_properties = Array.new
128
+ if @query.nil?
129
+ invalid_properties.push('invalid value for "query", query cannot be nil.')
130
+ end
131
+
132
+ invalid_properties
133
+ end
134
+
135
+ # Check to see if the all the properties in the model are valid
136
+ # @return true if the model is valid
137
+ def valid?
138
+ return false if @query.nil?
139
+ type_validator = EnumAttributeValidator.new('String', ['flux', 'influxql'])
140
+ return false unless type_validator.valid?(@type)
141
+ true
142
+ end
143
+
144
+ # Custom attribute writer method checking allowed values (enum).
145
+ # @param [Object] type Object to be assigned
146
+ def type=(type)
147
+ validator = EnumAttributeValidator.new('String', ['flux', 'influxql'])
148
+ unless validator.valid?(type)
149
+ fail ArgumentError, 'invalid value for "type", must be one of #{validator.allowable_values}.'
150
+ end
151
+ @type = type
152
+ end
153
+
154
+ # Checks equality by comparing each attribute.
155
+ # @param [Object] Object to be compared
156
+ def ==(o)
157
+ return true if self.equal?(o)
158
+ self.class == o.class &&
159
+ extern == o.extern &&
160
+ query == o.query &&
161
+ type == o.type &&
162
+ db == o.db &&
163
+ rp == o.rp &&
164
+ cluster == o.cluster &&
165
+ dialect == o.dialect
166
+ end
167
+
168
+ # @see the `==` method
169
+ # @param [Object] Object to be compared
170
+ def eql?(o)
171
+ self == o
172
+ end
173
+
174
+ # Calculates hash code according to all attributes.
175
+ # @return [Fixnum] Hash code
176
+ def hash
177
+ [extern, query, type, db, rp, cluster, dialect].hash
178
+ end
179
+
180
+ # Builds the object from hash
181
+ # @param [Hash] attributes Model attributes in the form of hash
182
+ # @return [Object] Returns the model itself
183
+ def build_from_hash(attributes)
184
+ return nil unless attributes.is_a?(Hash)
185
+ self.class.openapi_types.each_pair do |key, type|
186
+ if type =~ /\AArray<(.*)>/i
187
+ # check to ensure the input is an array given that the the attribute
188
+ # is documented as an array but the input is not
189
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
190
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
191
+ end
192
+ elsif !attributes[self.class.attribute_map[key]].nil?
193
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
194
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
195
+ end
196
+
197
+ self
198
+ end
199
+
200
+ # Deserializes the data based on type
201
+ # @param string type Data type
202
+ # @param string value Value to be deserialized
203
+ # @return [Object] Deserialized data
204
+ def _deserialize(type, value)
205
+ case type.to_sym
206
+ when :DateTime
207
+ DateTime.parse(value)
208
+ when :Date
209
+ Date.parse(value)
210
+ when :String
211
+ value.to_s
212
+ when :Integer
213
+ value.to_i
214
+ when :Float
215
+ value.to_f
216
+ when :BOOLEAN
217
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
218
+ true
219
+ else
220
+ false
221
+ end
222
+ when :Object
223
+ # generic object (usually a Hash), return directly
224
+ value
225
+ when /\AArray<(?<inner_type>.+)>\z/
226
+ inner_type = Regexp.last_match[:inner_type]
227
+ value.map { |v| _deserialize(inner_type, v) }
228
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
229
+ k_type = Regexp.last_match[:k_type]
230
+ v_type = Regexp.last_match[:v_type]
231
+ {}.tap do |hash|
232
+ value.each do |k, v|
233
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
234
+ end
235
+ end
236
+ else # model
237
+ temp_model = InfluxDB2.const_get(type).new
238
+ temp_model.build_from_hash(value)
239
+ end
240
+ end
241
+
242
+ # Returns the string representation of the object
243
+ # @return [String] String presentation of the object
244
+ def to_s
245
+ to_hash.to_s
246
+ end
247
+
248
+ # to_body is an alias to to_hash (backward compatibility)
249
+ # @return [Hash] Returns the object in the form of hash
250
+ def to_body
251
+ to_hash
252
+ end
253
+
254
+ # Returns the object in the form of hash
255
+ # @return [Hash] Returns the object in the form of hash
256
+ def to_hash
257
+ hash = {}
258
+ self.class.attribute_map.each_pair do |attr, param|
259
+ value = self.send(attr)
260
+ next if value.nil?
261
+ hash[param] = _to_hash(value)
262
+ end
263
+ hash
264
+ end
265
+
266
+ # Outputs non-array value in the form of hash
267
+ # For object, use to_hash. Otherwise, just return the value
268
+ # @param [Object] value Any valid value
269
+ # @return [Hash] Returns the value in the form of hash
270
+ def _to_hash(value)
271
+ if value.is_a?(Array)
272
+ value.compact.map { |v| _to_hash(v) }
273
+ elsif value.is_a?(Hash)
274
+ {}.tap do |hash|
275
+ value.each { |k, v| hash[k] = _to_hash(v) }
276
+ end
277
+ elsif value.respond_to? :to_hash
278
+ value.to_hash
279
+ else
280
+ value
281
+ end
282
+ end
283
+ end
284
+ end