influxdb-client 2.3.0 → 2.4.0.pre.4821
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +21 -21
- data/lib/influxdb-client.rb +7 -0
- data/lib/influxdb2/client/client.rb +7 -0
- data/lib/influxdb2/client/default_api.rb +8 -13
- data/lib/influxdb2/client/delete_api.rb +1 -1
- data/lib/influxdb2/client/flux_csv_parser.rb +21 -2
- data/lib/influxdb2/client/health_api.rb +1 -1
- data/lib/influxdb2/client/invocable_scripts_api.rb +147 -0
- data/lib/influxdb2/client/models/script.rb +299 -0
- data/lib/influxdb2/client/models/script_create_request.rb +259 -0
- data/lib/influxdb2/client/models/script_invocation_params.rb +210 -0
- data/lib/influxdb2/client/models/script_language.rb +36 -0
- data/lib/influxdb2/client/models/script_update_request.rb +229 -0
- data/lib/influxdb2/client/models/scripts.rb +212 -0
- data/lib/influxdb2/client/ping_api.rb +1 -1
- data/lib/influxdb2/client/query_api.rb +2 -2
- data/lib/influxdb2/client/version.rb +1 -1
- data/test/influxdb/flux_csv_parser_test.rb +17 -0
- data/test/influxdb/invocable_scripts_api_test.rb +41 -0
- metadata +14 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5ef02d36ae695e1bdaa6cba01ce9f6a383295cabe4af6c532d89a1a9a44577d
|
4
|
+
data.tar.gz: 6e77b330945e1d15f1df2ce5ac387159c3b886a5e8295450b700770b09fdc415
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fca02aadc5268810c5a91a76c11acf847e4c594c6fcb1f25e618e40ec69486794e8e7190072f86a3ecb5ace26129a0be21b17fd6f8f206a30c85f55d2fafe1b2
|
7
|
+
data.tar.gz: 44f9dfd7eb9e549533f59c71f866a464c87b57b673188349eaf41c321547c2ba3bbc0ad57e86daf1975d5fc4fd5c7389a113630dd2863990cd3651861d174499
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
[](https://github.com/influxdata/influxdb-client-ruby/pulls)
|
9
9
|
[](https://www.influxdata.com/slack)
|
10
10
|
|
11
|
-
This repository contains the reference Ruby client for the InfluxDB 2.
|
11
|
+
This repository contains the reference Ruby client for the InfluxDB 2.x.
|
12
12
|
|
13
13
|
#### Note: Use this client library with InfluxDB 2.x and InfluxDB 1.8+ ([see details](#influxdb-18-api-compatibility)). For connecting to InfluxDB 1.7 or earlier instances, use the [influxdb-ruby](https://github.com/influxdata/influxdb-ruby) client library.
|
14
14
|
|
@@ -31,14 +31,14 @@ This repository contains the reference Ruby client for the InfluxDB 2.0.
|
|
31
31
|
|
32
32
|
This section contains links to the client library documentation.
|
33
33
|
|
34
|
-
* [Product documentation](https://docs.influxdata.com/influxdb/
|
34
|
+
* [Product documentation](https://docs.influxdata.com/influxdb/latest/api-guide/client-libraries/), [Getting Started](#installation)
|
35
35
|
* [Examples](examples)
|
36
36
|
* [API Reference](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2.html)
|
37
37
|
* [Changelog](CHANGELOG.md)
|
38
38
|
|
39
39
|
## Features
|
40
40
|
|
41
|
-
InfluxDB 2.
|
41
|
+
InfluxDB 2.x client consists of two packages
|
42
42
|
|
43
43
|
- `influxdb-client`
|
44
44
|
- Querying data using the Flux language
|
@@ -46,7 +46,7 @@ InfluxDB 2.0 client consists of two packages
|
|
46
46
|
- batched in chunks on background
|
47
47
|
- automatic retries on write failures
|
48
48
|
- `influxdb-client-apis`
|
49
|
-
- provides all other InfluxDB 2.
|
49
|
+
- provides all other InfluxDB 2.x APIs for managing
|
50
50
|
- buckets
|
51
51
|
- labels
|
52
52
|
- authorizations
|
@@ -180,7 +180,7 @@ result[0].records.each { |record| puts "#{record.time} #{record.measurement}: #{
|
|
180
180
|
```
|
181
181
|
|
182
182
|
### Writing data
|
183
|
-
The [WriteApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/write_api.rb) supports synchronous and batching writes into InfluxDB 2.
|
183
|
+
The [WriteApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/write_api.rb) supports synchronous and batching writes into InfluxDB 2.x. In default api uses synchronous write. To enable batching you can use WriteOption.
|
184
184
|
|
185
185
|
```ruby
|
186
186
|
client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
|
@@ -324,7 +324,7 @@ write_api.write(data: InfluxDB2::Point.new(name: 'h2o')
|
|
324
324
|
|
325
325
|
### Delete data
|
326
326
|
|
327
|
-
The [DeleteApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/delete_api.rb) supports deletes [points](https://
|
327
|
+
The [DeleteApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/delete_api.rb) supports deletes [points](https://docs.influxdata.com/influxdb/latest/reference/key-concepts/data-elements/#point) from an InfluxDB bucket.
|
328
328
|
|
329
329
|
```ruby
|
330
330
|
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
@@ -347,16 +347,16 @@ The time range could be specified as:
|
|
347
347
|
|
348
348
|
The client supports following management API:
|
349
349
|
|
350
|
-
| | API docs
|
351
|
-
| ---
|
352
|
-
| [**AuthorizationsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/AuthorizationsApi.html) | https://docs.influxdata.com/influxdb/
|
353
|
-
| [**BucketsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/BucketsApi.html) | https://docs.influxdata.com/influxdb/
|
354
|
-
| [**LabelsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/LabelsApi.html) | https://docs.influxdata.com/influxdb/
|
355
|
-
| [**OrganizationsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/OrganizationsApi.html) | https://docs.influxdata.com/influxdb/
|
356
|
-
| [**UsersApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/UsersApi.html) | https://docs.influxdata.com/influxdb/
|
350
|
+
| | API docs |
|
351
|
+
| --- |---------------------------------------------------------------------|
|
352
|
+
| [**AuthorizationsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/AuthorizationsApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Authorizations |
|
353
|
+
| [**BucketsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/BucketsApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Buckets |
|
354
|
+
| [**LabelsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/LabelsApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Labels |
|
355
|
+
| [**OrganizationsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/OrganizationsApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Organizations |
|
356
|
+
| [**UsersApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/UsersApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Users |
|
357
357
|
|
358
358
|
|
359
|
-
The following example demonstrates how to use a InfluxDB 2.
|
359
|
+
The following example demonstrates how to use a InfluxDB 2.x Management API to create new bucket. For further information see docs and [examples](/examples).
|
360
360
|
|
361
361
|
```ruby
|
362
362
|
#
|
@@ -427,7 +427,7 @@ client.close!
|
|
427
427
|
|
428
428
|
### Check the server status
|
429
429
|
|
430
|
-
Server availability can be checked using the `client.ping` method. That is equivalent of the [influx ping](https://
|
430
|
+
Server availability can be checked using the `client.ping` method. That is equivalent of the [influx ping](https://docs.influxdata.com/influxdb/latest/reference/cli/influx/ping/).
|
431
431
|
|
432
432
|
### Proxy configuration
|
433
433
|
|
@@ -445,15 +445,15 @@ To overcome this limitation you have to set the client property `redirect_forwar
|
|
445
445
|
|
446
446
|
### InfluxDB 1.8 API compatibility
|
447
447
|
|
448
|
-
[InfluxDB 1.8.0 introduced forward compatibility APIs](https://docs.influxdata.com/influxdb/v1.8/tools/api/#influxdb-2-0-api-compatibility-endpoints) for InfluxDB 2.
|
448
|
+
[InfluxDB 1.8.0 introduced forward compatibility APIs](https://docs.influxdata.com/influxdb/v1.8/tools/api/#influxdb-2-0-api-compatibility-endpoints) for InfluxDB 2.x. This allow you to easily move from InfluxDB 1.x to InfluxDB 2.x Cloud or open source.
|
449
449
|
|
450
450
|
The following forward compatible APIs are available:
|
451
451
|
|
452
|
-
| API | Endpoint | Description
|
453
|
-
|
454
|
-
| [query_api.rb](lib/influxdb2/client/query_api.rb) | [/api/v2/query](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-query-http-endpoint) | Query data in InfluxDB 1.8.0+ using the InfluxDB 2.
|
455
|
-
| [write_api.rb](lib/influxdb2/client/write_api.rb) | [/api/v2/write](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-write-http-endpoint) | Write data to InfluxDB 1.8.0+ using the InfluxDB 2.
|
456
|
-
| [health_api.rb](lib/influxdb2/client/health_api.rb) | [/health](https://docs.influxdata.com/influxdb/latest/tools/api/#health-http-endpoint) | Check the health of your InfluxDB instance
|
452
|
+
| API | Endpoint | Description |
|
453
|
+
|:----------|:----------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
454
|
+
| [query_api.rb](lib/influxdb2/client/query_api.rb) | [/api/v2/query](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-query-http-endpoint) | Query data in InfluxDB 1.8.0+ using the InfluxDB 2.x API and [Flux](https://docs.influxdata.com/flux/latest/) _(endpoint should be enabled by [`flux-enabled` option](https://docs.influxdata.com/influxdb/latest/administration/config/#flux-enabled-false))_ |
|
455
|
+
| [write_api.rb](lib/influxdb2/client/write_api.rb) | [/api/v2/write](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-write-http-endpoint) | Write data to InfluxDB 1.8.0+ using the InfluxDB 2.x API |
|
456
|
+
| [health_api.rb](lib/influxdb2/client/health_api.rb) | [/health](https://docs.influxdata.com/influxdb/latest/tools/api/#health-http-endpoint) | Check the health of your InfluxDB instance |
|
457
457
|
|
458
458
|
For detail info see [InfluxDB 1.8 example](examples/influxdb_18_example.rb).
|
459
459
|
|
data/lib/influxdb-client.rb
CHANGED
@@ -27,6 +27,13 @@ require 'influxdb2/client/query_api'
|
|
27
27
|
require 'influxdb2/client/delete_api'
|
28
28
|
require 'influxdb2/client/health_api'
|
29
29
|
require 'influxdb2/client/ping_api'
|
30
|
+
require 'influxdb2/client/invocable_scripts_api'
|
30
31
|
require 'influxdb2/client/point'
|
31
32
|
require 'influxdb2/client/flux_table'
|
32
33
|
require 'influxdb2/client/write_retry'
|
34
|
+
require 'influxdb2/client/models/script'
|
35
|
+
require 'influxdb2/client/models/scripts'
|
36
|
+
require 'influxdb2/client/models/script_create_request'
|
37
|
+
require 'influxdb2/client/models/script_language'
|
38
|
+
require 'influxdb2/client/models/script_update_request'
|
39
|
+
require 'influxdb2/client/models/script_invocation_params'
|
@@ -85,6 +85,13 @@ module InfluxDB2
|
|
85
85
|
DeleteApi.new(options: @options)
|
86
86
|
end
|
87
87
|
|
88
|
+
# Create an InvocableScripts API instance.
|
89
|
+
#
|
90
|
+
# @return [InvocableScriptsApi] New instance of InvocableScriptsApi.
|
91
|
+
def create_invocable_scripts_api
|
92
|
+
InvocableScriptsApi.new(options: @options)
|
93
|
+
end
|
94
|
+
|
88
95
|
# Get the health of an instance.
|
89
96
|
#
|
90
97
|
# @deprecated Use `ping` instead
|
@@ -63,33 +63,28 @@ module InfluxDB2
|
|
63
63
|
URI.parse(File.join(@options[:url], api_path))
|
64
64
|
end
|
65
65
|
|
66
|
-
def
|
66
|
+
def _request_json(payload, uri, headers: {}, method: Net::HTTP::Post)
|
67
67
|
_check_arg_type(:headers, headers, Hash)
|
68
|
-
|
68
|
+
_request(payload, uri, headers: headers.merge(HEADER_CONTENT_TYPE => 'application/json'), method: method)
|
69
69
|
end
|
70
70
|
|
71
71
|
def _post_text(payload, uri, headers: {})
|
72
72
|
_check_arg_type(:headers, headers, Hash)
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
def _post(payload, uri, limit: @max_redirect_count, add_authorization: true, headers: {})
|
77
|
-
_request(payload, uri, limit: limit, add_authorization: add_authorization,
|
78
|
-
headers: headers, request: Net::HTTP::Post)
|
73
|
+
_request(payload, uri, headers: headers.merge(HEADER_CONTENT_TYPE => 'text/plain'))
|
79
74
|
end
|
80
75
|
|
81
76
|
def _get(uri, limit: @max_redirect_count, add_authorization: true, headers: {})
|
82
77
|
_request(nil, uri, limit: limit, add_authorization: add_authorization,
|
83
|
-
headers: headers.merge('Accept' => 'application/json'),
|
78
|
+
headers: headers.merge('Accept' => 'application/json'), method: Net::HTTP::Get)
|
84
79
|
end
|
85
80
|
|
86
81
|
def _request(payload, uri, limit: @max_redirect_count, add_authorization: true, headers: {},
|
87
|
-
|
82
|
+
method: Net::HTTP::Post)
|
88
83
|
raise InfluxError.from_message("Too many HTTP redirects. Exceeded limit: #{@max_redirect_count}") if limit.zero?
|
89
84
|
|
90
85
|
http = _prepare_http_client(uri)
|
91
86
|
|
92
|
-
request =
|
87
|
+
request = method.new(uri.request_uri)
|
93
88
|
request['Authorization'] = "Token #{@options[:token]}" if add_authorization
|
94
89
|
request['User-Agent'] = "influxdb-client-ruby/#{InfluxDB2::VERSION}"
|
95
90
|
headers.each { |k, v| request[k] = v }
|
@@ -111,8 +106,8 @@ module InfluxDB2
|
|
111
106
|
|
112
107
|
redirect_forward_authorization ||= (uri_redirect.host == uri.host) && (uri_redirect.port == uri.port)
|
113
108
|
|
114
|
-
|
115
|
-
|
109
|
+
_request(payload, uri_redirect, limit: limit - 1, add_authorization: redirect_forward_authorization,
|
110
|
+
headers: headers, method: method)
|
116
111
|
else
|
117
112
|
raise InfluxError.from_response(response)
|
118
113
|
end
|
@@ -64,7 +64,7 @@ module InfluxDB2
|
|
64
64
|
uri = _parse_uri('/api/v2/delete')
|
65
65
|
uri.query = URI.encode_www_form(org: org_param, bucket: bucket_param)
|
66
66
|
|
67
|
-
|
67
|
+
_request_json(delete_request.to_body.to_json, uri)
|
68
68
|
end
|
69
69
|
|
70
70
|
def _to_rfc3339(time)
|
@@ -41,11 +41,23 @@ module InfluxDB2
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
# The configuration for expected amount of metadata response from InfluxDB.
|
45
|
+
#
|
46
|
+
class FluxResponseMode
|
47
|
+
# full information about types, default values and groups
|
48
|
+
FULL = 'full'.freeze
|
49
|
+
# useful for Invocable scripts
|
50
|
+
ONLY_NAMES = 'only_names'.freeze
|
51
|
+
end
|
52
|
+
|
44
53
|
# This class us used to construct FluxResult from CSV.
|
45
54
|
#
|
46
55
|
class FluxCsvParser
|
47
56
|
include Enumerable
|
48
|
-
|
57
|
+
# @param [String|HTTPResponse] data to be parse
|
58
|
+
# @param [Boolean] stream set to true if the response is stream otherwise (`string`) set `false`
|
59
|
+
# @param [str] response_mode set the amount of metadata expected in response
|
60
|
+
def initialize(response, stream: false, response_mode: InfluxDB2::FluxResponseMode::FULL)
|
49
61
|
@response = response
|
50
62
|
@stream = stream
|
51
63
|
@tables = {}
|
@@ -58,6 +70,7 @@ module InfluxDB2
|
|
58
70
|
@parsing_state_error = false
|
59
71
|
|
60
72
|
@closed = false
|
73
|
+
@response_mode = response_mode
|
61
74
|
end
|
62
75
|
|
63
76
|
attr_reader :tables, :closed
|
@@ -112,7 +125,9 @@ module InfluxDB2
|
|
112
125
|
token = csv[0]
|
113
126
|
|
114
127
|
# start new table
|
115
|
-
if (ANNOTATIONS.include? token) && !@start_new_table
|
128
|
+
if ((ANNOTATIONS.include? token) && !@start_new_table) ||
|
129
|
+
(@response_mode == InfluxDB2::FluxResponseMode::ONLY_NAMES && @table.nil?)
|
130
|
+
|
116
131
|
# Return already parsed DataFrame
|
117
132
|
@start_new_table = true
|
118
133
|
@table = InfluxDB2::FluxTable.new
|
@@ -177,6 +192,10 @@ module InfluxDB2
|
|
177
192
|
def _parse_values(csv)
|
178
193
|
# parse column names
|
179
194
|
if @start_new_table
|
195
|
+
if @response_mode == InfluxDB2::FluxResponseMode::ONLY_NAMES && @table.columns.empty?
|
196
|
+
_add_data_types(@table, csv.map { |_| 'string' })
|
197
|
+
@groups = csv.map { |_| 'false' }
|
198
|
+
end
|
180
199
|
_add_groups(@table, @groups)
|
181
200
|
_add_column_names_and_tags(@table, csv)
|
182
201
|
@start_new_table = false
|
@@ -20,7 +20,7 @@
|
|
20
20
|
require_relative 'models/health_check'
|
21
21
|
|
22
22
|
module InfluxDB2
|
23
|
-
# The client of the InfluxDB 2.
|
23
|
+
# The client of the InfluxDB 2.x that implement Health HTTP API endpoint.
|
24
24
|
#
|
25
25
|
# @deprecated Use `PingApi` instead
|
26
26
|
class HealthApi < DefaultApi
|
@@ -0,0 +1,147 @@
|
|
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/script'
|
22
|
+
|
23
|
+
module InfluxDB2
|
24
|
+
# Use API invokable scripts to create custom InfluxDB API endpoints that query, process, and shape data.
|
25
|
+
#
|
26
|
+
# API invokable scripts let you assign scripts to API endpoints and then execute them as standard REST operations
|
27
|
+
# in InfluxDB Cloud.
|
28
|
+
class InvocableScriptsApi < DefaultApi
|
29
|
+
# @param [Hash] options The options to be used by the client.
|
30
|
+
def initialize(options:)
|
31
|
+
super(options: options)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Create a script.
|
35
|
+
#
|
36
|
+
# @param script_create_request [ScriptCreateRequest] The script to create.
|
37
|
+
#
|
38
|
+
# @return [Script] The created script.
|
39
|
+
def create_script(script_create_request)
|
40
|
+
uri = _parse_uri('/api/v2/scripts')
|
41
|
+
|
42
|
+
response = _request_json(script_create_request.to_body.to_json, uri, headers: { 'Accept' => 'application/json' })
|
43
|
+
|
44
|
+
_to_object(response, Script)
|
45
|
+
end
|
46
|
+
|
47
|
+
# Update a script.
|
48
|
+
#
|
49
|
+
# @param script_id [String] The ID of the script to update. (required)
|
50
|
+
# @param update_request [ScriptUpdateRequest] Script updates to apply (required)
|
51
|
+
#
|
52
|
+
# @return [Script] The updated script.
|
53
|
+
def update_script(script_id, update_request)
|
54
|
+
uri = _parse_uri_script(script_id)
|
55
|
+
|
56
|
+
response = _request_json(update_request.to_body.to_json, uri, headers: { 'Accept' => 'application/json' },
|
57
|
+
method: Net::HTTP::Patch)
|
58
|
+
_to_object(response, Script)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Delete a script.
|
62
|
+
#
|
63
|
+
# @param script_id [String] The ID of the script to delete. (required)
|
64
|
+
def delete_script(script_id)
|
65
|
+
uri = _parse_uri_script(script_id)
|
66
|
+
|
67
|
+
_request_json('', uri, headers: { 'Accept' => 'application/json' },
|
68
|
+
method: Net::HTTP::Delete)
|
69
|
+
end
|
70
|
+
|
71
|
+
# List scripts.
|
72
|
+
#
|
73
|
+
# @param [Hash] opts the optional parameters
|
74
|
+
# @option opts [Integer] :limit The number of scripts to return.
|
75
|
+
# @option opts [Integer] :offset The offset for pagination.
|
76
|
+
#
|
77
|
+
# @return [Script]
|
78
|
+
def find_scripts(opts = {})
|
79
|
+
limit = !opts[:limit].nil? ? opts[:limit] : []
|
80
|
+
offset = !opts[:offset].nil? ? opts[:offset] : []
|
81
|
+
uri = _parse_uri('/api/v2/scripts')
|
82
|
+
uri.query = URI.encode_www_form(limit: limit, offset: offset)
|
83
|
+
|
84
|
+
response = _request_json('', uri, headers: { 'Accept' => 'application/json' },
|
85
|
+
method: Net::HTTP::Get)
|
86
|
+
|
87
|
+
_to_object(response, Scripts).scripts
|
88
|
+
end
|
89
|
+
|
90
|
+
# Invoke synchronously a script and return result as a [String].
|
91
|
+
#
|
92
|
+
# @param script_id [String] The ID of the script to invoke. (required)
|
93
|
+
# @param [Enumerable] params represent key/value pairs parameters to be injected into script
|
94
|
+
#
|
95
|
+
# @return [String] result of query
|
96
|
+
def invoke_script_raw(script_id, params: nil)
|
97
|
+
_invoke_script(script_id, params: params).read_body
|
98
|
+
end
|
99
|
+
|
100
|
+
# Invoke synchronously a script and return result as a [FluxTable].
|
101
|
+
#
|
102
|
+
# @param script_id [String] The ID of the script to invoke. (required)
|
103
|
+
# @param [Enumerable] params represent key/value pairs parameters to be injected into script
|
104
|
+
#
|
105
|
+
# @return [Array] list of FluxTables which are matched the query
|
106
|
+
def invoke_script(script_id, params: nil)
|
107
|
+
response = invoke_script_raw(script_id, params: params)
|
108
|
+
parser = InfluxDB2::FluxCsvParser.new(response, stream: false,
|
109
|
+
response_mode: InfluxDB2::FluxResponseMode::ONLY_NAMES)
|
110
|
+
|
111
|
+
parser.parse
|
112
|
+
parser.tables
|
113
|
+
end
|
114
|
+
|
115
|
+
# Invoke synchronously a script and return result as a stream of FluxRecord.
|
116
|
+
#
|
117
|
+
# @param script_id [String] The ID of the script to invoke. (required)
|
118
|
+
# @param [Enumerable] params represent key/value pairs parameters to be injected into script
|
119
|
+
#
|
120
|
+
# @return stream of Flux Records
|
121
|
+
def invoke_script_stream(script_id, params: nil)
|
122
|
+
response = _invoke_script(script_id, params: params)
|
123
|
+
|
124
|
+
InfluxDB2::FluxCsvParser.new(response, stream: true, response_mode: InfluxDB2::FluxResponseMode::ONLY_NAMES)
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def _parse_uri_script(script_id, path = nil)
|
130
|
+
_parse_uri('/api/v2/scripts/' + URI.encode_www_form_component(script_id) + (path.nil? ? '' : "/#{path}"))
|
131
|
+
end
|
132
|
+
|
133
|
+
def _to_object(response, model)
|
134
|
+
body = response.body
|
135
|
+
|
136
|
+
data = JSON.parse("[#{body}]", symbolize_names: true)[0]
|
137
|
+
model.build_from_hash(data)
|
138
|
+
end
|
139
|
+
|
140
|
+
def _invoke_script(script_id, params: nil)
|
141
|
+
uri = _parse_uri_script(script_id, 'invoke')
|
142
|
+
|
143
|
+
script_invocation_params = InfluxDB2::ScriptInvocationParams.new(params: params)
|
144
|
+
_request_json(script_invocation_params.to_body.to_json, uri, headers: { 'Accept' => 'application/json' })
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|