Class: Compp::Sprinkler
- Inherits:
-
Connection
- Object
- EM::Connection
- Connection
- Compp::Sprinkler
- Defined in:
- lib/compp/sprinkler.rb
Overview
This is the default Compp::Connection. For each GET request it receives, it extract the credentails from the headers, and connects an XMPP client. The user can define its own xmpp handlers by subclassing this class.
Constant Summary collapse
- @@xmpp_client =
nil
- @@channel =
nil
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Sprinkler
constructor
Initialize a new Compp:Connection.
-
#process_http_request ⇒ Object
Called when a user send an HTTP request.
-
#register_xmpp_handlers(client) ⇒ Object
In this case, where we broadcast, this does nothing…
Methods inherited from Connection
Constructor Details
#initialize(opts = {}) ⇒ Sprinkler
Initialize a new Compp:Connection
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/compp/sprinkler.rb', line 13 def initialize(opts = {}) if !@@xmpp_client # Right, we need to connect the xmpp client now @@xmpp_client = Blather::Client.setup(opts[:jid], opts[:password]) @@channel = EM::Channel.new @@xmpp_client.register_handler(:message) do |m| @@channel.push(m.to_xml) end @@xmpp_client.connect end @@channel.subscribe{ |msg| orbitize(msg) } end |
Instance Method Details
#process_http_request ⇒ Object
Called when a user send an HTTP request.
30 31 32 33 34 35 |
# File 'lib/compp/sprinkler.rb', line 30 def process_http_request orbitize("HTTP/1.0 200 OK")+ orbitize("Content-Type: text/xml") orbitize("Connection: close\r\n") orbitize( "<?xml version='1.0' encoding='utf-8' ?>") end |
#register_xmpp_handlers(client) ⇒ Object
In this case, where we broadcast, this does nothing… and is never called anyway!
39 40 |
# File 'lib/compp/sprinkler.rb', line 39 def register_xmpp_handlers(client) end |