influxdb-client 1.2.0.pre.618 → 1.2.0.pre.639

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aad438641f5726343f225cda984046fb1efc961b72be1fb5ba2fd0e6e16d1164
4
- data.tar.gz: 6464e15970dd4f6106f747e02e6b06483f769324524c58c9ea852bc158d9b5f5
3
+ metadata.gz: 172c1e4bb1951e9314cd52824e3f09fe64a5148dd9c2c89fa143d66cdfd3fd93
4
+ data.tar.gz: 3eed57dd71787b1341fe487ba3d03e20902a4f3fd97f690b56f0408b6778b1c3
5
5
  SHA512:
6
- metadata.gz: 256090a137253d1458ba53d3ca0ab8193c6bd7847e642c25219d57130fbc234eca2d049b54be5a6cfecee9b5b4a1d32b4401ef36c2a15a654181d227f73f3d12
7
- data.tar.gz: e1142f3894eb825fa341d5b85b1f3ee55d9a869a05d0c210d5b92c1428cf90a18d10366e6b9c6ce9b7613245fee1e8212fe923e3f36565c3712f0604f8457b7c
6
+ metadata.gz: eaf2473a3cbbac664343fbe2648d18331f5f0d5b0eac484d255a9fb11d7841ad4f970a08bf3a16987ce150938e86637e15f4c335b61092baa041ad629cd9d600
7
+ data.tar.gz: acafe6bc8ae5987b6bf0b0e57c3bb692d21ddfdb1263c5213b75c4f895f7a1966705d1d5cf3c8cb842e23616dc38f4d9b3c4b1b4920011498d30db671420adf1
data/CHANGELOG.md CHANGED
@@ -11,6 +11,7 @@
11
11
  ### Bugs
12
12
  1. [#22](https://github.com/influxdata/influxdb-client-ruby/pull/22): Fixed batch write
13
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
14
15
 
15
16
  ## 1.1.0 [2020-02-14]
16
17
 
@@ -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)
@@ -44,6 +56,8 @@ module InfluxDB2
44
56
  request = Net::HTTP::Post.new(uri.request_uri)
45
57
  request['Authorization'] = "Token #{@options[:token]}"
46
58
  request['User-Agent'] = "influxdb-client-ruby/#{InfluxDB2::VERSION}"
59
+ headers.each { |k, v| request[k] = v }
60
+
47
61
  request.body = payload
48
62
 
49
63
  begin
@@ -53,7 +67,7 @@ module InfluxDB2
53
67
  response
54
68
  when Net::HTTPRedirection then
55
69
  location = response['location']
56
- _post(payload, URI.parse(location), limit - 1)
70
+ _post(payload, URI.parse(location), limit: limit - 1, headers: headers)
57
71
  else
58
72
  raise InfluxError.from_response(response)
59
73
  end
@@ -62,6 +76,10 @@ module InfluxDB2
62
76
  end
63
77
  end
64
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
+
65
83
  def _check(key, value)
66
84
  raise ArgumentError, "The '#{key}' should be defined as argument or default option: #{@options}" if value.nil?
67
85
  end
@@ -64,7 +64,7 @@ module InfluxDB2
64
64
  uri = URI.parse(File.join(@options[:url], '/api/v2/delete'))
65
65
  uri.query = URI.encode_www_form(org: org_param, bucket: bucket_param)
66
66
 
67
- _post(delete_request.to_body.to_json, uri)
67
+ _post_json(delete_request.to_body.to_json, uri)
68
68
  end
69
69
 
70
70
  def _to_rfc3339(time)
@@ -73,7 +73,7 @@ module InfluxDB2
73
73
  uri = URI.parse(File.join(@options[:url], '/api/v2/query'))
74
74
  uri.query = URI.encode_www_form(org: org_param)
75
75
 
76
- _post(payload.to_body.to_json, uri)
76
+ _post_json(payload.to_body.to_json, uri)
77
77
  end
78
78
 
79
79
  def _generate_payload(query, dialect)
@@ -163,7 +163,7 @@ module InfluxDB2
163
163
  uri = URI.parse(File.join(@options[:url], '/api/v2/write'))
164
164
  uri.query = URI.encode_www_form(bucket: bucket_param, org: org_param, precision: precision_param.to_s)
165
165
 
166
- _post(payload, uri)
166
+ _post_text(payload, uri)
167
167
  end
168
168
 
169
169
  # Item for batching queue
@@ -112,7 +112,8 @@ class DeleteApiTest < MiniTest::Test
112
112
  body = '{"start":"2019-02-03T04:05:06+07:00","stop":"2019-04-03T04:05:06+07:00"}'
113
113
  headers = {
114
114
  'Authorization' => 'Token my-token',
115
- 'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}"
115
+ 'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
116
+ 'Content-Type' => 'application/json'
116
117
  }
117
118
  assert_requested(:post, 'http://localhost:9999/api/v2/delete?bucket=my-bucket&org=my-org',
118
119
  times: 1, body: body, headers: headers)
@@ -73,7 +73,7 @@ class QueryApiTest < MiniTest::Test
73
73
  assert_equal 'free', record1.field
74
74
  end
75
75
 
76
- def test_user_agent_header
76
+ def test_headers
77
77
  stub_request(:post, 'http://localhost:9999/api/v2/query?org=my-org')
78
78
  .to_return(body: SUCCESS_DATA)
79
79
 
@@ -87,7 +87,8 @@ class QueryApiTest < MiniTest::Test
87
87
 
88
88
  headers = {
89
89
  'Authorization' => 'Token my-token',
90
- 'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}"
90
+ 'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
91
+ 'Content-Type' => 'application/json'
91
92
  }
92
93
  assert_requested(:post, 'http://localhost:9999/api/v2/query?org=my-org',
93
94
  times: 1, headers: headers)
@@ -61,6 +61,7 @@ class WriteApiIntegrationTest < MiniTest::Test
61
61
  uri = URI.parse('http://localhost:9999/api/v2/query?org=my-org')
62
62
  request = Net::HTTP::Post.new(uri.request_uri)
63
63
  request['Authorization'] = 'Token my-token'
64
+ request[InfluxDB2::DefaultApi::HEADER_CONTENT_TYPE] = 'application/json'
64
65
  request.body = query.to_json
65
66
 
66
67
  http = Net::HTTP.new(uri.host, uri.port)
@@ -252,7 +252,7 @@ class WriteApiTest < MiniTest::Test
252
252
  assert_equal 'The time precision not_supported is not supported.', error.message
253
253
  end
254
254
 
255
- def test_user_agent_header
255
+ def test_headers
256
256
  stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
257
257
  .to_return(status: 204)
258
258
 
@@ -266,7 +266,8 @@ class WriteApiTest < MiniTest::Test
266
266
 
267
267
  headers = {
268
268
  'Authorization' => 'Token my-token',
269
- 'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}"
269
+ 'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
270
+ 'Content-Type' => 'text/plain'
270
271
  }
271
272
  assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
272
273
  times: 1, body: 'h2o,location=west value=33i 15', headers: headers)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.pre.618
4
+ version: 1.2.0.pre.639
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Bednar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-02 00:00:00.000000000 Z
11
+ date: 2020-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler