Created
September 24, 2008 16:40
-
-
Save tomtaylor/12598 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'xmpp4r-simple' | |
module ActiveMessaging | |
module Adapters | |
module Xmpp | |
class Connection | |
include ActiveMessaging::Adapter | |
register :xmpp | |
def initialize(cfg) | |
jabber_id = cfg[:jabber_id] | |
password = cfg[:password] | |
@jabber = Jabber::Simple.new(jabber_id, password) | |
@jabber.accept_subscriptions = true | |
logger.info "Jabber Connected." if @jabber.connected? | |
end | |
def disconnect | |
@jabber.disconnect | |
end | |
def receive | |
sleep 0.01 # this is horrible | |
message = @jabber.received_messages.shift | |
message ? Message.new(message) : nil | |
end | |
def send destination_name, message_body, message_headers = {} | |
@jabber.deliver message_body[:to], message_body[:body] | |
end | |
def received message, message_headers = {} | |
end | |
def subscribe destination_name, message_headers={} | |
end | |
def unsubscribe destination_name, message_headers={} | |
end | |
end | |
class Message | |
attr_accessor :headers, :body | |
def initialize body | |
@body = body | |
@headers = {} | |
@headers['destination'] = 'jabber' | |
end | |
def command | |
'MESSAGE' | |
end | |
def to_s | |
"<Xmpp::Message body='#{body}' headers='#{headers.inspect}' command='#{command}' >" | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment