influxdb-client 1.0.0.pre.104 → 1.0.0.pre.108

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: 5ca23c627175392169979db1cc4471ce9a78024773876bc729c7dea1e87cd759
4
- data.tar.gz: d61490a327935ecc02f13835ea95365f263bbd1afe9ff4f796193ec0fb55146b
3
+ metadata.gz: df08f52880c0709b679a2871ced126914d75fcfde22a0b29875e05cfecc40392
4
+ data.tar.gz: 6f18b94e41549768e3c16705d73be76ec389ab92a2e789f877076df284f8a7a5
5
5
  SHA512:
6
- metadata.gz: 022d330869720c7feb99adc0ea0f633bc50f70c8e8a4815cb5787860eb6c67c820bbd6abaee199fd512cf30b998a765bb0ea05581217f39b5d193e8f222827b5
7
- data.tar.gz: 584f77afc19bb8d1bb9a3ab368fe807323eeb0badc938bf946016748045d73fa9dcbdfb7a700d7f8cd5f3df9ec9fecabeef9d5265d32d39bc467cd42b57ae75c
6
+ metadata.gz: aaee4d0f21ee6975aa173d71d0564a7470eb6539a7f90a25ad18516d39979748bd61b6a914fe9758d47e46ec347cf6fe0beda26ecf7a2e9b3e3c048c70db6c27
7
+ data.tar.gz: ce56b97581e0ec783d5cd6478870c66d0f9040dc48fcad15478b4dd97ea908d20913ababdd5242fb491f533ec8cb61cf52e87fe77c7fde750cc462fa44a57d61
data/README.md CHANGED
@@ -32,7 +32,7 @@ gem install influxdb-client --pre
32
32
  Use **InfluxDB::Client** to create a client connected to a running InfluxDB 2 instance.
33
33
 
34
34
  ```ruby
35
- client = InfluxDB::Client.new('http://localhost:9999', 'my-token')
35
+ client = InfluxDB::Client.new('https://localhost:9999', 'my-token')
36
36
  ```
37
37
 
38
38
  #### Client Options
@@ -46,9 +46,10 @@ client = InfluxDB::Client.new('http://localhost:9999', 'my-token')
46
46
  | write_timeout | Number of seconds to wait for one block of data to be written | Integer | 10 |
47
47
  | read_timeout | Number of seconds to wait for one block of data to be read | Integer | 10 |
48
48
  | max_redirect_count | Maximal number of followed HTTP redirects | Integer | 10 |
49
+ | use_ssl | Turn on/off SSL for HTTP communication | bool | true |
49
50
 
50
51
  ```ruby
51
- client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
52
+ client = InfluxDB::Client.new('https://localhost:9999', 'my-token',
52
53
  bucket: 'my-bucket',
53
54
  org: 'my-org',
54
55
  precision: InfluxDB::WritePrecision::NANOSECOND)
@@ -57,7 +58,7 @@ client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
57
58
  ### Writing data
58
59
 
59
60
  ```ruby
60
- client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
61
+ client = InfluxDB::Client.new('https://localhost:9999', 'my-token',
61
62
  bucket: 'my-bucket',
62
63
  org: 'my-org',
63
64
  precision: InfluxDB::WritePrecision::NANOSECOND)
@@ -70,7 +71,7 @@ write_api.write(data: 'h2o,location=west value=33i 15')
70
71
 
71
72
  Configure default time precision:
72
73
  ```ruby
73
- client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
74
+ client = InfluxDB::Client.new('https://localhost:9999', 'my-token',
74
75
  bucket: 'my-bucket',
75
76
  org: 'my-org',
76
77
  precision: InfluxDB::WritePrecision::NANOSECOND)
@@ -78,7 +79,7 @@ client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
78
79
 
79
80
  Configure precision per write:
80
81
  ```ruby
81
- client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
82
+ client = InfluxDB::Client.new('https://localhost:9999', 'my-token',
82
83
  bucket: 'my-bucket',
83
84
  org: 'my-org')
84
85
 
@@ -96,7 +97,7 @@ Allowed values for precision are:
96
97
 
97
98
  Default `bucket` and `organization` destination are configured via `InfluxDB::Client`:
98
99
  ```ruby
99
- client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
100
+ client = InfluxDB::Client.new('https://localhost:9999', 'my-token',
100
101
  bucket: 'my-bucket',
101
102
  org: 'my-org')
102
103
  ```
@@ -104,7 +105,7 @@ client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
104
105
  but there is also possibility to override configuration per write:
105
106
 
