latias-influxdb 0.3.0 → 1.0.0.pre.bata

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: '005047899e29d95b4e056709cee013a8acf0318f7c40449ab483421fdc495dd5'
4
- data.tar.gz: 6aa38fb36ebbda1952da047034a3992d7c9677bb7dc31b9cacd0dd026e0c29dc
3
+ metadata.gz: d81103797f4987e9edcf5d79d896d86536a617d76b75696fd0dab690b49d9cea
4
+ data.tar.gz: fba4af3dcc45f9e785b0dd3d641d35e968b61687d20b56ab7343c4c16644f14e
5
5
  SHA512:
6
- metadata.gz: b30dcf6a0e3ae8b95946e8ad3cf76e138846674f38803bbde3c4b3523ae55120196244f60f33da28b66e3823ec60008dc119ae5f5839fbbad896dfbe7f29fcda
7
- data.tar.gz: db373d2feff2943d25b5acb48aba0aa3fde4484113366b1846477d80308ec515fb4a4604e89c9759013477ce6269b666ac3fc500f4e7f4fc84563eec7753c73d
6
+ metadata.gz: ea0c14439f1a0281422fd39cef6998b6bcff89d93e09420d04438f1f1a2ff217f9d099025a7ec72925beb1502a226b98648ebbe1862ab9d9b68a8025f2b33cba
7
+ data.tar.gz: 11eeee42967286b77a0eaf535dc987d8019b52b01d989105af9dbc61cbe7b3897ba6fb8e632b721146dd6c9006637dd071eaa9d450c2f6195ab3b1d1f92660fe
data/README.md CHANGED
@@ -2,7 +2,77 @@
2
2
 
3
3
  Ruby lib for use influxdb version 2 on Ruby language
4
4
 
5
- ## Usage
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'latias-influxdb'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install latias-influxdb
23
+ ```
24
+
25
+ Check version
26
+
27
+ ```bash
28
+ rails latias:influxdb:verion
29
+ ```
30
+
31
+ ## Configuration & Usage
32
+
33
+ ### Configuration
34
+
35
+ First generating config file
36
+
37
+ ```bash
38
+ rails g latias:influxdb:install
39
+ ```
40
+
41
+ ```ruby
42
+ # config/initializers/latias_influxdb
43
+ Latias::Influxdb.configure do |config|
44
+ # default
45
+ # config.url = 'http://localhost:8086'
46
+ # config.token = 'token'
47
+ # config.bucket = 'bucket'
48
+ # config.org = 'org'
49
+ # config.use_ssl = false
50
+ # config.verify_mode = OpenSSL::SSL::VERIFY_NONE
51
+ end
52
+ ```
53
+
54
+ ### Usage
55
+
56
+ You can use
57
+
58
+ <!--
59
+
60
+ # config.url = 'http://188.166.252.165:8086'
61
+ # config.token = 'YyD4UGu4_Xn0CIVsycFdjaQVd7m1g5wRp0z2BCfBSyNL6-GHqqyZRePGy46B2m8Zg6jgqHAN_J6jyhCmvGeQRA=='
62
+ # config.bucket = 'MDBEnergy'
63
+ # config.org = 'MDBEnergy'
64
+
65
+ -->
66
+
67
+ ```ruby
68
+ bucket = Latias::Influxdb::Bucket.new
69
+ bucket.client_connection
70
+ # or bucket = Latias::Influxdb::Bucket.new.client_connection
71
+ bucket.range('start: -1m').filter('fn: (r) => r["_measurement"] == "cpu"')
72
+ bucket.call
73
+ ```
74
+
75
+ Or use with model
6
76
 
7
77
  <!-- ```ruby
8
78
  class MdbEnergyBucket < Latias::Influxdb::Bucket
