Class: ZSS::Client
- Inherits:
-
Object
- Object
- ZSS::Client
- Includes:
- LoggerFacade::Loggable
- Defined in:
- lib/zss/client.rb
Instance Attribute Summary collapse
-
#frontend ⇒ Object
readonly
Returns the value of attribute frontend.
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
-
#sid ⇒ Object
readonly
Returns the value of attribute sid.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
- #call(verb, payload, headers: {}, timeout: nil) ⇒ Object
-
#initialize(sid, config = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(sid, config = {}) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/zss/client.rb', line 11 def initialize sid, config = {} @frontend = config[:frontend] || Configuration.default.frontend @sid = sid.to_s.upcase @identity = config[:identity] || "client" @timeout = config[:timeout] || 1000 @config = Hashie::Mash.new( socket_address: frontend, identity: identity, timeout: timeout ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (private)
50 51 52 53 54 55 56 |
# File 'lib/zss/client.rb', line 50 def method_missing method, *args # since we cannot use / on method names we replace _ with / verb = method.to_s.gsub('_', '/') payload = args[0] = args[1] || {} call verb, payload, end |
Instance Attribute Details
#frontend ⇒ Object (readonly)
Returns the value of attribute frontend.
9 10 11 |
# File 'lib/zss/client.rb', line 9 def frontend @frontend end |
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
9 10 11 |
# File 'lib/zss/client.rb', line 9 def identity @identity end |
#sid ⇒ Object (readonly)
Returns the value of attribute sid.
9 10 11 |
# File 'lib/zss/client.rb', line 9 def sid @sid end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/zss/client.rb', line 9 def timeout @timeout end |
Instance Method Details
#call(verb, payload, headers: {}, timeout: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/zss/client.rb', line 23 def call verb, payload, headers: {}, timeout: nil action = verb.to_s.upcase address = Message::Address.new(sid: sid, verb: action) request = Message.new( address: address, headers: headers, payload: payload) timeout ||= config.timeout = (timeout, request) log.info("Request #{request.rid} sent to #{request.address} with #{timeout/1000.0}s timeout", ) response = socket.call(request, timeout) = (timeout, response) log.info("Received response to #{request.rid} with status #{response.status}", ) fail ZSS::Error.new(response.status, payload: response.payload) if response.is_error? response.payload end |