influxdb 0.0.3 → 0.0.4

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
  SHA1:
3
- metadata.gz: e8b59b9b818ffdb252513445a60eacdeae93fa49
4
- data.tar.gz: 779f22ee66d5017709f38496e9e408e83c2efb05
3
+ metadata.gz: 015169efb594ef5763c19ae7775484d4d7bb5503
4
+ data.tar.gz: 5028373587c1b36ce5d8c5e723f9641d71fea996
5
5
  SHA512:
6
- metadata.gz: ca55be4627b2396175944f5f14d471a216fa2febb1b3f4db746ff0a2ca42c1b32a78e08be2980e5377f1bea37f35db9f8678c3728abd00fb01f106b2f84a4ae9
7
- data.tar.gz: e03e5c64acf71ccdeda8a89b4c82879a55341727086d5d5824ad5f88550a7a21d4808010669ee55d83bed9192ad18e6a528d1405d80648c01f3dd68de277622c
6
+ metadata.gz: fb0d6534aa38bf7673c310a864731f21f0e7154244eb37c9cf92bc78833dae03ff6548a31e381a535533de48528df10da4e09af453b782dfae1eb853374d5826
7
+ data.tar.gz: bbb42ada8b32eeda12ee2966814cfd6fa18d336499d4c7accea408cd23bb4cc5e9b8678f8e1f0db82768d6f66408990dc56933629ba4624d76d7e0f10ecf494d
data/README.md CHANGED
@@ -2,3 +2,121 @@ influxdb-ruby
2
2
  =============
3
3
 
