Class: Circus::Agents::Client
- Inherits:
-
Object
- Object
- Circus::Agents::Client
- Defined in:
- lib/circus/agents/client.rb
Overview
Client for XMPP based agents.
Direct Known Subclasses
Instance Method Summary collapse
- #call(to, name, params = {}, &block) ⇒ Object
-
#initialize(connection) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(connection) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/circus/agents/client.rb', line 8 def initialize(connection) @connection = connection end |
Instance Method Details
#call(to, name, params = {}, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/circus/agents/client.rb', line 12 def call(to, name, params = {}, &block) body = if params.length > 0 "#{name} #{Encoding.encode(params)}" else name end msg = Blather::Stanza::Message.new to, body msg.id = Blather::Stanza.next_id msg.thread = msg.id promise = Promise.new last = nil @connection.register_thread_handler(msg.thread) do |m| block.call(m) begin if Conversation.ended? m result = nil if last and last.body and last.body.start_with? 'ok ' result = Encoding.decode(last.body[('ok '.length)..-1]) end promise.completed!(result) else last = m end rescue puts $!, $@ end end @connection.write(msg) promise end |