Module: Messenger::Jabber

Defined in:
lib/messenger/jabber.rb

Class Method Summary collapse

Class Method Details

.deliver(url, body, options = {}) ⇒ Object

URL format:

jabber://[email protected]/server_hostname

The server’s hostname is optional, but needed for Google Apps jabber accounts.

Options:

:jabber_id => The jabber id of the sender
:jabber_password => The password of the sender


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/messenger/jabber.rb', line 19

def self.deliver(url, body, options={})
  raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
  recipient, host = url.sub("jabber://", "").split("/")[0,2]
  jabber = ::Jabber::Simple.new(options[:jabber_id], options[:jabber_password], host)
  jabber.deliver(recipient, body)
  pending_messages_count = 1
  until pending_messages_count == 0
    pending_messages_count = jabber.send(:queue, :pending_messages).size
    sleep 1
  end
  status = jabber.subscribed_to?(recipient)
  Messenger::Result.new(status, status ? nil : "Not yet authorized")
end

.obfuscate(url) ⇒ Object



33
34
35
36
# File 'lib/messenger/jabber.rb', line 33

def self.obfuscate(url)
  raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url)
  url
end

.valid_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
# File 'lib/messenger/jabber.rb', line 5

def self.valid_url?(url)
  !!matcher(url)
rescue NoMethodError
  false
end