Class: AgentXmpp::BaseController
- Inherits:
-
Object
- Object
- AgentXmpp::BaseController
- Defined in:
- lib/agent_xmpp/app/controller.rb
Overview
Direct Known Subclasses
Class Attribute Summary collapse
-
.routes ⇒ Object
readonly
.….….….….….….….….….….….….….….….….….….….….….….….….….….
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#pipe ⇒ Object
readonly
.….….….….….….….….….….….….….….….….….….….….….….….….….….
Class Method Summary collapse
-
.chat(opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.command_nodes ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.event(jid, node, opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.event_domains ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.execute(node, opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.route(action, nroute) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
.subscriptions(service) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
Instance Method Summary collapse
-
#handle_request ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#initialize(pipe, params) ⇒ BaseController
constructor
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#invoke_chat ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#invoke_event ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#invoke_execute ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#result_jabber_x_data(params, payload) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
-
#result_message_chat(params, payload) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
Constructor Details
#initialize(pipe, params) ⇒ BaseController
.….….….….….….….….….….….….….….….….….….….….….….….….….….
59 60 61 62 |
# File 'lib/agent_xmpp/app/controller.rb', line 59 def initialize(pipe, params) @params = params @pipe = pipe end |
Class Attribute Details
.routes ⇒ Object (readonly)
.….….….….….….….….….….….….….….….….….….….….….….….….….….
14 15 16 |
# File 'lib/agent_xmpp/app/controller.rb', line 14 def routes @routes end |
Instance Attribute Details
#params ⇒ Object (readonly)
.….….….….….….….….….….….….….….….….….….….….….….….….….….
56 57 58 |
# File 'lib/agent_xmpp/app/controller.rb', line 56 def params @params end |
#pipe ⇒ Object (readonly)
.….….….….….….….….….….….….….….….….….….….….….….….….….….
56 57 58 |
# File 'lib/agent_xmpp/app/controller.rb', line 56 def pipe @pipe end |
Class Method Details
.chat(opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
28 29 30 |
# File 'lib/agent_xmpp/app/controller.rb', line 28 def chat(opts = {}, &blk) route(:chat, {:opts => opts, :blk => blk}) end |
.command_nodes ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
38 39 40 |
# File 'lib/agent_xmpp/app/controller.rb', line 38 def command_nodes (routes[:execute] ||= []).map{|r| r[:node]} end |
.event(jid, node, opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
22 23 24 25 |
# File 'lib/agent_xmpp/app/controller.rb', line 22 def event(jid, node, opts = {}, &blk) j = Xmpp::Jid.new(jid) route(:event, {:node => "/home/#{j.domain}/#{j.node}/#{node}", :domain => j.domain, :opts => opts, :blk => blk}) end |
.event_domains ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
48 49 50 |
# File 'lib/agent_xmpp/app/controller.rb', line 48 def event_domains (routes[:event] ||= []).map{|r| r[:domain]}.uniq end |
.execute(node, opts = {}, &blk) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
17 18 19 |
# File 'lib/agent_xmpp/app/controller.rb', line 17 def execute(node, opts = {}, &blk) route(:execute, {:node => node, :opts => opts, :blk => blk}) end |
.route(action, nroute) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
33 34 35 |
# File 'lib/agent_xmpp/app/controller.rb', line 33 def route(action, nroute) (routes[action] ||= []).push(nroute).last end |
.subscriptions(service) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
43 44 45 |
# File 'lib/agent_xmpp/app/controller.rb', line 43 def subscriptions(service) (routes[:event] ||= []).inject([]){|s,r| /#{r[:domain]}/.match(service) ? s << r[:node] : s} end |
Instance Method Details
#handle_request ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….….
108 109 110 |
# File 'lib/agent_xmpp/app/controller.rb', line 108 def handle_request EventMachine.defer(method(:request).to_proc, respond_to?(:request_callback) ? method(:request_callback).to_proc : nil) end |
#invoke_chat ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/agent_xmpp/app/controller.rb', line 92 def invoke_chat route = chat_route unless route.nil? (:request, &route[:blk]) else (:request) do "#{AgentXmpp::AGENT_XMPP_NAME} #{AgentXmpp::VERSION}, #{AgentXmpp::OS_VERSION}" end end (:request_callback) do |result| add_payload_to_container(result) if result.kind_of?(String) end handle_request end |
#invoke_event ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
81 82 83 84 85 86 87 88 89 |
# File 'lib/agent_xmpp/app/controller.rb', line 81 def invoke_event route = get_route(:event) unless route.nil? (:request, &route[:blk]) handle_request else AgentXmpp.logger.error "ROUTING ERROR: no route for {:node => '#{params[:node]}'}." end end |
#invoke_execute ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/agent_xmpp/app/controller.rb', line 65 def invoke_execute route = get_route(params[:action]) unless route.nil? (:request, &route[:blk]) (:request_callback) do |*result| result = result.first if result.length.eql?(1) add_payload_to_container(result.nil? ? nil : result.to_x_data) end handle_request else AgentXmpp.logger.error "ROUTING ERROR: no route for {:node => '#{params[:node]}', :action => '#{params[:action]}'}." Xmpp::ErrorResponse.no_route(params) end end |
#result_jabber_x_data(params, payload) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….…. add payloads .….….….….….….….….….….….….….….….….….….….….….….….….….….
115 116 117 |
# File 'lib/agent_xmpp/app/controller.rb', line 115 def result_jabber_x_data(params, payload) Xmpp::IqCommand.result(:to => params[:from], :id => params[:id], :node => params[:node], :payload => payload) end |