influxdb-client 1.1.0 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c567a9747fbb62687569311a2a23d75115eab950713766a8a7e8ac0a65d8a7b
4
- data.tar.gz: 1fdb87086e8f18ff65d2da79a51d34c397887bc6ad0ae87dd3904b3cbb1787e0
3
+ metadata.gz: 0bef54ca002cca11fb29d73a4de5efaa081a800ebc6a284a7eca088bf7d257ea
4
+ data.tar.gz: 1ca91c0b690ee38c10e89cc41a178f071e244b7b85126a0fadb52315c9eb5a45
5
5
  SHA512:
6
- metadata.gz: bbc770f809525bd1799e1698d4c8214893a4364f9563fcb972e47f5446720cbbfda6e07acdb0c253b2cad0c6d86decda03fbdcb8ac5639f3428a4362f2f59819
7
- data.tar.gz: 3469d334c5fe3bade7cca71291db812f617a56231a8a6a5abe309b2ecb97a381a6f547df81699da7ba0a8c67b20742a620cba020b2bed366802a259463881df0
6
+ metadata.gz: 849abb961288944fb762ec38a8bb7fdc4b51be0941a03547e8e23360aee98aedf78018e98f75bb879497784bf75a6df3f5c80f164c2a9a453a466f5b8e890d7d
7
+ data.tar.gz: 2f9a75a9913f0f719d4dce37b1dfa33527159c0435672473979562aba705f8bf1ce34e1be5bd27bfd5dd713af41e39cf194460859a3631d6b28ededb9d188588
@@ -2,7 +2,7 @@ Closes #
2
2
 
3
3
  _Briefly describe your proposed changes:_
4
4
 
