Class: Blather::Stream::Register

Inherits:
Features
  • Object
show all
Defined in:
lib/blather/stream/features/register.rb

Constant Summary collapse

REGISTER_NS =
"http://jabber.org/features/iq-register".freeze

Instance Method Summary collapse

Methods inherited from Features

#fail!, #feature?, from_namespace, #next!, register, #succeed!

Constructor Details

#initialize(stream, succeed, fail) ⇒ Register

Returns a new instance of Register.



8
9
10
11
12
# File 'lib/blather/stream/features/register.rb', line 8

def initialize(stream, succeed, fail)
  super
  @jid = @stream.jid
  @pass = @stream.password
end

Instance Method Details

#receive_data(stanza) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# 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_queryObject



26
27
28
29
30
31
32
33
34
35
# 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