4
4
  ![InfluxDB Build Status](https://travis-ci.org/influxdb/influxdb-ruby.png)
5
+
6
+ Ruby client library for [InfluxDB](http://influxdb.org/).
7
+
8
+ Install
9
+ -------
10
+
11
+ ```
12
+ $ [sudo] gem install influxdb
13
+ ```
14
+
15
+ Or add it to your `Gemfile`, etc.
16
+
17
+ Usage
18
+ -----
19
+
20
+ Create a database:
21
+
22
+ ``` ruby
23
+ require 'influxdb'
24
+
25
+ hostname = 'localhost'
26
+ port = 8086
27
+ username = 'root'
28
+ password = 'root'
29
+ database = 'site_development'
30
+
31
+ influxdb = InfluxDB::Client.new(hostname, port, username, password)
32
+
33
+ influxdb.create_database(database)
34
+ ```
35
+
36
+ Create a user for a database:
37
+
38
+ ``` ruby
39
+ require 'influxdb'
40
+
41
+ hostname = 'localhost'
42
+ port = 8086
43
+ username = 'root'
44
+ password = 'root'
45
+ database = 'site_development'
46
+
47
+ influxdb = InfluxDB::Client.new(hostname, port, username, password)
48
+
49
+ new_username = 'foo'
50
+ new_password = 'bar'
51
+ influxdb.create_database_user(database, new_username, new_password)
52
+ ```
53
+
54
+ Write some data:
55
+
56
+ ``` ruby
57
+ require 'influxdb'
58
+
59
+ hostname = 'localhost'
60
+ port = 8086
61
+ username = 'foo'
62
+ password = 'bar'
63
+ database = 'site_development'
64
+ name = 'foobar'
65
+
66
+ influxdb = InfluxDB::Client.new(hostname, port, username, password, database)
67
+
68
+ # Enumerator that emits a sine wave
69
+ Value = (0..360).to_a.map {|i| Math.send(:sin, i / 10.0) * 10 }.each
70
+
71
+ loop do
72
+ data = {
73
+ :value => Value.next
74
+ }
75
+
76
+ influxdb.write_point(name, data)
77
+
78
+ sleep 1
79
+ end
80
+ ```
81
+
82
+ List databases:
83
+
84
+ ``` ruby
85
+ require 'influxdb'
86
+
87
+ hostname = 'localhost'
88
+ port = 8086
89
+ username = 'root'
90
+ password = 'root'
91
+
92
+ influxdb = InfluxDB::Client.new(hostname, 8086, username, password)
93
+
94
+ influxdb.get_database_list
95
+ ```
96
+
97
+ Delete a database:
98
+
99
+ ``` ruby
100
+ require 'influxdb'
101
+
102
+ hostname = 'localhost'
103
+ port = 8086
104
+ username = 'root'
105
+ password = 'root'
106
+ database = 'site_development'
107
+
108
+ influxdb = InfluxDB::Client.new(username, port, username, password)
109
+
110
+ influxdb.delete_database(database)
111
+ ```
112
+
113
+
114
+ Testing
115
+ -------
116
+
117
+ ```
118
+ git clone git@github.com:influxdb/influxdb-ruby.git
119
+ cd influxdb-ruby
120
+ bundle
121
+ rake
122
+ ```
@@ -1,13 +1,37 @@
1
- require "net/http"
1
+ require 'net/http'
2
+ require 'json'
2
3
 
3
4
  module InfluxDB
4
5
  class Client
5
- def initialize(host, port, username, password, database = nil)
6
- @host = host
7
- @port = port
8
- @username = username
9
- @password = password
10
- @database = database
6
+ attr_accessor :host, :port, :username, :password, :database
7
+
8
+ # Initializes a new Influxdb client
9
+ #
10
+ # === Examples:
11
+ #
12
+ # Influxdb.new # connect to localhost using root/root
13
+ # # as the credentials and doesn't connect to a db
14
+ #
15
+ # Influxdb.new 'db' # connect to localhost using root/root
16
+ # # as the credentials and 'db' as the db name
17
+ #
18
+ # Influxdb.new :username => 'username' # override username, other defaults remain unchanged
19
+ #
20
+ # Influxdb.new 'db', :username => 'username' # override username, use 'db' as the db name
21
+ #
22
+ # === Valid options in hash
23
+ #
24
+ # +:hostname+:: the hostname to connect to
25
+ # +:port+:: the port to connect to
26
+ # +:username+:: the username to use when executing commands
27
+ # +:password+:: the password associated with the username
28
+ def initialize *args
29
+ opts = args.last.is_a?(Hash) ? args.last : {}
30
+ @host = opts[:host] || "localhost"
31
+ @port = opts[:port] || 8086
32
+ @username = opts[:username] || "root"
33
+ @password = opts[:password] || "root"
34
+ @database = args.first
11
35
  end
12
36
 
13
37
  def create_database(name)
@@ -48,7 +72,7 @@ module InfluxDB
48
72
  end
49
73
 
50
74
  payload[:points].push point
51
- data = JSON.generate(payload)
75
+ data = JSON.generate([payload])
52
76
  response = http.request(Net::HTTP::Post.new(url), data)
53
77
  end
54
78
  end
@@ -1,3 +1,3 @@
1
1
  module InfluxDB
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -3,14 +3,30 @@ require "json"
3
3
 
4
4
  describe InfluxDB::Client do
5
5
  before do
6
- @influxdb = InfluxDB::Client.new("influxdb.test", 9999, "username", "password", "database")
6
+ @influxdb = InfluxDB::Client.new "database", :host => "influxdb.test",
7
+ :port => 9999, :username => "username", :password => "password"
7
8
  end
8
9
 
9
10
  describe "#new" do
11
+ it "should instantiate a new InfluxDB client and default to localhost" do
12
+ @influxdb = InfluxDB::Client.new
13
+
14
+ @influxdb.should be_a(InfluxDB::Client)
15
+ @influxdb.host.should ==("localhost")
16
+ @influxdb.port.should ==(8086)
17
+ @influxdb.username.should ==("root")
18
+ @influxdb.password.should ==("root")
19
+ end
20
+
10
21
  it "should instantiate a new InfluxDB client" do
11
- @influxdb = InfluxDB::Client.new("host", "port", "username", "password", "database")
22
+ @influxdb = InfluxDB::Client.new "database", :hostname => "host",
23
+ :port => "port", :username => "username", :password => "password"
12
24
 
13
25
  @influxdb.should be_a(InfluxDB::Client)
26
+ @influxdb.host.should ==("localhost")
27
+ @influxdb.port.should ==("port")
28
+ @influxdb.username.should ==("username")
29
+ @influxdb.password.should ==("password")
14
30
  end
15
31
  end
16
32
 
@@ -58,11 +74,11 @@ describe InfluxDB::Client do
58
74
 
59
75
  describe "#write_point" do
60
76
  it "should POST to add points" do
61
- body = {
77
+ body = [{
62
78
  :name => "seriez",
63
79
  :points => [["juan", 87]],
64
80
  :columns => ["name", "age"]
65
- }
81
+ }]
66
82
 
67
83
  stub_request(:post, "http://influxdb.test:9999/db/database/series").with(
68
84
  :query => {:u => "username", :p => "password"},
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Persen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-07 00:00:00.000000000 Z
11
+ date: 2013-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json