influxdb-client 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 +7 -0
- data/.circleci/config.yml +157 -0
- data/.circleci/setup-rubygems.sh +3 -0
- data/.codecov.yml +3 -0
- data/.github/PULL_REQUEST_TEMPLATE +8 -0
- data/.gitignore +16 -0
- data/.rubocop.yml +38 -0
- data/CHANGELOG.md +27 -0
- data/Gemfile +24 -0
- data/LICENSE +21 -0
- data/README.md +248 -0
- data/Rakefile +37 -0
- data/bin/generate-sources.sh +23 -0
- data/bin/influxdb-onboarding.sh +39 -0
- data/bin/influxdb-restart.sh +60 -0
- data/bin/pom.xml +34 -0
- data/bin/swagger.yml +9867 -0
- data/influxdb-client.gemspec +53 -0
- data/lib/influxdb2/client.rb +29 -0
- data/lib/influxdb2/client/client.rb +89 -0
- data/lib/influxdb2/client/default_api.rb +87 -0
- data/lib/influxdb2/client/delete_api.rb +80 -0
- data/lib/influxdb2/client/flux_csv_parser.rb +251 -0
- data/lib/influxdb2/client/flux_table.rb +99 -0
- data/lib/influxdb2/client/influx_error.rb +31 -0
- data/lib/influxdb2/client/models/delete_predicate_request.rb +215 -0
- data/lib/influxdb2/client/models/dialect.rb +317 -0
- data/lib/influxdb2/client/models/query.rb +284 -0
- data/lib/influxdb2/client/point.rb +215 -0
- data/lib/influxdb2/client/query_api.rb +93 -0
- data/lib/influxdb2/client/version.rb +23 -0
- data/lib/influxdb2/client/worker.rb +115 -0
- data/lib/influxdb2/client/write_api.rb +243 -0
- data/test/influxdb/client_test.rb +70 -0
- data/test/influxdb/delete_api_integration_test.rb +100 -0
- data/test/influxdb/delete_api_test.rb +121 -0
- data/test/influxdb/flux_csv_parser_test.rb +401 -0
- data/test/influxdb/point_test.rb +221 -0
- data/test/influxdb/query_api_integration_test.rb +58 -0
- data/test/influxdb/query_api_stream_test.rb +98 -0
- data/test/influxdb/query_api_test.rb +96 -0
- data/test/influxdb/write_api_batching_test.rb +292 -0
- data/test/influxdb/write_api_integration_test.rb +76 -0
- data/test/influxdb/write_api_test.rb +275 -0
- data/test/test_helper.rb +39 -0
- metadata +214 -0
@@ -0,0 +1,99 @@
|
|
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
|
+
module InfluxDB2
|
22
|
+
# This class represents the table structure of the Flux CSV Response.
|
23
|
+
# Ref: http://bit.ly/flux-spec#table
|
24
|
+
class FluxTable
|
25
|
+
def initialize
|
26
|
+
@columns = []
|
27
|
+
@records = []
|
28
|
+
end
|
29
|
+
attr_reader :columns, :records
|
30
|
+
|
31
|
+
# A table's group key is subset of the entire columns dataset that assigned to the table.
|
32
|
+
# As such, all records within a table will have the same values for each column that is part of the group key.
|
33
|
+
def group_key
|
34
|
+
columns = []
|
35
|
+
|
36
|
+
@columns.each do |column|
|
37
|
+
columns.push(column) if column.group
|
38
|
+
end
|
39
|
+
|
40
|
+
columns
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# A record is a tuple of values. Each record in the table represents a single point in the series.
|
45
|
+
# Ref: http://bit.ly/flux-spec#record
|
46
|
+
class FluxRecord
|
47
|
+
# @param [Integer] table the index of table which contains the record
|
48
|
+
# @param [Hash] values tuple of values
|
49
|
+
def initialize(table, values: nil)
|
50
|
+
@table = table
|
51
|
+
@values = values || {}
|
52
|
+
end
|
53
|
+
attr_reader :table, :values
|
54
|
+
attr_writer :table
|
55
|
+
|
56
|
+
# @return [Time] the inclusive lower time bound of all records
|
57
|
+
def start
|
58
|
+
values['_start']
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Time] the exclusive upper time bound of all records
|
62
|
+
def stop
|
63
|
+
values['_stop']
|
64
|
+
end
|
65
|
+
|
66
|
+
# @return [Time] the time of the record
|
67
|
+
def time
|
68
|
+
values['_time']
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [Object] the value of the record
|
72
|
+
def value
|
73
|
+
values['_value']
|
74
|
+
end
|
75
|
+
|
76
|
+
# @return [String] value with key "_field"
|
77
|
+
def field
|
78
|
+
values['_field']
|
79
|
+
end
|
80
|
+
|
81
|
+
# @return [String] value with key "_measurement"
|
82
|
+
def measurement
|
83
|
+
values['_measurement']
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# This class represents a column header specification of FluxTable.
|
88
|
+
class FluxColumn
|
89
|
+
def initialize(index: nil, label: nil, data_type: nil, group: nil, default_value: nil)
|
90
|
+
@index = index
|
91
|
+
@label = label
|
92
|
+
@data_type = data_type
|
93
|
+
@group = group
|
94
|
+
@default_value = default_value
|
95
|
+
end
|
96
|
+
attr_reader :index, :label, :data_type, :group, :default_value
|
97
|
+
attr_writer :index, :label, :data_type, :group, :default_value
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module InfluxDB2
|
2
|
+
# InfluxError that is raised during HTTP communication.
|
3
|
+
class InfluxError < StandardError
|
4
|
+
# HTTP status code
|
5
|
+
attr_reader :code
|
6
|
+
# Reference code unique to the error type
|
7
|
+
attr_reader :reference
|
8
|
+
# The Retry-After header describes when to try the request again.
|
9
|
+
attr_reader :retry_after
|
10
|
+
|
11
|
+
def initialize(message:, code:, reference:, retry_after:)
|
12
|
+
super(message)
|
13
|
+
|
14
|
+
@code = code
|
15
|
+
@reference = reference
|
16
|
+
@retry_after = retry_after
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.from_response(response)
|
20
|
+
json = JSON.parse(response.body)
|
21
|
+
obj = new(message: json['message'] || '', code: response.code, reference: json['code'] || '',
|
22
|
+
retry_after: response['Retry-After'] || '')
|
23
|
+
obj
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.from_message(message)
|
27
|
+
obj = new(message: message, code: '', reference: '', retry_after: '')
|
28
|
+
obj
|
29
|
+
end
|
30
|
+
end
|
31
|
+
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
|
@@ -0,0 +1,317 @@
|
|
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
|
+
# Dialect are options to change the default CSV output format; https://www.w3.org/TR/2015/REC-tabular-metadata-20151217/#dialect-descriptions
|
17
|
+
class Dialect
|
18
|
+
# If true, the results will contain a header row
|
19
|
+
attr_accessor :header
|
20
|
+
|
21
|
+
# Separator between cells; the default is ,
|
22
|
+
attr_accessor :delimiter
|
23
|
+
|
24
|
+
# Https://www.w3.org/TR/2015/REC-tabular-data-model-20151217/#columns
|
25
|
+
attr_accessor :annotations
|
26
|
+
|
27
|
+
# Character prefixed to comment strings
|
28
|
+
attr_accessor :comment_prefix
|
29
|
+
|
30
|
+
# Format of timestamps
|
31
|
+
attr_accessor :date_time_format
|
32
|
+
|
33
|
+
class EnumAttributeValidator
|
34
|
+
attr_reader :datatype
|
35
|
+
attr_reader :allowable_values
|
36
|
+
|
37
|
+
def initialize(datatype, allowable_values)
|
38
|
+
@allowable_values = allowable_values.map do |value|
|
39
|
+
case datatype.to_s
|
40
|
+
when /Integer/i
|
41
|
+
value.to_i
|
42
|
+
when /Float/i
|
43
|
+
value.to_f
|
44
|
+
else
|
45
|
+
value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def valid?(value)
|
51
|
+
!value || allowable_values.include?(value)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
56
|
+
def self.attribute_map
|
57
|
+
{
|
58
|
+
:'header' => :'header',
|
59
|
+
:'delimiter' => :'delimiter',
|
60
|
+
:'annotations' => :'annotations',
|
61
|
+
:'comment_prefix' => :'commentPrefix',
|
62
|
+
:'date_time_format' => :'dateTimeFormat'
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
# Attribute type mapping.
|
67
|
+
def self.openapi_types
|
68
|
+
{
|
69
|
+
:'header' => :'BOOLEAN',
|
70
|
+
:'delimiter' => :'String',
|
71
|
+
:'annotations' => :'Array<String>',
|
72
|
+
:'comment_prefix' => :'String',
|
73
|
+
:'date_time_format' => :'String'
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
# Initializes the object
|
78
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
79
|
+
def initialize(attributes = {})
|
80
|
+
return unless attributes.is_a?(Hash)
|
81
|
+
|
82
|
+
# convert string to symbol for hash key
|
83
|
+
attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
|
84
|
+
|
85
|
+
if attributes.has_key?(:'header')
|
86
|
+
self.header = attributes[:'header']
|
87
|
+
else
|
88
|
+
self.header = true
|
89
|
+
end
|
90
|
+
|
91
|
+
if attributes.has_key?(:'delimiter')
|
92
|
+
self.delimiter = attributes[:'delimiter']
|
93
|
+
else
|
94
|
+
self.delimiter = ','
|
95
|
+
end
|
96
|
+
|
97
|
+
if attributes.has_key?(:'annotations')
|
98
|
+
if (value = attributes[:'annotations']).is_a?(Array)
|
99
|
+
self.annotations = value
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
if attributes.has_key?(:'commentPrefix')
|
104
|
+
self.comment_prefix = attributes[:'commentPrefix']
|
105
|
+
else
|
106
|
+
self.comment_prefix = '#'
|
107
|
+
end
|
108
|
+
|
109
|
+
if attributes.has_key?(:'dateTimeFormat')
|
110
|
+
self.date_time_format = attributes[:'dateTimeFormat']
|
111
|
+
else
|
112
|
+
self.date_time_format = 'RFC3339'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
117
|
+
# @return Array for valid properties with the reasons
|
118
|
+
def list_invalid_properties
|
119
|
+
invalid_properties = Array.new
|
120
|
+
if !@delimiter.nil? && @delimiter.to_s.length > 1
|
121
|
+
invalid_properties.push('invalid value for "delimiter", the character length must be smaller than or equal to 1.')
|
122
|
+
end
|
123
|
+
|
124
|
+
if !@delimiter.nil? && @delimiter.to_s.length < 1
|
125
|
+
invalid_properties.push('invalid value for "delimiter", the character length must be great than or equal to 1.')
|
126
|
+
end
|
127
|
+
|
128
|
+
if !@comment_prefix.nil? && @comment_prefix.to_s.length > 1
|
129
|
+
invalid_properties.push('invalid value for "comment_prefix", the character length must be smaller than or equal to 1.')
|
130
|
+
end
|
131
|
+
|
132
|
+
if !@comment_prefix.nil? && @comment_prefix.to_s.length < 0
|
133
|
+
invalid_properties.push('invalid value for "comment_prefix", the character length must be great than or equal to 0.')
|
134
|
+
end
|
135
|
+
|
136
|
+
invalid_properties
|
137
|
+
end
|
138
|
+
|
139
|
+
# Check to see if the all the properties in the model are valid
|
140
|
+
# @return true if the model is valid
|
141
|
+
def valid?
|
142
|
+
return false if !@delimiter.nil? && @delimiter.to_s.length > 1
|
143
|
+
return false if !@delimiter.nil? && @delimiter.to_s.length < 1
|
144
|
+
return false if !@comment_prefix.nil? && @comment_prefix.to_s.length > 1
|
145
|
+
return false if !@comment_prefix.nil? && @comment_prefix.to_s.length < 0
|
146
|
+
date_time_format_validator = EnumAttributeValidator.new('String', ['RFC3339', 'RFC3339Nano'])
|
147
|
+
return false unless date_time_format_validator.valid?(@date_time_format)
|
148
|
+
true
|
149
|
+
end
|
150
|
+
|
151
|
+
# Custom attribute writer method with validation
|
152
|
+
# @param [Object] delimiter Value to be assigned
|
153
|
+
def delimiter=(delimiter)
|
154
|
+
if !delimiter.nil? && delimiter.to_s.length > 1
|
155
|
+
fail ArgumentError, 'invalid value for "delimiter", the character length must be smaller than or equal to 1.'
|
156
|
+
end
|
157
|
+
|
158
|
+
if !delimiter.nil? && delimiter.to_s.length < 1
|
159
|
+
fail ArgumentError, 'invalid value for "delimiter", the character length must be great than or equal to 1.'
|
160
|
+
end
|
161
|
+
|
162
|
+
@delimiter = delimiter
|
163
|
+
end
|
164
|
+
|
165
|
+
# Custom attribute writer method with validation
|
166
|
+
# @param [Object] comment_prefix Value to be assigned
|
167
|
+
def comment_prefix=(comment_prefix)
|
168
|
+
if !comment_prefix.nil? && comment_prefix.to_s.length > 1
|
169
|
+
fail ArgumentError, 'invalid value for "comment_prefix", the character length must be smaller than or equal to 1.'
|
170
|
+
end
|
171
|
+
|
172
|
+
if !comment_prefix.nil? && comment_prefix.to_s.length < 0
|
173
|
+
fail ArgumentError, 'invalid value for "comment_prefix", the character length must be great than or equal to 0.'
|
174
|
+
end
|
175
|
+
|
176
|
+
@comment_prefix = comment_prefix
|
177
|
+
end
|
178
|
+
|
179
|
+
# Custom attribute writer method checking allowed values (enum).
|
180
|
+
# @param [Object] date_time_format Object to be assigned
|
181
|
+
def date_time_format=(date_time_format)
|
182
|
+
validator = EnumAttributeValidator.new('String', ['RFC3339', 'RFC3339Nano'])
|
183
|
+
unless validator.valid?(date_time_format)
|
184
|
+
fail ArgumentError, 'invalid value for "date_time_format", must be one of #{validator.allowable_values}.'
|
185
|
+
end
|
186
|
+
@date_time_format = date_time_format
|
187
|
+
end
|
188
|
+
|
189
|
+
# Checks equality by comparing each attribute.
|
190
|
+
# @param [Object] Object to be compared
|
191
|
+
def ==(o)
|
192
|
+
return true if self.equal?(o)
|
193
|
+
self.class == o.class &&
|
194
|
+
header == o.header &&
|
195
|
+
delimiter == o.delimiter &&
|
196
|
+
annotations == o.annotations &&
|
197
|
+
comment_prefix == o.comment_prefix &&
|
198
|
+
date_time_format == o.date_time_format
|
199
|
+
end
|
200
|
+
|
201
|
+
# @see the `==` method
|
202
|
+
# @param [Object] Object to be compared
|
203
|
+
def eql?(o)
|
204
|
+
self == o
|
205
|
+
end
|
206
|
+
|
207
|
+
# Calculates hash code according to all attributes.
|
208
|
+
# @return [Fixnum] Hash code
|
209
|
+
def hash
|
210
|
+
[header, delimiter, annotations, comment_prefix, date_time_format].hash
|
211
|
+
end
|
212
|
+
|
213
|
+
# Builds the object from hash
|
214
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
215
|
+
# @return [Object] Returns the model itself
|
216
|
+
def build_from_hash(attributes)
|
217
|
+
return nil unless attributes.is_a?(Hash)
|
218
|
+
self.class.openapi_types.each_pair do |key, type|
|
219
|
+
if type =~ /\AArray<(.*)>/i
|
220
|
+
# check to ensure the input is an array given that the the attribute
|
221
|
+
# is documented as an array but the input is not
|
222
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
223
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
224
|
+
end
|
225
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
226
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
227
|
+
end # or else data not found in attributes(hash), not an issue as the data can be optional
|
228
|
+
end
|
229
|
+
|
230
|
+
self
|
231
|
+
end
|
232
|
+
|
233
|
+
# Deserializes the data based on type
|
234
|
+
# @param string type Data type
|
235
|
+
# @param string value Value to be deserialized
|
236
|
+
# @return [Object] Deserialized data
|
237
|
+
def _deserialize(type, value)
|
238
|
+
case type.to_sym
|
239
|
+
when :DateTime
|
240
|
+
DateTime.parse(value)
|
241
|
+
when :Date
|
242
|
+
Date.parse(value)
|
243
|
+
when :String
|
244
|
+
value.to_s
|
245
|
+
when :Integer
|
246
|
+
value.to_i
|
247
|
+
when :Float
|
248
|
+
value.to_f
|
249
|
+
when :BOOLEAN
|
250
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
251
|
+
true
|
252
|
+
else
|
253
|
+
false
|
254
|
+
end
|
255
|
+
when :Object
|
256
|
+
# generic object (usually a Hash), return directly
|
257
|
+
value
|
258
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
259
|
+
inner_type = Regexp.last_match[:inner_type]
|
260
|
+
value.map { |v| _deserialize(inner_type, v) }
|
261
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
262
|
+
k_type = Regexp.last_match[:k_type]
|
263
|
+
v_type = Regexp.last_match[:v_type]
|
264
|
+
{}.tap do |hash|
|
265
|
+
value.each do |k, v|
|
266
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
else # model
|
270
|
+
temp_model = InfluxDB2.const_get(type).new
|
271
|
+
temp_model.build_from_hash(value)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
# Returns the string representation of the object
|
276
|
+
# @return [String] String presentation of the object
|
277
|
+
def to_s
|
278
|
+
to_hash.to_s
|
279
|
+
end
|
280
|
+
|
281
|
+
# to_body is an alias to to_hash (backward compatibility)
|
282
|
+
# @return [Hash] Returns the object in the form of hash
|
283
|
+
def to_body
|
284
|
+
to_hash
|
285
|
+
end
|
286
|
+
|
287
|
+
# Returns the object in the form of hash
|
288
|
+
# @return [Hash] Returns the object in the form of hash
|
289
|
+
def to_hash
|
290
|
+
hash = {}
|
291
|
+
self.class.attribute_map.each_pair do |attr, param|
|
292
|
+
value = self.send(attr)
|
293
|
+
next if value.nil?
|
294
|
+
hash[param] = _to_hash(value)
|
295
|
+
end
|
296
|
+
hash
|
297
|
+
end
|
298
|
+
|
299
|
+
# Outputs non-array value in the form of hash
|
300
|
+
# For object, use to_hash. Otherwise, just return the value
|
301
|
+
# @param [Object] value Any valid value
|
302
|
+
# @return [Hash] Returns the value in the form of hash
|
303
|
+
def _to_hash(value)
|
304
|
+
if value.is_a?(Array)
|
305
|
+
value.compact.map { |v| _to_hash(v) }
|
306
|
+
elsif value.is_a?(Hash)
|
307
|
+
{}.tap do |hash|
|
308
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
309
|
+
end
|
310
|
+
elsif value.respond_to? :to_hash
|
311
|
+
value.to_hash
|
312
|
+
else
|
313
|
+
value
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|