106
107
  ```ruby
107
- client = InfluxDB::Client.new('http://localhost:9999', 'my-token')
108
+ client = InfluxDB::Client.new('https://localhost:9999', 'my-token')
108
109
 
109
110
  write_api = client.create_write_api
110
111
  write_api.write(data: 'h2o,location=west value=33i 15', bucket: 'production-data', org: 'customer-1')
@@ -120,7 +121,7 @@ The data could be written as:
120
121
  1. `Array` of above items
121
122
 
122
123
  ```ruby
123
- client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
124
+ client = InfluxDB::Client.new('https://localhost:9999', 'my-token',
124
125
  bucket: 'my-bucket',
125
126
  org: 'my-org',
126
127
  precision: InfluxDB::WritePrecision::NANOSECOND)
@@ -28,10 +28,10 @@ module InfluxDB
28
28
  # Instantiate a new InfluxDB client.
29
29
  #
30
30
  # @example Instantiate a client.
31
- # InfluxDBClient::Client.new(url: 'http://localhost:9999', token: 'my-token')
31
+ # InfluxDBClient::Client.new(url: 'https://localhost:9999', token: 'my-token')
32
32
  #
33
33
  # @param [Hash] options The options to be used by the client.
34
- # @param [String] url InfluxDB URL to connect to (ex. http://localhost:9999).
34
+ # @param [String] url InfluxDB URL to connect to (ex. https://localhost:9999).
35
35
  # @param [String] token Access Token used for authenticating/authorizing the InfluxDB request sent by client.
36
36
  #
37
37
  # @option options [String] :bucket the default destination bucket for writes
@@ -41,6 +41,7 @@ module InfluxDB
41
41
  # @option options [Integer] :write_timeout Number of seconds to wait for one block of data to be written
42
42
  # @option options [Integer] :read_timeout Number of seconds to wait for one block of data to be read
43
43
  # @option options [Integer] :max_redirect_count Maximal number of followed HTTP redirects
44
+ # @option options [bool] :use_ssl Turn on/off SSL for HTTP communication
44
45
  # the body line-protocol
45
46
  def initialize(url, token, options = nil)
46
47
  @options = options ? options.dup : {}
@@ -19,11 +19,20 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module InfluxDB
22
+ # Precision constants.
23
+ #
22
24
  class WritePrecision
23
25
  SECOND = 's'.freeze
24
26
  MILLISECOND = 'ms'.freeze
25
27
  MICROSECOND = 'us'.freeze
26
28
  NANOSECOND = 'ns'.freeze
29
+
30
+ def get_from_value(value)
31
+ constants = WritePrecision.constants.select { |c| WritePrecision.const_get(c) == value }
32
+ raise "The time precision #{value} is not supported." if constants.empty?
33
+
34
+ value
35
+ end
27
36
  end
28
37
 
29
38
  # Write time series data into InfluxDB.
@@ -96,7 +105,7 @@ module InfluxDB
96
105
  http.open_timeout = @options[:open_timeout] || DEFAULT_TIMEOUT
97
106
  http.write_timeout = @options[:write_timeout] || DEFAULT_TIMEOUT if Net::HTTP.method_defined? :write_timeout
98
107
  http.read_timeout = @options[:read_timeout] || DEFAULT_TIMEOUT
99
- http.use_ssl = @options[:use_ssl] || false
108
+ http.use_ssl = @options[:use_ssl].nil? ? true : @options[:use_ssl]
100
109
 
101
110
  request = Net::HTTP::Post.new(uri.request_uri)
102
111
  request['Authorization'] = "Token #{@options[:token]}"
@@ -30,7 +30,8 @@ class WriteApiIntegrationTest < MiniTest::Test
30
30
  client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
31
31
  bucket: 'my-bucket',
32
32
  org: 'my-org',
33
- precision: InfluxDB::WritePrecision::NANOSECOND)
33
+ precision: InfluxDB::WritePrecision::NANOSECOND,
34
+ use_ssl: false)
34
35
 
35
36
  now = Time.now.utc
36
37
 
@@ -60,7 +60,8 @@ class WriteApiTest < MiniTest::Test
60
60
  client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
61
61
  bucket: 'my-bucket',
62
62
  org: 'my-org',
63
- precision: InfluxDB::WritePrecision::NANOSECOND)
63
+ precision: InfluxDB::WritePrecision::NANOSECOND,
64
+ use_ssl: false)
64
65
 
65
66
  client.create_write_api.write(data: 'h2o,location=west value=33i 15')
66
67
 
@@ -74,7 +75,8 @@ class WriteApiTest < MiniTest::Test
74
75
  client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
