Class: Nwsdk::Endpoint
- Inherits:
-
Object
- Object
- Nwsdk::Endpoint
- Defined in:
- lib/nwsdk/endpoint.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#host ⇒ Object
Returns the value of attribute host.
-
#pass ⇒ Object
Returns the value of attribute pass.
-
#port ⇒ Object
Returns the value of attribute port.
-
#save_request ⇒ Object
Returns the value of attribute save_request.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
- #get_request(path: 'sdk', params: {}) ⇒ Object
-
#initialize(*args) {|_self| ... } ⇒ Endpoint
constructor
A new instance of Endpoint.
- #loghost ⇒ Object
- #type=(type_sym) ⇒ Object
- #uri(path = 'sdk') ⇒ Object
Constructor Details
#initialize(*args) {|_self| ... } ⇒ Endpoint
Returns a new instance of Endpoint.
11 12 13 14 15 16 17 |
# File 'lib/nwsdk/endpoint.rb', line 11 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 |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
3 4 5 |
# File 'lib/nwsdk/endpoint.rb', line 3 def config @config end |
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/nwsdk/endpoint.rb', line 3 def host @host end |
#pass ⇒ Object
Returns the value of attribute pass.
3 4 5 |
# File 'lib/nwsdk/endpoint.rb', line 3 def pass @pass end |
#port ⇒ Object
Returns the value of attribute port.
3 4 5 |
# File 'lib/nwsdk/endpoint.rb', line 3 def port @port end |
#save_request ⇒ Object
Returns the value of attribute save_request.
3 4 5 |
# File 'lib/nwsdk/endpoint.rb', line 3 def save_request @save_request end |
#user ⇒ Object
Returns the value of attribute user.
3 4 5 |
# File 'lib/nwsdk/endpoint.rb', line 3 def user @user end |
Class Method Details
.configure(conf = File.join(ENV["HOME"],".nwsdk.json")) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/nwsdk/endpoint.rb', line 4 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 |
Instance Method Details
#get_request(path: 'sdk', params: {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nwsdk/endpoint.rb', line 36 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 |
#loghost ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/nwsdk/endpoint.rb', line 52 def loghost if config.has_key?("syslog") [ config["syslog"]["loghost"], config["syslog"]["logport"]] else nil end end |
#type=(type_sym) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/nwsdk/endpoint.rb', line 19 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 |
#uri(path = 'sdk') ⇒ Object
32 33 34 |
# File 'lib/nwsdk/endpoint.rb', line 32 def uri(path='sdk') sprintf('https://%s:%d/%s', host, port, path) end |