class Blather::Stream::Register

Constants

REGISTER_NS

Public Class Methods

new(stream, succeed, fail) click to toggle source
Calls superclass method Blather::Stream::Features::new
# File lib/blather/stream/features/register.rb, line 8
def initialize(stream, succeed, fail)
  super
  @jid = @stream.jid
  @pass = @stream.password
end

Public Instance Methods

receive_data(stanza) click to toggle source
# File lib/blather/stream/features/register.rb, line 14
def receive_data(stanza)
  error_node = stanza.xpath("//error").first

  if error_node
    fail!(BlatherError.new(stanza))
  elsif stanza['type'] == 'result' && (stanza.content.empty? || stanza.children.find { |v| v.element_name == "query" })
    succeed!
  else
    @stream.send register_query
  end
end
register_query() click to toggle source
# File lib/blather/stream/features/register.rb, line 26
def register_query
  node = Blather::Stanza::Iq::Query.new(:set)
  query_node = node.xpath('//query').first
  query_node['xmlns'] = 'jabber:iq:register'
  Nokogiri::XML::Builder.with(query_node) do |xml|
    xml.username @jid.node
    xml.password @pass
  end
  node
end