latias-influxdb 0.2.0 → 1.0.1

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: e1922c4c627f003a81bd378c4844a9285a44118abe5950954ae40d87055d6144
4
- data.tar.gz: 2ed4cf9876fdc08ed9a25c60751989dd0749c6295ddc5ae8dbc24ef7e32ad314
3
+ metadata.gz: 628887438811d27b302005eea23f65ef70c4f3d7d841b23feb4be41c839deadc
4
+ data.tar.gz: f1c53f167d7cf896ff38927d8e7e52f59a186972909284ce8641fd0379b3e8e4
5
5
  SHA512:
6
- metadata.gz: f6d25a50e23bcea9a13ffd6bf33ca59a0b03a05a838ea32b3a5d51478be1233a9c61593c740d6ef863a294a19e6e329be84a36bfc928ca0e7294c145dab076ee
7
- data.tar.gz: f21959a4acbd90c6915e2c7b394ffa4c5cc101fb987f68820e4ad19c9cb7e06dae4d9b48978e620c0d17912136f475353dec13bab7408d4af96e7446398e6b75
6
+ metadata.gz: db9a7a7565326d5d51d60d5a33972d303bb2788d4b8533d25ae8565ba07be3c45ff92be3b993cd9d724f90ea8719c5a6a50575724e0db85761e2f164cc2731ef
7
+ data.tar.gz: df32c1c7092cb94c2ffdc8e28822844dda23da5915dae6ba238304e6432789157b1dbf05940a7b9b3a499b32e019d87ed70207d365f85f17b24c9df5ee5d1f6a
data/README.md CHANGED
@@ -2,12 +2,81 @@
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
9
79
  def initialize
10
- super
11
80
  @url = 'http://188.166.252.165:8086'
12
81
  @token = 'YyD4UGu4_Xn0CIVsycFdjaQVd7m1g5wRp0z2BCfBSyNL6-GHqqyZRePGy46B2m8Zg6jgqHAN_J6jyhCmvGeQRA=='
13
82
  @bucket = 'MDBEnergy'
@@ -25,13 +94,12 @@ mdb_energy_bucket.call
25
94
  ```ruby
26
95
  class MdbEnergyBucket < Latias::Influxdb::Bucket
27
96
  def initialize
28
- super
29
97
  @url = 'http://localhost:8086'
30
98
  @token = 'your token'
31
99
  @bucket = 'MDBEnergy'
32
100
  @org = 'MDBEnergy'
33
101
  @use_ssl = false
34
- @client = client
102
+ client_connection
35
103
  end
36
104
  end
37
105
 
@@ -40,30 +108,13 @@ mdb_energy_bucket.range('start: -1m').filter('fn: (r) => r["_measurement"] == "c
40
108
  mdb_energy_bucket.call
41
109
  ```
42
110
 
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:
111
+ ## License
52
112
 
53
- ```bash
54
- $ bundle
55
- ```
113
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
56
114
 
57
- Or install it yourself as:
115
+ ## Build and push GEM
58
116
 
59
117
  ```bash
60
- $ gem install latias-influxdb
118
+ gem build latias-influxdb.gemspec
119
+ gem push latias-influxdb-xx.xx.xx.gem
61
120
  ```
62
-
63
- ## Contributing
64
-
65
- Contribution directions go here.
66
-
67
- ## License
68
-
69
- 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
@@ -9,14 +9,10 @@ module Latias
9
9
  class Bucket
10
10
  attr_reader :url, :token, :bucket, :org, :use_ssl, :verify_mode, :precision
11
11
 
12
- def initialize
13
- set_default
14
- end
15
-
16
12
  def call
17
- all_query = "from(bucket: \"#{@bucket}\") #{@query}"
13
+ all_query = "from(bucket: \"#{use_value('bucket')}\") #{@query}"
18
14
  @query = ''
19
- @client.create_query_api.query(query: all_query, org: @org)
15
+ @client.create_query_api.query(query: all_query, org: use_value('org'))
20
16
  end
21
17
 
22
18
  def yield(query)
@@ -38,27 +34,32 @@ module Latias
38
34
  @query += query
39
35
  end
40
36
 
37
+ def client_connection
38
+ @query = ''
39
+ @client = InfluxDB2::Client.new(use_value('url'), use_value('token'),
40
+ use_ssl: use_value('use_ssl'),
41
+ verify_mode: use_value('verify_mode'),
42
+ precision: InfluxDB2::WritePrecision::NANOSECOND)
43
+ self
44
+ end
45
+
46
+ def client_reconnection
47
+ client_connection
48
+ end
49
+
41
50
  private
