Class: ZSS::Client
- Inherits:
-
Object
- Object
- ZSS::Client
- 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 = nil, headers: {}, timeout: nil) ⇒ Object
-
#initialize(sid, config = nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(sid, config = nil) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 |
# File 'lib/zss/client.rb', line 8 def initialize sid, config = nil @frontend = config.try(:frontend) || Configuration.default.frontend @sid = sid.to_s.upcase @identity = config.try(:identity) || "client" @timeout = config.try(:timeout) || 1000 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, payload = nil, headers: {}) ⇒ Object (private)
32 33 34 35 36 |
# File 'lib/zss/client.rb', line 32 def method_missing method, payload = nil, headers: {} # since we cannot use / on method names we replace _ with / verb = method.to_s.gsub('_', '/') call verb, payload, headers: headers end |
Instance Attribute Details
#frontend ⇒ Object (readonly)
Returns the value of attribute frontend.
6 7 8 |
# File 'lib/zss/client.rb', line 6 def frontend @frontend end |
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
6 7 8 |
# File 'lib/zss/client.rb', line 6 def identity @identity end |
#sid ⇒ Object (readonly)
Returns the value of attribute sid.
6 7 8 |
# File 'lib/zss/client.rb', line 6 def sid @sid end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
6 7 8 |
# File 'lib/zss/client.rb', line 6 def timeout @timeout end |
Instance Method Details
#call(verb, payload = nil, headers: {}, timeout: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/zss/client.rb', line 15 def call verb, payload = nil, headers: {}, timeout: nil action = verb.to_s.upcase#.gsub('_', '/') address = Message::Address.new(sid: sid, verb: action) request = Message.new( address: address, headers: headers, payload: payload) response = socket.call(request) fail ZSS::Error.new(response.status, response.payload) if response.is_error? response.payload end |