5
- - [ ] CHANGELOG.md updated
6
- - [ ] Rebased/mergeable
7
- - [ ] Tests pass
8
- - [ ] Sign [CLA](https://influxdata.com/community/cla/) (if not already signed)
5
+ - [ ] CHANGELOG.md updated
6
+ - [ ] Rebased/mergeable
7
+ - [ ] Tests pass
8
+ - [ ] Sign [CLA](https://influxdata.com/community/cla/) (if not already signed)
@@ -27,11 +27,11 @@ AllCops:
27
27
  Metrics/LineLength:
28
28
  Max: 120
29
29
  Metrics/MethodLength:
30
- Max: 30
30
+ Max: 50
31
31
  Metrics/ClassLength:
32
32
  Max: 200
33
33
  Metrics/AbcSize:
34
- Max: 30
34
+ Max: 40
35
35
  Metrics/CyclomaticComplexity:
36
36
  Max: 15
37
37
  Metrics/PerceivedComplexity:
@@ -1,3 +1,18 @@
1
+ ## 1.2.0 [2020-03-13]
2
+
3
+ ### Features
4
+ 1. [#23](https://github.com/influxdata/influxdb-client-ruby/issues/23): Added DeleteApi to delete time series data from InfluxDB.
5
+ 1. [#24](https://github.com/influxdata/influxdb-client-ruby/issues/24): Added jitter_interval and retry_interval to WriteApi
6
+ 1. [#26](https://github.com/influxdata/influxdb-client-ruby/issues/26): Set User-Agent to influxdb-client-ruby/VERSION for all requests
7
+
8
+ ### Security
9
+ 1. [#29](https://github.com/influxdata/influxdb-client-ruby/pull/29): Upgrade rake to version 12.3.3 - [CVE-2020-8130](https://github.com/advisories/GHSA-jppv-gw3r-w3q8)
10
+
11
+ ### Bugs
12
+ 1. [#22](https://github.com/influxdata/influxdb-client-ruby/pull/22): Fixed batch write
13
+ 1. [#28](https://github.com/influxdata/influxdb-client-ruby/pull/28): Correctly parse CSV where multiple results include multiple tables
14
+ 1. [#30](https://github.com/influxdata/influxdb-client-ruby/pull/30): Send Content-Type headers
15
+
1
16
  ## 1.1.0 [2020-02-14]
2
17
 
3
18
  ### Features
data/README.md CHANGED
@@ -11,7 +11,6 @@
11
11
  This repository contains the reference Ruby client for the InfluxDB 2.0.
12
12
 
13
13
  #### Note: This library is for use with InfluxDB 2.x. For connecting to InfluxDB 1.x instances, please use the [influxdb-ruby](https://github.com/influxdata/influxdb-ruby) client.
14
- #### Disclaimer: This library is a work in progress and should not be considered production ready yet.
15
14
 
16
15
  ## Installation
17
16
 
@@ -24,7 +23,7 @@ The client can be installed manually or with bundler.
24
23
  To install the client gem manually:
25
24
 
26
25
  ```
27
- gem install influxdb-client -v 1.1.0
26
+ gem install influxdb-client -v 1.2.0
28
27
  ```
29
28
 
30
29
  ## Usage
@@ -122,8 +121,10 @@ The writes are processed in batches which are configurable by `WriteOptions`:
122
121
 
123
122
  | Property | Description | Default Value |
124
123
  | --- | --- | --- |
125
- | **batchSize** | the number of data point to collect in batch | 1000 |
126
- | **flushInterval** | the number of milliseconds before the batch is written | 1000 |
124
+ | batchSize | the number of data point to collect in batch | 1000 |
125
+ | flushInterval | the number of milliseconds before the batch is written | 1000 |
126
+ | retry_interval | the number of milliseconds to retry unsuccessful write. The retry interval is used when the InfluxDB server does not specify "Retry-After" header. | 1000 |
127
+ | jitter_interval | the number of milliseconds to increase the batch flush interval by a random amount | 0 |
127
128
 
128
129
  ```ruby
129
130
  write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
@@ -209,6 +210,27 @@ write_api = client.create_write_api
209
210
  write_api.write(data: ['h2o,location=west value=33i 15', point, hash])
210
211
  ```
211
212
 
213
+ ### Delete data
214
+
215
+ The [DeleteApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/delete_api.rb) supports deletes [points](https://v2.docs.influxdata.com/v2.0/reference/glossary/#point) from an InfluxDB bucket.
216
+
217
+ ```ruby
218
+ client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
219
+ bucket: 'my-bucket',
220
+ org: 'my-org',
221
+ precision: InfluxDB2::WritePrecision::NANOSECOND)
222
+
223
+ client.create_delete_api.delete(DateTime.rfc3339('2019-02-03T04:05:06+07:00'),
224
+ DateTime.rfc3339('2019-03-03T04:05:06+07:00'),
225
+ predicate: 'key1="value1" AND key2="value"')
226
+ ```
227
+
228
+ The time range could be specified as:
229
+
230
+ 1. String - `"2019-02-03T04:05:06+07:00"`
231
+ 1. DateTime - `DateTime.rfc3339('2019-03-03T04:05:06+07:00')`
232
+ 1. Time - `Time.utc(2015, 10, 16, 8, 20, 15)`
233
+
212
234
  ## Local tests
213
235
 
214
236
  ```
@@ -4,12 +4,7 @@
4
4
 
5
5
  SCRIPT_PATH="$( cd "$(dirname "$0")" || exit ; pwd -P )"
6
6
 
7
- # Generate OpenAPI generator
8
- #cd "${SCRIPT_PATH}"/../openapi-generator/ || exit
9
- #mvn clean install -DskipTests
10
-
11
7
  # delete old sources
12
- #rm "${SCRIPT_PATH}"/../influxdb_client/domain/*.py
13
8
  rm "${SCRIPT_PATH}"/../lib/influxdb2/client/models/*
14
9
 
15
10
  # Generate client
@@ -21,10 +16,8 @@ mkdir -p "${SCRIPT_PATH}"/../lib/influxdb2/client/models
21
16
  mv "${SCRIPT_PATH}"/../lib/influx_db2/models/* "${SCRIPT_PATH}"/../lib/influxdb2/client/models
22
17
 
23
18
  cd "${SCRIPT_PATH}"/../lib/influxdb2/client/models || exit
24
- rm -r $(ls | grep -v "\<query.rb\>\|\<dialect.rb\>")
19
+ rm -r $(ls | grep -v "\<dialect.rb\>\|\<query.rb\>\|\<delete_predicate_request.rb\>")
25
20
 
26
21
  # Clean
27
22
  rmdir "${SCRIPT_PATH}"/../lib/influx_db2/models
28
23
  rmdir "${SCRIPT_PATH}"/../lib/influx_db2/
29
-
30
- #rm -r $(ls | grep -v "\<query.rb\>\|\<dialect.rb\>")
@@ -46,7 +46,7 @@ Gem::Specification.new do |spec|
46
46
  spec.add_development_dependency 'codecov', '~> 0.1.16'
47
47
  spec.add_development_dependency 'minitest', '~> 5.0'
48
48
  spec.add_development_dependency 'minitest-reporters', '~> 1.4'
49
- spec.add_development_dependency 'rake', '~> 10.0'
49
+ spec.add_development_dependency 'rake', '>= 12.3.3'
50
50
  spec.add_development_dependency 'rubocop', '~> 0.66.0'
51
51
  spec.add_development_dependency 'simplecov', '~> 0.17.1'
52
52
  spec.add_development_dependency 'webmock', '~> 3.7'
@@ -24,5 +24,6 @@ require 'influxdb2/client/client'
24
24
  require 'influxdb2/client/influx_error'
25
25
  require 'influxdb2/client/write_api'
26
26
  require 'influxdb2/client/query_api'
27
+ require 'influxdb2/client/delete_api'
27
28
  require 'influxdb2/client/point'
28
29
  require 'influxdb2/client/flux_table'
@@ -70,6 +70,13 @@ module InfluxDB2
70
70
  QueryApi.new(options: @options)
71
71
  end
72
72
 
73
+ # Get the Delete API to delete time series data from InfluxDB.
74
+ #
75
+ # @return [DeleteApi] New instance of DeleteApi.
76
+ def create_delete_api
77
+ DeleteApi.new(options: @options)
78
+ end
79
+
73
80
  # Close all connections into InfluxDB 2.
74
81
  #
75
82
  # @return [ true ] Always true.
@@ -24,6 +24,8 @@ module InfluxDB2
24
24
  DEFAULT_TIMEOUT = 10
25
25
  DEFAULT_REDIRECT_COUNT = 10
26
26
 
27
+ HEADER_CONTENT_TYPE = 'Content-Type'.freeze
28
+
27
29
  # @param [Hash] options The options to be used by the client.
28
30
  def initialize(options:)
29
31
  @options = options
@@ -32,7 +34,17 @@ module InfluxDB2
32
34
 
33
35
  private
34
36
 
35
- def _post(payload, uri, limit = @max_redirect_count)
37
+ def _post_json(payload, uri, headers: {})
38
+ _check_arg_type(:headers, headers, Hash)
39
+ _post(payload, uri, headers: headers.merge(HEADER_CONTENT_TYPE => 'application/json'))
40
+ end
41
+
42
+ def _post_text(payload, uri, headers: {})
43
+ _check_arg_type(:headers, headers, Hash)
44
+ _post(payload, uri, headers: headers.merge(HEADER_CONTENT_TYPE => 'text/plain'))
45
+ end
46
+
47
+ def _post(payload, uri, limit: @max_redirect_count, headers: {})
36
48
  raise InfluxError.from_message("Too many HTTP redirects. Exceeded limit: #{@max_redirect_count}") if limit.zero?
37
49
 
38
50
  http = Net::HTTP.new(uri.host, uri.port)
@@ -43,6 +55,9 @@ module InfluxDB2
43
55
 
44
56
  request = Net::HTTP::Post.new(uri.request_uri)
45
57
  request['Authorization'] = "Token #{@options[:token]}"
58
+ request['User-Agent'] = "influxdb-client-ruby/#{InfluxDB2::VERSION}"
59
+ headers.each { |k, v| request[k] = v }
60
+
46
61
  request.body = payload
47
62
 
48
63
  begin
@@ -52,7 +67,7 @@ module InfluxDB2
52
67
  response
53
68
  when Net::HTTPRedirection then
54
69
  location = response['location']
55
- _post(payload, URI.parse(location), limit - 1)
70
+ _post(payload, URI.parse(location), limit: limit - 1, headers: headers)
56
71
  else
57
72
  raise InfluxError.from_response(response)
58
73
  end
@@ -61,6 +76,10 @@ module InfluxDB2
61
76
  end
62
77
  end
63
78
 
79
+ def _check_arg_type(name, value, klass)
80
+ raise TypeError, "expected a #{klass.name} for #{name}; got #{value.class.name}" unless value.is_a?(klass)
81
+ end
82
+
64
83
  def _check(key, value)
65
84
  raise ArgumentError, "The '#{key}' should be defined as argument or default option: #{@options}" if value.nil?
66
85
  end
@@ -0,0 +1,80 @@
1
+ # The MIT License
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require_relative 'models/delete_predicate_request'
22
+
23
+ module InfluxDB2
24
+ # Delete time series data from InfluxDB
25
+ #
26
+ class DeleteApi < DefaultApi
27
+ # @param [Hash] options The options to be used by the client.
28
+ def initialize(options:)
29
+ super(options: options)
30
+ end
31
+
32
+ # Delete time series data from InfluxDB.
33
+ #
34
+ # @example
35
+ # delete('2019-02-03T04:05:06+07:00', '2019-04-03T04:05:06+07:00',
36
+ # predicate: 'key1="value1" AND key2="value"', bucket: 'my-bucket', org: 'my-org')
37
+ #
38
+ # @example
39
+ # delete(DateTime.rfc3339('2019-02-03T04:05:06+07:00'), DateTime.rfc3339('2019-03-03T04:05:06+07:00'),
40
+ # predicate: 'key1="value1" AND key2="value"', bucket: 'my-bucket', org: 'my-org')
41
+ #
42
+ # @param [Object] start Start time of interval to delete data.
43
+ # The start could be represent by [Time], [DateTime] or [String] formatted as RFC3339.
44
+ # @param [Object] stop Stop time of interval to delete data
45
+ # The stop could be represent by [Time], [DateTime] or [String] formatted as RFC3339.
46
+ # @param [String] predicate InfluxQL-like predicate Stop time of interval to delete data
47
+ # @param [String] bucket specifies the bucket to remove data from
48
+ # @param [String] org specifies the organization to remove data from
49
+ def delete(start, stop, predicate: nil, bucket: nil, org: nil)
50
+ delete_request = InfluxDB2::DeletePredicateRequest.new(start: _to_rfc3339(start), stop: _to_rfc3339(stop),
51
+ predicate: predicate)
52
+
53
+ _delete(delete_request, bucket: bucket, org: org)
54
+ end
55
+
56
+ private
57
+
58
+ def _delete(delete_request, bucket: nil, org: nil)
59
+ bucket_param = bucket || @options[:bucket]
60
+ org_param = org || @options[:org]
61
+ _check('bucket', bucket_param)
62
+ _check('org', org_param)
63
+
64
+ uri = URI.parse(File.join(@options[:url], '/api/v2/delete'))
65
+ uri.query = URI.encode_www_form(org: org_param, bucket: bucket_param)
66
+
67
+ _post_json(delete_request.to_body.to_json, uri)
68
+ end
69
+
70
+ def _to_rfc3339(time)
71
+ if time.is_a?(String)
72
+ time
73
+ elsif time.is_a?(Time)
74
+ _to_rfc3339(time.to_datetime)
75
+ elsif time.is_a?(DateTime)
76
+ _to_rfc3339(time.rfc3339)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -19,6 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
  require 'csv'
21
21
  require 'base64'
22
+ require 'time'
22
23
 
23
24
  module InfluxDB2
24
25
  # This class represents Flux query error
@@ -50,6 +51,7 @@ module InfluxDB2
50
51
  @tables = {}
51
52
 
52
53
  @table_index = 0
54
+ @table_id = -1
53
55
  @start_new_table = false
54
56
  @table = nil
55
57
  @parsing_state_error = false
@@ -112,6 +114,7 @@ module InfluxDB2
112
114
  @tables[@table_index] = @table unless @stream
113
115
 
114
116
  @table_index += 1
117
+ @table_id = -1
115
118
  elsif @table.nil?
116
119
  raise FluxCsvParserError, 'Unable to parse CSV response. FluxTable definition was not found.'
117
120
  end
@@ -172,9 +175,10 @@ module InfluxDB2
172
175
  return
173
176
  end
174
177
 
175
- @current_index = csv[2].to_i
178
+ current_id = csv[2].to_i
179
+ @table_id = current_id if @table_id == -1
176
180
 
177
- if @current_index > (@table_index - 1)
181
+ if @table_id != current_id
178
182
  # create new table with previous column headers settings
179
183
  @flux_columns = @table.columns
180
184
  @table = InfluxDB2::FluxTable.new
@@ -185,6 +189,7 @@ module InfluxDB2
185
189
 
186
190
  @tables[@table_index] = @table unless @stream
187
191
  @table_index += 1
192
+ @table_id = current_id
188
193
  end
189
194
 
190
195
  flux_record = _parse_record(@table_index - 1, @table, csv)
@@ -5,22 +5,26 @@ module InfluxDB2
5
5
  attr_reader :code
6
6
  # Reference code unique to the error type
7
7
  attr_reader :reference
8
+ # The Retry-After header describes when to try the request again.
9
+ attr_reader :retry_after
8
10
 
9
- def initialize(message:, code:, reference:)
11
+ def initialize(message:, code:, reference:, retry_after:)
10
12
  super(message)
11
13
 
12
14
  @code = code
13
15
  @reference = reference
16
+ @retry_after = retry_after
14
17
  end
15
18
 
16
19
  def self.from_response(response)
17
20
  json = JSON.parse(response.body)
18
- obj = new(message: json['message'] || '', code: response.code, reference: json['code'] || '')
21
+ obj = new(message: json['message'] || '', code: response.code, reference: json['code'] || '',
22
+ retry_after: response['Retry-After'] || '')
19
23
  obj
20
24
  end
21
25
 
22
26
  def self.from_message(message)
23
- obj = new(message: message, code: '', reference: '')
27
+ obj = new(message: message, code: '', reference: '', retry_after: '')
24
28
  obj
25
29
  end
26
30
  end
@@ -0,0 +1,215 @@
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
+ # The delete predicate request.
17
+ class DeletePredicateRequest
18
+ # RFC3339Nano
19
+ attr_accessor :start
20
+
21
+ # RFC3339Nano
22
+ attr_accessor :stop
23
+
24
+ # InfluxQL-like delete statement
25
+ attr_accessor :predicate
26
+
27
+ # Attribute mapping from ruby-style variable name to JSON key.
28
+ def self.attribute_map
29
+ {
30
+ :'start' => :'start',
31
+ :'stop' => :'stop',
32
+ :'predicate' => :'predicate'
33
+ }
34
+ end
35
+
36
+ # Attribute type mapping.
37
+ def self.openapi_types
38
+ {
39
+ :'start' => :'DateTime',
40
+ :'stop' => :'DateTime',
41
+ :'predicate' => :'String'
42
+ }
43
+ end
44
+
45
+ # Initializes the object
46
+ # @param [Hash] attributes Model attributes in the form of hash
47
+ def initialize(attributes = {})
48
+ return unless attributes.is_a?(Hash)
49
+
50
+ # convert string to symbol for hash key
51
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
52
+
53
+ if attributes.has_key?(:'start')
54
+ self.start = attributes[:'start']
55
+ end
56
+
57
+ if attributes.has_key?(:'stop')
58
+ self.stop = attributes[:'stop']
59
+ end
60
+
61
+ if attributes.has_key?(:'predicate')
62
+ self.predicate = attributes[:'predicate']
63
+ end
64
+ end
65
+
66
+ # Show invalid properties with the reasons. Usually used together with valid?
67
+ # @return Array for valid properties with the reasons
68
+ def list_invalid_properties
69
+ invalid_properties = Array.new
70
+ if @start.nil?
71
+ invalid_properties.push('invalid value for "start", start cannot be nil.')
72
+ end
73
+
74
+ if @stop.nil?
75
+ invalid_properties.push('invalid value for "stop", stop cannot be nil.')
76
+ end
77
+
78
+ invalid_properties
79
+ end
80
+
81
+ # Check to see if the all the properties in the model are valid
82
+ # @return true if the model is valid
83
+ def valid?
84
+ return false if @start.nil?
85
+ return false if @stop.nil?
86
+ true
87
+ end
88
+
89
+ # Checks equality by comparing each attribute.
90
+ # @param [Object] Object to be compared
91
+ def ==(o)
92
+ return true if self.equal?(o)
93
+ self.class == o.class &&
94
+ start == o.start &&
95
+ stop == o.stop &&
96
+ predicate == o.predicate
97
+ end
98
+
99
+ # @see the `==` method
100
+ # @param [Object] Object to be compared
101
+ def eql?(o)
102
+ self == o
103
+ end
104
+
105
+ # Calculates hash code according to all attributes.
106
+ # @return [Fixnum] Hash code
107
+ def hash
108
+ [start, stop, predicate].hash
109
+ end
110
+
111
+ # Builds the object from hash
112
+ # @param [Hash] attributes Model attributes in the form of hash
113
+ # @return [Object] Returns the model itself
114
+ def build_from_hash(attributes)
115
+ return nil unless attributes.is_a?(Hash)
116
+ self.class.openapi_types.each_pair do |key, type|
117
+ if type =~ /\AArray<(.*)>/i
118
+ # check to ensure the input is an array given that the the attribute
119
+ # is documented as an array but the input is not
120
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
121
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
122
+ end
123
+ elsif !attributes[self.class.attribute_map[key]].nil?
124
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
125
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
126
+ end
127
+
128
+ self
129
+ end
130
+
131
+ # Deserializes the data based on type
132
+ # @param string type Data type
133
+ # @param string value Value to be deserialized
134
+ # @return [Object] Deserialized data
135
+ def _deserialize(type, value)
136
+ case type.to_sym
137
+ when :DateTime
138
+ DateTime.parse(value)
139
+ when :Date
140
+ Date.parse(value)
141
+ when :String
142
+ value.to_s
143
+ when :Integer
144
+ value.to_i
145
+ when :Float
146
+ value.to_f
147
+ when :BOOLEAN
148
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
149
+ true
150
+ else
151
+ false
152
+ end
153
+ when :Object
154
+ # generic object (usually a Hash), return directly
155
+ value
156
+ when /\AArray<(?<inner_type>.+)>\z/
157
+ inner_type = Regexp.last_match[:inner_type]
158
+ value.map { |v| _deserialize(inner_type, v) }
159
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
160
+ k_type = Regexp.last_match[:k_type]
161
+ v_type = Regexp.last_match[:v_type]
162
+ {}.tap do |hash|
163
+ value.each do |k, v|
164
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
165
+ end
166
+ end
167
+ else # model
168
+ temp_model = InfluxDB2.const_get(type).new
169
+ temp_model.build_from_hash(value)
170
+ end
171
+ end
172
+
173
+ # Returns the string representation of the object
174
+ # @return [String] String presentation of the object
175
+ def to_s
176
+ to_hash.to_s
177
+ end
178
+
179
+ # to_body is an alias to to_hash (backward compatibility)
180
+ # @return [Hash] Returns the object in the form of hash
181
+ def to_body
182
+ to_hash
183
+ end
184
+
185
+ # Returns the object in the form of hash
186
+ # @return [Hash] Returns the object in the form of hash
187
+ def to_hash
188
+ hash = {}
189
+ self.class.attribute_map.each_pair do |attr, param|
190
+ value = self.send(attr)
191
+ next if value.nil?
192
+ hash[param] = _to_hash(value)
193
+ end
194
+ hash
195
+ end
196
+
197
+ # Outputs non-array value in the form of hash
198
+ # For object, use to_hash. Otherwise, just return the value
199
+ # @param [Object] value Any valid value
200
+ # @return [Hash] Returns the value in the form of hash
201
+ def _to_hash(value)
202
+ if value.is_a?(Array)
203
+ value.compact.map { |v| _to_hash(v) }
204
+ elsif value.is_a?(Hash)
205
+ {}.tap do |hash|
206
+ value.each { |k, v| hash[k] = _to_hash(v) }
207
+ end
208
+ elsif value.respond_to? :to_hash
209
+ value.to_hash
210
+ else
211
+ value
212
+ end
213
+ end
214
+ end
215
+ end