42
51
 
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
52
+ def use_value(key)
53
+ b = get_binding("self")
54
+ b.eval("@#{key}") || Latias::Influxdb.configuration.send(key)
51
55
  end
52
56
 
53
57
  def new_command
54
58
  '|> '
55
59
  end
56
60
 
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)
61
+ def get_binding(param)
62
+ binding
62
63
  end
63
64
  end
64
65
  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.2.0'
5
+ VERSION = '1.0.1'
6
6
  end
7
7
  end
@@ -0,0 +1,19 @@
1
+ require 'rails/generators'
2
+
3
+ module Latias
4
+ module Influxdb
5
+ class InstallGenerator < Rails::Generators::Base
6
+ desc "Description:\n This creates a Rails initializer for latias::InfluxDB::Rails."
7
+
8
+ source_root File.expand_path('templates', __dir__)
9
+
10
+ def copy_initializer_file
11
+ template 'initializer.rb', 'config/initializers/latias_influxdb.rb'
12
+ end
13
+
14
+ def install
15
+ # nothing to do here
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ Latias::Influxdb.configure do |config|
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
9
+ end
@@ -1,4 +1,10 @@
1
- # desc "Explaining what the task does"
2
- # task :latias_influxdb do
3
- # # Task goes here
4
- # end
1
+ require 'latias/influxdb/version'
2
+
3
+ namespace :latias do
4
+ namespace :influxdb do
5
+ desc 'check lib varsion'
6
+ task verion: :environment do
7
+ puts "Version: #{Latias::Influxdb::VERSION}"
8
+ end
9
+ end
10
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: latias-influxdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nattanon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-08 00:00:00.000000000 Z
11
+ date: 2021-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: influxdb-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.16.0.pre.2765
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.16.0.pre.2765
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rails
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -34,20 +48,14 @@ files:
34
48
  - MIT-LICENSE
35
49
  - README.md
36
50
  - Rakefile
37
- - app/assets/config/latias_influxdb_manifest.js
38
- - app/assets/stylesheets/latias/influxdb/application.css
39
- - app/controllers/latias/influxdb/application_controller.rb
40
- - app/helpers/latias/influxdb/application_helper.rb
41
- - app/jobs/latias/influxdb/application_job.rb
42
- - app/mailers/latias/influxdb/application_mailer.rb
43
- - app/models/latias/influxdb/application_record.rb
44
- - app/views/layouts/latias/influxdb/application.html.erb
45
51
  - config/routes.rb
46
52
  - lib/latias/influxdb.rb
47
53
  - lib/latias/influxdb/bucket.rb
48
54
  - lib/latias/influxdb/configuration.rb
49
55
  - lib/latias/influxdb/engine.rb
50
56
  - lib/latias/influxdb/version.rb
57
+ - lib/rails/generators/latias/influxdb/install_generator.rb
58
+ - lib/rails/generators/latias/influxdb/templates/initializer.rb
51
59
  - lib/tasks/latias/influxdb_tasks.rake
52
60
  homepage: https://gitlab.opensource-technology.com/nattanon/latias-influxdb
53
61
  licenses:
@@ -1 +0,0 @@
1
- //= link_directory ../stylesheets/latias/influxdb .css
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
- * files in this directory. Styles in this file should be added after the last require_* statement.
11
- * It is generally better to create a new file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
@@ -1,6 +0,0 @@
1
- module Latias
2
- module Influxdb
3
- class ApplicationController < ActionController::Base
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module Latias
2
- module Influxdb
3
- module ApplicationHelper
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module Latias
2
- module Influxdb
3
- class ApplicationJob < ActiveJob::Base
4
- end
5
- end
6
- end
@@ -1,8 +0,0 @@
1
- module Latias
2
- module Influxdb
3
- class ApplicationMailer < ActionMailer::Base
4
- default from: 'from@example.com'
5
- layout 'mailer'
6
- end
7
- end
8
- end
@@ -1,7 +0,0 @@
1
- module Latias
2
- module Influxdb
3
- class ApplicationRecord < ActiveRecord::Base
4
- self.abstract_class = true
5
- end
6
- end
7
- end
@@ -1,15 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Latias influxdb</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
7
-
8
- <%= stylesheet_link_tag "latias/influxdb/application", media: "all" %>
9
- </head>
10
- <body>
11
-
12
- <%= yield %>
13
-
14
- </body>
15
- </html>