Sha256: 5a1e48b2e643a796ad5c051515a3e84667ddbc36da050411e2b0e3af70b4ca1f

Contents?: true

Size: 1014 Bytes

Versions: 5

Compression:

Stored size: 1014 Bytes

Contents

module Oxidized
  class RestClient
    require 'net/http'
    require 'json'
    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
        web = new host, port
        web.next opt
      end
    end

    def initialize host=HOST, port=PORT
      @web = Net::HTTP.new host, port
    end

    def next opt
      data = JSON.dump opt
      @web.put PATH + '/node/next/' + opt[:name].to_s, data
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
oxidized-0.21.0 extra/rest_client.rb
oxidized-0.20.0 extra/rest_client.rb
oxidized-0.19.0 extra/rest_client.rb
oxidized-0.18.0 extra/rest_client.rb
oxidized-0.17.0 extra/rest_client.rb