Module: Messenger::Jabber
- Defined in:
- lib/messenger/jabber.rb
Class Method Summary collapse
-
.deliver(url, body, options = {}) ⇒ Object
URL format: jabber://[email protected]/server_hostname.
- .obfuscate(url) ⇒ Object
- .valid_url?(url) ⇒ Boolean
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, ={}) raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url) recipient, host = url.sub("jabber://", "").split("/")[0,2] jabber = ::Jabber::Simple.new([:jabber_id], [:jabber_password], host) jabber.deliver(recipient, body) = 1 until == 0 = 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
5 6 7 8 9 |
# File 'lib/messenger/jabber.rb', line 5 def self.valid_url?(url) !!matcher(url) rescue NoMethodError false end |