Sha256: a85110bd35e82d5e224611fc295ada93801108afd2de3674fe63a70d1e01dc0d
Contents?: true
Size: 1.39 KB
Versions: 3
Compression:
Stored size: 1.39 KB
Contents
module Nwsdk class Endpoint attr_accessor :host, :port, :user, :pass, :config, :save_request def self.configure(conf=File.join(ENV["HOME"],".nwsdk.json")) config=JSON.parse(File.read(conf)) endpoint=Nwsdk::Endpoint.new(config["endpoint"]) endpoint.config=config endpoint end def initialize(*args) Hash[*args].each {|k,v| self.send("%s=" % k, v) } @port ||= 50103 @save_request||=false yield self if block_given? self end def type=(type_sym) @port=case type_sym when :broker 50103 when :decoder 50104 when :concentrator 50105 else raise ArgumentError, "invalid endpoint type #{type_sym.to_s}" end end def uri(path='sdk') sprintf('https://%s:%d/%s', host, port, path) end def get_request(path: 'sdk', params: {}) req=RestClient::Request.new( method: :get, url: uri(path), user: user, password: pass, read_timenout: nil, verify_ssl: OpenSSL::SSL::VERIFY_NONE, payload: params, headers: { "Accept-Encoding" => :deflate, accept: :json, } ) end def loghost if config.has_key?("syslog") [ config["syslog"]["loghost"], config["syslog"]["logport"]] else nil end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
nwsdk-1.2.0 | lib/nwsdk/endpoint.rb |
nwsdk-1.1.7 | lib/nwsdk/endpoint.rb |
nwsdk-1.1.3 | lib/nwsdk/endpoint.rb |