@@ -40,36 +110,6 @@ mdb_energy_bucket.range('start: -1m').filter('fn: (r) => r["_measurement"] == "c
40
110
  mdb_energy_bucket.call
41
111
  ```
42
112
 
43
- ## Installation
44
-
45
- Add this line to your application's Gemfile:
46
-
47
- ```ruby
48
- gem 'latias-influxdb'
49
- ```
50
-
51
- And then execute:
52
-
53
- ```bash
54
- $ bundle
55
- ```
56
-
57
- Or install it yourself as:
58
-
59
- ```bash
60
- $ gem install latias-influxdb
61
- ```
62
-
63
- Check version
64
-
65
- ```bash
66
- rails latias:influxdb:verion
67
- ```
68
-
69
- ## Contributing
70
-
71
- Contribution directions go here.
72
-
73
113
  ## License
74
114
 
75
115
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -3,6 +3,7 @@
3
3
  require 'latias/influxdb/bucket'
4
4
  require 'latias/influxdb/version'
5
5
  require 'latias/influxdb/engine'
6
+ require "latias/influxdb/configuration"
6
7
 
7
8
  module Latias
8
9
  # Influxdb
@@ -10,13 +10,13 @@ module Latias
10
10
  attr_reader :url, :token, :bucket, :org, :use_ssl, :verify_mode, :precision
11
11
 
12
12
  def initialize
13
- set_default
13
+ @query = ''
14
14
  end
15
15
 
16
16
  def call
17
- all_query = "from(bucket: \"#{@bucket}\") #{@query}"
17
+ all_query = "from(bucket: \"#{use_value('bucket')}\") #{@query}"
18
18
  @query = ''
19
- @client.create_query_api.query(query: all_query, org: @org)
19
+ @client.create_query_api.query(query: all_query, org: use_value('org'))
20
20
  end
21
21
 
22
22
  def yield(query)
@@ -38,27 +38,31 @@ module Latias
38
38
  @query += query
39
39
  end
40
40
 
41
+ def client_connection
42
+ @client = InfluxDB2::Client.new(use_value('url'), use_value('token'),
43
+ use_ssl: use_value('use_ssl'),
44
+ verify_mode: use_value('verify_mode'),
45
+ precision: InfluxDB2::WritePrecision::NANOSECOND)
46
+ self
47
+ end
48
+
49
+ def client_reconnection
50
+ client_connection
51
+ end
52
+
41
53
  private
42
54
 
43
- def set_default
44
- @query = ''
45
- @url = 'http://localhost:8086'
46
- @token = 'token'
47
- @bucket = 'bucket'
48
- @org = 'org'
49
- @use_ssl = false
50
- @verify_mode = OpenSSL::SSL::VERIFY_NONE
55
+ def use_value(key)
56
+ b = get_binding("self")
57
+ b.eval("@#{key}") || Latias::Influxdb.configuration.send(key)
51
58
  end
52
59
 
53
60
  def new_command
54
61
  '|> '
55
62
  end
56
63
 
57
- def client_connection
58
- @client = InfluxDB2::Client.new(@url, @token,
59
- use_ssl: @use_ssl,
60
- verify_mode: @verify_mode.present? ? @verify_mode : OpenSSL::SSL::VERIFY_NONE,
61
- precision: InfluxDB2::WritePrecision::NANOSECOND)
64
+ def get_binding(param)
65
+ binding
62
66
  end
63
67
  end
64
68
  end
@@ -5,14 +5,19 @@ module Latias
5
5
  module Influxdb
6
6
  # Configuration
7
7
  class Configuration
8
- attr_accessor :async
8
+ attr_accessor :url, :token, :bucket, :org, :use_ssl, :verify_mode, :precision
9
9
 
10
10
  def initialize
11
- @async = true
11
+ @query = ''
12
+ @url = 'http://localhost:8086'
13
+ @token = 'token'
14
+ @bucket = 'bucket'
15
+ @org = 'org'
16
+ @use_ssl = false
17
+ @verify_mode = OpenSSL::SSL::VERIFY_NONE
12
18
  end
13
19
  end
14
20
 
15
- # Borrow syntax from Clearance: https://github.com/thoughtbot/clearance/blob/master/lib/clearance/configuration.rb
16
21
  def self.configuration
17
22
  @configuration ||= Configuration.new
18
23
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Latias
4
4
  module Influxdb
5
- VERSION = '0.3.0'
5
+ VERSION = '1.0.0-bata'
6
6
  end
7
7
  end
@@ -1,3 +1,9 @@
1
1
  Latias::Influxdb.configure do |config|
2
- # Latias::Influxdb.configure
2
+ # default
3
+ # config.url = 'http://localhost:8086'
4
+ # config.token = 'token'
5
+ # config.bucket = 'bucket'
6
+ # config.org = 'org'
7
+ # config.use_ssl = false
8
+ # config.verify_mode = OpenSSL::SSL::VERIFY_NONE
3
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: latias-influxdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0.pre.bata
5
5
  platform: ruby
6
6
  authors:
7
7
  - nattanon
@@ -74,9 +74,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - ">="
77
+ - - ">"
78
78
  - !ruby/object:Gem::Version
79
- version: '0'
79
+ version: 1.3.1
80
80
  requirements: []
81
81
  rubygems_version: 3.2.6
82
82
  signing_key: