Class: SubZero::Client
- Inherits:
-
Object
- Object
- SubZero::Client
- Defined in:
- lib/sub_zero/client.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#sid ⇒ Object
readonly
Returns the value of attribute sid.
Instance Method Summary collapse
- #[](verb) ⇒ Object
- #call(verb, payload = {}, options = {}) ⇒ Object
- #call!(verb, payload = {}, options = {}, &block) ⇒ Object
-
#initialize(sid) {|@config| ... } ⇒ Client
constructor
A new instance of Client.
- #method_missing(method, payload = {}, options = {}, &block) ⇒ Object
- #socket ⇒ Object
Constructor Details
#initialize(sid) {|@config| ... } ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/sub_zero/client.rb', line 6 def initialize sid @sid, @config = sid.to_s.upcase, Configuration.default yield @config if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, payload = {}, options = {}, &block) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/sub_zero/client.rb', line 39 def method_missing method, payload = {}, = {}, &block if method.to_s.end_with? '!' call! method.to_s.delete('!'), payload, , &block else call method, payload, , &block end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/sub_zero/client.rb', line 4 def config @config end |
#sid ⇒ Object (readonly)
Returns the value of attribute sid.
4 5 6 |
# File 'lib/sub_zero/client.rb', line 4 def sid @sid end |
Instance Method Details
#[](verb) ⇒ Object
35 36 37 |
# File 'lib/sub_zero/client.rb', line 35 def [] verb call verb end |
#call(verb, payload = {}, options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sub_zero/client.rb', line 15 def call verb, payload = {}, = {} sz_verb = verb.to_s.upcase.gsub('_', '/') request = Message.new(type: 'REQ', subtype: sid, verb: sz_verb, payload: payload, options: ) response = socket.call(request) if block_given? yield response else fail Error.new(response) if response.error? response.payload end end |
#call!(verb, payload = {}, options = {}, &block) ⇒ Object
31 32 33 |
# File 'lib/sub_zero/client.rb', line 31 def call! verb, payload = {}, = {}, &block call verb, payload, , &block end |