75
76
  bucket: 'my-bucket',
76
77
  org: 'my-org',
77
- precision: InfluxDB::WritePrecision::NANOSECOND)
78
+ precision: InfluxDB::WritePrecision::NANOSECOND,
79
+ use_ssl: false)
78
80
 
79
81
  client.create_write_api.write(data: InfluxDB::Point.new(name: 'h2o')
80
82
  .add_tag('location', 'europe')
@@ -90,7 +92,8 @@ class WriteApiTest < MiniTest::Test
90
92
  client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
91
93
  bucket: 'my-bucket',
92
94
  org: 'my-org',
93
- precision: InfluxDB::WritePrecision::NANOSECOND)
95
+ precision: InfluxDB::WritePrecision::NANOSECOND,
96
+ use_ssl: false)
94
97
 
95
98
  client.create_write_api.write(data: { name: 'h2o',
96
99
  tags: { host: 'aws', region: 'us' },
@@ -107,7 +110,8 @@ class WriteApiTest < MiniTest::Test
107
110
  client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
108
111
  bucket: 'my-bucket',
109
112
  org: 'my-org',
110
- precision: InfluxDB::WritePrecision::NANOSECOND)
113
+ precision: InfluxDB::WritePrecision::NANOSECOND,
114
+ use_ssl: false)
111
115
 
112
116
  point = InfluxDB::Point.new(name: 'h2o')
113
117
  .add_tag('location', 'europe')
@@ -131,7 +135,8 @@ class WriteApiTest < MiniTest::Test
131
135
  client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
132
136
  bucket: 'my-bucket',
133
137
  org: 'my-org',
134
- precision: InfluxDB::WritePrecision::NANOSECOND)
138
+ precision: InfluxDB::WritePrecision::NANOSECOND,
139
+ use_ssl: false)
135
140
 
136
141
  client.create_write_api.write(data: 'h2o,location=west value=33i 15')
137
142
 
@@ -162,7 +167,8 @@ class WriteApiTest < MiniTest::Test
162
167
  client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
163
168
  bucket: 'my-bucket',
164
169
  org: 'my-org',
165
- precision: InfluxDB::WritePrecision::NANOSECOND)
170
+ precision: InfluxDB::WritePrecision::NANOSECOND,
171
+ use_ssl: false)
166
172
 
167
173
  error = assert_raises InfluxDB::InfluxError do
168
174
  client.create_write_api.write(data: 'h2o,location=west value=33i 15')
@@ -184,7 +190,8 @@ class WriteApiTest < MiniTest::Test
184
190
  client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
185
191
  bucket: 'my-bucket',
186
192
  org: 'my-org',
187
- precision: InfluxDB::WritePrecision::NANOSECOND)
193
+ precision: InfluxDB::WritePrecision::NANOSECOND,
194
+ use_ssl: false)
188
195
 
189
196
  client.create_write_api.write(data: 'h2o,location=west value=33i 15')
190
197
 
@@ -203,7 +210,8 @@ class WriteApiTest < MiniTest::Test
203
210
  bucket: 'my-bucket',
204
211
  org: 'my-org',
205
212
  precision: InfluxDB::WritePrecision::NANOSECOND,
206
- max_redirect_count: 5)
213
+ max_redirect_count: 5,
214
+ use_ssl: false)
207
215
 
208
216
  error = assert_raises InfluxDB::InfluxError do
209
217
  client.create_write_api.write(data: 'h2o,location=west value=33i 15')
@@ -211,4 +219,17 @@ class WriteApiTest < MiniTest::Test
211
219
 
212
220
  assert_equal 'Too many HTTP redirects. Exceeded limit: 5', error.message
213
221
  end
222
+
223
+ def test_write_precision_constant
224
+ assert_equal InfluxDB::WritePrecision::SECOND, InfluxDB::WritePrecision.new.get_from_value('s')
225
+ assert_equal InfluxDB::WritePrecision::MILLISECOND, InfluxDB::WritePrecision.new.get_from_value('ms')
226
+ assert_equal InfluxDB::WritePrecision::MICROSECOND, InfluxDB::WritePrecision.new.get_from_value('us')
227
+ assert_equal InfluxDB::WritePrecision::NANOSECOND, InfluxDB::WritePrecision.new.get_from_value('ns')
228
+
229
+ error = assert_raises RuntimeError do
230
+ InfluxDB::WritePrecision.new.get_from_value('not_supported')
231
+ end
232
+
233
+ assert_equal 'The time precision not_supported is not supported.', error.message
234
+ end
214
235
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.104
4
+ version: 1.0.0.pre.108
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Bednar