influxdb 0.1.6 → 0.1.7

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: d2a420cee21fd581baa624089984defee6907a8c
4
- data.tar.gz: 5dfb27c78ace10b2a8c9c84bc98bcc49024000f9
3
+ metadata.gz: 340e103295b0398a309d3e05e64da660e9fc220e
4
+ data.tar.gz: 794b43a718b6a3d0a4cd9779a428958d228b400f
5
5
  SHA512:
6
- metadata.gz: 38af5bb53a3dc79ba014c64d98464d0653ad004f795e89545e1ec8d25fbb501c5001c2bc2c8c59a6cafd30069e8266b2d02ad916f1dafb80e9b3196136727e3a
7
- data.tar.gz: 87d24e5dcbe7d02beddaa522759e8897b388a3da15f54fe5646d7affb0397aa492d84430b0514f82c967852b594a03747ae42559b9c7082567e3878cd845415d
6
+ metadata.gz: 9b2e87b5273b7b7d593ae48a0d90d375a2bb16a5c6f3ea207b163082fbb8ce8b4441b821f3238fedd1963b351003d455e0d06db2a767f8f19144234b351193b9
7
+ data.tar.gz: 6441b368ba226e0ff02dbc064a8ff8ba38f1a3de473e2329959d7bd4ee45a02bbfb88443dcdc4d5da2463e791bef77ba77a40db10a29ddd0c2f3dfefbdfdc14b
data/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  language: ruby
2
+ before_install:
3
+ - gem update bundler
2
4
  rvm:
3
- - 1.8.7
5
+ - 1.8.7-p374
4
6
  - ree
5
7
  - 1.9.3
6
8
  - 2.0.0
data/README.md CHANGED
@@ -223,5 +223,5 @@ Testing
223
223
  git clone git@github.com:influxdb/influxdb-ruby.git
224
224
  cd influxdb-ruby
225
225
  bundle
