Skip to content

Instantly share code, notes, and snippets.

@tomtaylor
Created September 24, 2008 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomtaylor/12598 to your computer and use it in GitHub Desktop.
Save tomtaylor/12598 to your computer and use it in GitHub Desktop.
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