Sha256: d60df612bb856b1583f0819377de61fd0ac2eeae977e85542ae8c5daf37f31d4

Contents?: true

Size: 1001 Bytes

Versions: 21

Compression:

Stored size: 1001 Bytes

Contents

module Blather
  class Stream
    class Register < Features
      REGISTER_NS = "http://jabber.org/features/iq-register".freeze

      register REGISTER_NS

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

      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

      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
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
blather-2.0.0 lib/blather/stream/features/register.rb
blather-1.2.0 lib/blather/stream/features/register.rb
blather-1.1.4 lib/blather/stream/features/register.rb
blather-1.1.3 lib/blather/stream/features/register.rb
blather-1.1.2 lib/blather/stream/features/register.rb
blather-1.1.1 lib/blather/stream/features/register.rb
blather-1.1.0 lib/blather/stream/features/register.rb
blather-1.0.0 lib/blather/stream/features/register.rb
blather-0.8.8 lib/blather/stream/features/register.rb
blather-0.8.7 lib/blather/stream/features/register.rb
blather-0.8.6 lib/blather/stream/features/register.rb
blather-0.8.5 lib/blather/stream/features/register.rb
blather-0.8.4 lib/blather/stream/features/register.rb
blather-0.8.3 lib/blather/stream/features/register.rb
blather-0.8.2 lib/blather/stream/features/register.rb
tp-blather-0.8.5 lib/blather/stream/features/register.rb
tp-blather-0.8.4 lib/blather/stream/features/register.rb
tp-blather-0.8.3 lib/blather/stream/features/register.rb
tp-blather-0.8.2 lib/blather/stream/features/register.rb
blather-0.8.1 lib/blather/stream/features/register.rb