influxdb 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWYyOTdjYTlkOGM4ZTk0Y2Q1MmQ5YmMwMDM0ODlmNTQ0YmI5MDQzNw==
4
+ MDEzYzNkNTY1OWIxYzcxMDI0ODVjNDMwMDZmZDgwMjI3OWZkODg2Mw==
5
5
  data.tar.gz: !binary |-
6
- NmFhMjg0MmU3M2Q2NzVjNWMyYzg4ZGVkNzQ3NmI4NzBlNTdjMTA3Nw==
6
+ ZTYxODNmYWVhYzUwMzY2ZGMxM2YyN2M1OGZkOGU1MGNhOGFiY2YwZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWVhZjdhN2NmOGU5ZTVhMjMyNjc0N2RlZThmNWJiNDU1ODRmN2Q2ZWI0N2Ex
10
- N2MyMmU4YmNjYTM0YmY3ZWUwNTNjOTE3ZDBiMzNlOGZjZjZlYzk0Yjc5MWE5
11
- N2M0MGI2NDE4Mzg3OGU4ZDQwYzU3ODVjZmIyNzNhMjcxNzU4ZjM=
9
+ OTNmNjMwZGFkYjEyMTA5MWEzZDc0YTQzZWJiZTNiYTlkY2UyNWZhODU1ODYw
10
+ Mzg4ZjMwZDQwZDk1Yzc4OGI1NjQyNzVmNzNjNDU4OWFkNjYxN2Q0MDM4NWRl
11
+ NGE5ZGNhN2Y4N2JlMWE0ZTRjY2ViMTIwNWY0N2Q5OTFlMjQ5Y2Q=
12
12
  data.tar.gz: !binary |-
13
- ZGUxYmU5YWE0ZjQ5OWVlODcxMDEyM2M4ZDdlN2FlMmI2NjcyZjhmMTg2Mjdl
14
- OTlhYWFhZmMxMjExNDMwYTgwZGIxMDFiOTRmNzU4ZDNlNTcxZmFlMDFkNjdi
15
- ZWQ0MzNkMzYyNjNjMWYwOTQzMjRlNTk3YTRlZTZmYTA4MjE2NjY=
13
+ M2RjNThlNjNlOTlkYTA1YTA4MmM4ODQ2ZDQ5ZmQ2YzRmOTI3NTg0NjgyZmZk
14
+ YzdhNjg5MTk0Yjk1NjUzNjk1ZTNiMGJiN2Y3MjZlMTRjNjFkMzU0Y2M4ZWZi
15
+ ZmE1ZDlmMTEwMjYwMDk1OGQwMGNjY2ExYzU4MWJiODAwMzM0MWU=
@@ -1,4 +1,5 @@
1
1
  require "influxdb/version"
2
+ require "influxdb/errors"
2
3
  require "influxdb/logger"
3
4
 
4
5
  require "influxdb/max_queue"
@@ -10,19 +10,19 @@ module InfluxDB
10
10
 
11
11
  include InfluxDB::Logger
12
12
 
13
- # Initializes a new Influxdb client
13
+ # Initializes a new InfluxDB client
14
14
  #
15
15
  # === Examples:
16
16
  #
17
- # Influxdb.new # connect to localhost using root/root
18
- # # as the credentials and doesn't connect to a db
17
+ # InfluxDB::Client.new # connect to localhost using root/root
18
+ # # as the credentials and doesn't connect to a db
19
19
  #
20
- # Influxdb.new 'db' # connect to localhost using root/root
21
- # # as the credentials and 'db' as the db name
20
+ # InfluxDB::Client.new 'db' # connect to localhost using root/root
21
+ # # as the credentials and 'db' as the db name
22
22
  #
23
- # Influxdb.new :username => 'username' # override username, other defaults remain unchanged
23
+ # InfluxDB::Client.new :username => 'username' # override username, other defaults remain unchanged
24
24
  #
25
- # Influxdb.new 'db', :username => 'username' # override username, use 'db' as the db name
25
+ # Influxdb::Client.new 'db', :username => 'username' # override username, use 'db' as the db name
26
26
  #
27
27
  # === Valid options in hash
28
28
  #
@@ -45,80 +45,55 @@ module InfluxDB
45
45
  def create_database(name)
46
46
  url = full_url("db")
47
47
  data = JSON.generate({:name => name})
48
-
49
- headers = {"Content-Type" => "application/json"}
50
- response = @http.request(Net::HTTP::Post.new(url, headers), data)
48
+ post(url, data)
51
49
  end
52
50
 
53
51
  def delete_database(name)
54
- url = full_url("db/#{name}")
55
-
56
- response = @http.request(Net::HTTP::Delete.new(url))
52
+ delete full_url("db/#{name}")
57
53
  end
58
54
 
59
55
  def get_database_list
60
- url = full_url("db")
61
-
62
- response = @http.request(Net::HTTP::Get.new(url))
63
- JSON.parse(response.body)
56
+ get full_url("db")
64
57
  end
