Class: XMPPAgent
Instance Method Summary collapse
- #add_route(arg) ⇒ Object
- #conn ⇒ Object
-
#initialize ⇒ XMPPAgent
constructor
A new instance of XMPPAgent.
- #message(route, &blk) ⇒ Object
- #messages(params, conn, ctx) ⇒ Object
- #presence_update(ctx) ⇒ Object
- #received(conn, ctx) ⇒ Object
Constructor Details
#initialize ⇒ XMPPAgent
Returns a new instance of XMPPAgent.
11 12 13 14 |
# File 'lib/xmpp-agent.rb', line 11 def initialize() @routes = {}; @params = {}; @conn = nil; @ctx = nil super() end |
Instance Method Details
#add_route(arg) ⇒ Object
50 51 52 |
# File 'lib/xmpp-agent.rb', line 50 def add_route(arg) get(arg) {yield(@params, @conn, @ctx)} end |
#conn ⇒ Object
58 |
# File 'lib/xmpp-agent.rb', line 58 def conn() @conn end |
#message(route, &blk) ⇒ Object
54 55 56 |
# File 'lib/xmpp-agent.rb', line 54 def (route, &blk) get(route, &blk) end |
#messages(params, conn, ctx) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/xmpp-agent.rb', line 24 def (params, conn, ctx) %r{(send_to|send2)\s+([^\s]+)\s+(.*)} do user, = params[:captures].values_at 1,2 data = conn.('to' => user) {|xml| xml.body() } conn.send_stanza data end 'help' do data = conn.('to' => ctx.from) do |xml| xml.body('available commands: help, send_to') end conn.send_stanza data end '.*' do data = conn.('to' => ctx.from) do |xml| xml.body('need some help? type help') end conn.send_stanza data end end |
#presence_update(ctx) ⇒ Object
60 61 |
# File 'lib/xmpp-agent.rb', line 60 def presence_update(ctx) end |
#received(conn, ctx) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/xmpp-agent.rb', line 16 def received(conn,ctx) @conn = conn @ctx = ctx (@params, @conn, @ctx) run_route ctx.body.strip end |