226
- bundle exec rspec
226
+ bundle exec rake
227
227
  ```
@@ -1,4 +1,5 @@
1
1
  require 'uri'
2
+ require 'cgi'
2
3
  require 'net/http'
3
4
  require 'net/https'
4
5
  require 'json'
@@ -53,6 +54,7 @@ module InfluxDB
53
54
  @open_timeout = opts[:write_timeout] || 5
54
55
  @read_timeout = opts[:read_timeout] || 300
55
56
  @async = opts[:async] || false
57
+ @retry = opts.fetch(:retry) { true }
56
58
 
57
59
  @worker = InfluxDB::Worker.new(self) if @async
58
60
 
@@ -61,62 +63,62 @@ module InfluxDB
61
63
 
62
64
  ## allow options, e.g. influxdb.create_database('foo', replicationFactor: 3)
63
65
  def create_database(name, options = {})
64
- url = full_url("db")
66
+ url = full_url("/db")
65
67
  options[:name] = name
66
68
  data = JSON.generate(options)
67
69
  post(url, data)
68
70
  end
69
71
 
70
72
  def delete_database(name)
71
- delete full_url("db/#{name}")
73
+ delete full_url("/db/#{name}")
72
74
  end
73
75
 
74
76
  def get_database_list
75
- get full_url("db")
77
+ get full_url("/db")
76
78
  end
77
79
 
78
80
  def create_cluster_admin(username, password)
79
- url = full_url("cluster_admins")
81
+ url = full_url("/cluster_admins")
80
82
  data = JSON.generate({:name => username, :password => password})
81
83
  post(url, data)
82
84
  end
83
85
 
84
86
  def update_cluster_admin(username, password)
85
- url = full_url("cluster_admins/#{username}")
87
+ url = full_url("/cluster_admins/#{username}")
86
88
  data = JSON.generate({:password => password})
87
89
  post(url, data)
88
90
  end
89
91
 
90
92
  def delete_cluster_admin(username)
91
- delete full_url("cluster_admins/#{username}")
93
+ delete full_url("/cluster_admins/#{username}")
92
94
  end
93
95
 
94
96
  def get_cluster_admin_list
95
- get full_url("cluster_admins")
97
+ get full_url("/cluster_admins")
96
98
  end
97
99
 
98
100
  def create_database_user(database, username, password)
99
- url = full_url("db/#{database}/users")
101
+ url = full_url("/db/#{database}/users")
100
102
  data = JSON.generate({:name => username, :password => password})
101
103
  post(url, data)
102
104
  end
103
105
 
104
106
  def update_database_user(database, username, options = {})
105
- url = full_url("db/#{database}/users/#{username}")
107
+ url = full_url("/db/#{database}/users/#{username}")
106
108
  data = JSON.generate(options)
107
109
  post(url, data)
108
110
  end
109
111
 
110
112
  def delete_database_user(database, username)
111
- delete full_url("db/#{database}/users/#{username}")
113
+ delete full_url("/db/#{database}/users/#{username}")
112
114
  end
113
115
 
114
116
  def get_database_user_list(database)
115
- get full_url("db/#{database}/users")
117
+ get full_url("/db/#{database}/users")
116
118
  end
117
119
 
118
120
  def get_database_user_info(database, username)
119
- get full_url("db/#{database}/users/#{username}")
121
+ get full_url("/db/#{database}/users/#{username}")
120
122
  end
121
123
 
122
124
  def alter_database_privilege(database, username, admin=true)
@@ -124,7 +126,7 @@ module InfluxDB
124
126
  end
125
127
 
126
128
  def continuous_queries(database)
127
- get full_url("db/#{database}/continuous_queries")
129
+ get full_url("/db/#{database}/continuous_queries")
128
130
  end
129
131
 
130
132
  def write_point(name, data, async=@async, time_precision=@time_precision)
@@ -146,13 +148,13 @@ module InfluxDB
146
148
  end
147
149
 
148
150
  def _write(payload, time_precision=@time_precision)
149
- url = full_url("db/#{@database}/series", "time_precision=#{time_precision}")
151
+ url = full_url("/db/#{@database}/series", :time_precision => time_precision)
150
152
  data = JSON.generate(payload)
151
153
  post(url, data)
152
154
  end
153
155
 
154
156
  def query(query, time_precision=@time_precision)
155
- url = URI.encode full_url("db/#{@database}/series", "q=#{query}&time_precision=#{time_precision}")
157
+ url = full_url("/db/#{@database}/series", :q => query, :time_precision => time_precision)
156
158
  series = get(url)
157
159
 
158
160
  if block_given?
@@ -176,11 +178,14 @@ module InfluxDB
176
178
  end
177
179
 
178
180
  private
179
- def full_url(path, params=nil)
180
- "".tap do |url|
181
- url << "/#{path}?u=#{@username}&p=#{@password}"
182
- url << "&#{params}" unless params.nil?
183
- end
181
+
182
+ def full_url(path, params={})
183
+ params[:u] = @username
184
+ params[:p] = @password
185
+
186
+ query = params.map { |k, v| [CGI.escape(k.to_s), "=", CGI.escape(v.to_s)].join }.join("&")
187
+
188
+ URI::Generic.build(:path => path, :query => query).to_s
184
189
  end
185
190
 
186
191
  def get(url)
@@ -236,8 +241,9 @@ module InfluxDB
236
241
  block.call(http)
237
242
 
238
243
  rescue Timeout::Error, *InfluxDB::NET_HTTP_EXCEPTIONS => e
239
- log :error, "Failed to contact host #{host}: #{e.inspect} #{"- retrying in #{delay}s." unless stopped?}"
244
+ log :error, "Failed to contact host #{host}: #{e.inspect} #{"- retrying in #{delay}s." if retry?}"
240
245
  log :info, "Queue size is #{@queue.length}." unless @queue.nil?
246
+ stop! unless retry?
241
247
  if stopped?
242
248
  raise e
243
249
  else
@@ -250,6 +256,10 @@ module InfluxDB
250
256
  end
251
257
  end
252
258
 
259
+ def retry?
260
+ !stopped? && @retry
261
+ end
262
+
253
263
  def denormalize_series series
254
264
  columns = series['columns']
255
265
 
@@ -1,3 +1,3 @@
1
1
  module InfluxDB
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -3,9 +3,11 @@ require "json"
3
3
 
4
4
  describe InfluxDB::Client do
5
5
  before do
6
- @influxdb = InfluxDB::Client.new "database", :host => "influxdb.test",
7
- :port => 9999, :username => "username", :password => "password", :time_precision => "s"
6
+ @influxdb = InfluxDB::Client.new "database", {
7
+ :host => "influxdb.test", :port => 9999, :username => "username",
8
+ :password => "password", :time_precision => "s" }.merge(args)
8
9
  end
10
+ let(:args) { {} }
9
11
 
10
12
  describe "#new" do
11
13
  describe "with no parameters specified" do
@@ -289,6 +291,13 @@ describe InfluxDB::Client do
289
291
  expect { subject }.to raise_error(Timeout::Error)
290
292
  end
291
293
 
294
+ context "when retry disabled" do
295
+ let(:args) { { :retry => false } }
296
+
297
+ it "raises" do
298
+ expect { subject }.to raise_error(Timeout::Error)
299
+ end
300
+ end
292
301
  end
293
302
 
294
303
  it "raise an exception if the server didn't return 200" do
@@ -481,4 +490,15 @@ describe InfluxDB::Client do
481
490
  @influxdb.query('select * from orders').should == {'orders' => [{'id' => 1, 'line_items' => line_items}]}
482
491
  end
483
492
  end
493
+
494
+ describe "#full_url" do
495
+ it "should return String" do
496
+ @influxdb.send(:full_url, "/unknown").should be_a String
497
+ end
498
+
499
+ it "should escape params" do
500
+ url = @influxdb.send(:full_url, "/unknown", :value => ' !@#$%^&*()/\\_+-=?|`~')
501
+ url.should include("value=+%21%40%23%24%25%5E%26%2A%28%29%2F%5C_%2B-%3D%3F%7C%60%7E")
502
+ end
503
+ end
484
504
  end
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.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Persen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-10 00:00:00.000000000 Z
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json