65
58
 
66
59
  def create_cluster_admin(username, password)
67
60
  url = full_url("cluster_admins")
68
61
  data = JSON.generate({:name => username, :password => password})
69
-
70
- headers = {"Content-Type" => "application/json"}
71
- response = @http.request(Net::HTTP::Post.new(url, headers), data)
62
+ post(url, data)
72
63
  end
73
64
 
74
65
  def update_cluster_admin(username, password)
75
66
  url = full_url("cluster_admins/#{username}")
76
67
  data = JSON.generate({:password => password})
77
-
78
- headers = {"Content-Type" => "application/json"}
79
- response = @http.request(Net::HTTP::Post.new(url, headers), data)
68
+ post(url, data)
80
69
  end
81
70
 
82
71
  def delete_cluster_admin(username)
83
- url = full_url("cluster_admins/#{username}")
84
-
85
- response = @http.request(Net::HTTP::Delete.new(url))
72
+ delete full_url("cluster_admins/#{username}")
86
73
  end
87
74
 
88
75
  def get_cluster_admin_list
89
- url = full_url("cluster_admins")
90
-
91
- response = @http.request(Net::HTTP::Get.new(url))
92
- JSON.parse(response.body)
76
+ get full_url("cluster_admins")
93
77
  end
94
78
 
95
79
  def create_database_user(database, username, password)
96
80
  url = full_url("db/#{database}/users")
97
81
  data = JSON.generate({:name => username, :password => password})
98
-
99
- headers = {"Content-Type" => "application/json"}
100
- response = @http.request(Net::HTTP::Post.new(url, headers), data)
82
+ post(url, data)
101
83
  end
102
84
 
103
85
  def update_database_user(database, username, options = {})
104
86
  url = full_url("db/#{database}/users/#{username}")
105
87
  data = JSON.generate(options)
106
-
107
- headers = {"Content-Type" => "application/json"}
108
- @http.request(Net::HTTP::Post.new(url, headers), data)
88
+ post(url, data)
109
89
  end
110
90
 
111
91
  def delete_database_user(database, username)
112
- url = full_url("db/#{database}/users/#{username}")
113
-
114
- @http.request(Net::HTTP::Delete.new(url))
92
+ delete full_url("db/#{database}/users/#{username}")
115
93
  end
116
94
 
117
95
  def get_database_user_list(database)
118
- url = full_url("db/#{database}/users")
119
-
120
- response = @http.request(Net::HTTP::Get.new(url))
121
- JSON.parse(response.body)
96
+ get full_url("db/#{database}/users")
122
97
  end
123
98
 
124
99
  def alter_database_privilege(database, username, admin=true)
@@ -155,10 +130,8 @@ module InfluxDB
155
130
  end
156
131
 
157
132
  def query(query)
158
- url = full_url("db/#{@database}/series", "q=#{query}")
159
- url = URI.encode url
160
- response = @http.request(Net::HTTP::Get.new(url))
161
- series = JSON.parse(response.body)
133
+ url = URI.encode full_url("db/#{@database}/series", "q=#{query}")
134
+ series = get(url)
162
135
 
163
136
  if block_given?
164
137
  series.each { |s| yield s['name'], denormalize_series(s) }
@@ -180,6 +153,40 @@ module InfluxDB
180
153
  end
181
154
  end
182
155
 
156
+ def get(url)
157
+ response = @http.request(Net::HTTP::Get.new(url))
158
+ if response.kind_of? Net::HTTPSuccess
159
+ return JSON.parse(response.body)
160
+ elsif response.kind_of? Net::HTTPUnauthorized
161
+ raise InfluxDB::AuthenticationError.new response.body
162
+ else
163
+ raise InfluxDB::Error.new response.body
164
+ end
165
+ end
166
+
167
+ def post(url, data)
168
+ headers = {"Content-Type" => "application/json"}
169
+ response = @http.request(Net::HTTP::Post.new(url, headers), data)
170
+ if response.kind_of? Net::HTTPSuccess
171
+ return response
172
+ elsif response.kind_of? Net::HTTPUnauthorized
173
+ raise InfluxDB::AuthenticationError.new response.body
174
+ else
175
+ raise InfluxDB::Error.new response.body
176
+ end
177
+ end
178
+
179
+ def delete(url)
180
+ response = @http.request(Net::HTTP::Delete.new(url))
181
+ if response.kind_of? Net::HTTPSuccess
182
+ return response
183
+ elsif response.kind_of? Net::HTTPUnauthorized
184
+ raise InfluxDB::AuthenticationError.new response.body
185
+ else
186
+ raise InfluxDB::Error.new response.body
187
+ end
188
+ end
189
+
183
190
  def denormalize_series series
184
191
  columns = series['columns']
185
192
  series['points'].map { |point| Hash[columns.zip(point)]}
@@ -1,3 +1,3 @@
1
1
  module InfluxDB
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Persen