summaryrefslogtreecommitdiff
path: root/extra/rest_client.rb
diff options
context:
space:
mode:
authorldep30 <dludo59@gmail.com>2016-06-10 16:06:33 +0200
committerGitHub <noreply@github.com>2016-06-10 16:06:33 +0200
commite1559940eed40096bce292f626bac482d27c55c9 (patch)
tree43810195812d4326b7806319d0646d5d4428b4a8 /extra/rest_client.rb
parent61eb0f24eb9d246a9b92742321770667878ecc59 (diff)
Update rest_client.rb to support 'rest' parameter
Diffstat (limited to 'extra/rest_client.rb')
-rw-r--r--extra/rest_client.rb30
1 files changed, 27 insertions, 3 deletions
diff --git a/extra/rest_client.rb b/extra/rest_client.rb
index a16bd42..5809457 100644
--- a/extra/rest_client.rb
+++ b/extra/rest_client.rb
@@ -2,8 +2,32 @@ module Oxidized
class RestClient
require 'net/http'
require 'json'
- HOST = 'localhost'
- PORT = 8888
+ require 'uri'
+ require 'asetus'
+
+ class Config
+ Root = File.join ENV['HOME'], '.config', 'oxidized'
+ end
+
+ CFGS = Asetus.new :name=>'oxidized', :load=>false, :key_to_s=>true
+ CFGS.default.rest = '127.0.0.1:8888'
+
+ begin
+ CFGS.load
+ rescue => error
+ raise InvalidConfig, "Error loading config: #{error.message}"
+ ensure
+ CFG = CFGS.cfg
+ end
+
+ restcfg = CFG.rest
+ if ! restcfg.match(/^http:\/\//)
+ restcfg.insert(0, 'http://')
+ end
+
+ HOST = URI(restcfg).host
+ PORT = URI(restcfg).port
+ PATH = URI(restcfg).path
class << self
def next opt={}, host=HOST, port=PORT
@@ -18,7 +42,7 @@ module Oxidized
def next opt
data = JSON.dump opt
- @web.put '/node/next/' + opt[:name].to_s, data
+ @web.put PATH + '/node/next/' + opt[:name].to_s, data
end
end