Class: RubyBOSH

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_bosh.rb

Defined Under Namespace

Classes: AuthFailed, ConnFailed, Timeout

Constant Summary collapse

BOSH_XMLNS =
'http://jabber.org/protocol/httpbind'
TLS_XMLNS =
'urn:ietf:params:xml:ns:xmpp-tls'
SASL_XMLNS =
'urn:ietf:params:xml:ns:xmpp-sasl'
BIND_XMLNS =
'urn:ietf:params:xml:ns:xmpp-bind'
SESSION_XMLNS =
'urn:ietf:params:xml:ns:xmpp-session'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(jid, pw, service_url, opts = {}) ⇒ RubyBOSH

Returns a new instance of RubyBOSH.



21
22
23
24
25
26
27
28
29
# File 'lib/ruby_bosh.rb', line 21

def initialize(jid, pw, service_url, opts={}) 
  @service_url = service_url
  @jid, @pw = jid, pw
  @host = jid.split("@").last
  @success = false
  @timeout = opts[:timeout] || 3 #seconds 
  @headers = {"Content-Type" => "text/xml; charset=utf-8",
              "Accept" => "text/xml"}
end

Instance Attribute Details

#jidObject

Returns the value of attribute jid.



20
21
22
# File 'lib/ruby_bosh.rb', line 20

def jid
  @jid
end

#ridObject

Returns the value of attribute rid.



20
21
22
# File 'lib/ruby_bosh.rb', line 20

def rid
  @rid
end

#sidObject

Returns the value of attribute sid.



20
21
22
# File 'lib/ruby_bosh.rb', line 20

def sid
  @sid
end

#successObject

Returns the value of attribute success.



20
21
22
# File 'lib/ruby_bosh.rb', line 20

def success
  @success
end

Class Method Details

.initialize_session(*args) ⇒ Object



35
36
37
# File 'lib/ruby_bosh.rb', line 35

def self.initialize_session(*args)
  new(*args).connect
end

Instance Method Details

#connectObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ruby_bosh.rb', line 39

def connect
  initialize_bosh_session
  if send_auth_request 
    send_restart_request
    request_resource_binding
    @success = send_session_request
  end

  raise RubyBOSH::AuthFailed, "could not authenticate #{@jid}" unless success?
  @rid += 1 #updates the rid for the next call from the browser
  
  [@jid, @sid, @rid]
end

#success?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/ruby_bosh.rb', line 31

def success?
  @success == true
end