diff options
author | ytti <saku@ytti.fi> | 2016-08-29 18:45:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-29 18:45:10 +0300 |
commit | 29b972f0a2a11b2ca52cf290f733914914f2f3f8 (patch) | |
tree | 07138905a81b7217c400374022c89ec8f1ceea4d /extra | |
parent | dbab46d5f8228f8dd56bbca2e63405e818c598f9 (diff) | |
parent | b5011707b9193ec4ecd4c4ee8df903b7becc1a6b (diff) |
Merge pull request #467 from ldep30/patch-1
Update rest_client.rb to support 'rest' parameter
Diffstat (limited to 'extra')
-rw-r--r-- | extra/rest_client.rb | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/extra/rest_client.rb b/extra/rest_client.rb index a16bd42..35d93ae 100644 --- a/extra/rest_client.rb +++ b/extra/rest_client.rb @@ -2,8 +2,30 @@ module Oxidized class RestClient require 'net/http' require 'json' - HOST = 'localhost' - PORT = 8888 + require 'uri' + require 'asetus' + + class Config + Root = Root = ENV['OXIDIZED_HOME'] || 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}" + end + + restcfg = CFGS.cfg.rest + unless 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 +40,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 |