Sha256: 2be8f9c5b22d205c8bc66654ccb3f4da323b2e5012a2bf3847dc0c6c83cae738

Contents?: true

Size: 1 KB

Versions: 27

Compression:

Stored size: 1 KB

Contents

# encoding: UTF-8

module Vines
  class Stanza
    class PubSub
      class Create < PubSub
        NS = NAMESPACES[:pubsub]

        register "/iq[@id and @type='set']/ns:pubsub/ns:create", 'ns' => NS

        def process
          return if route_iq || !allowed?
          validate_to_address

          node = self.xpath('ns:pubsub/ns:create', 'ns' => NS)
          raise StanzaErrors::BadRequest.new(self, 'modify') if node.size != 1
          node = node.first

          id = (node['node'] || '').strip
          id = Kit.uuid if id.empty?
          raise StanzaErrors::Conflict.new(self, 'cancel') if pubsub.node?(id)
          pubsub.add_node(id)
          send_result_iq(id)
        end

        private

        def send_result_iq(id)
          el = to_result
          el << el.document.create_element('pubsub') do |node|
            node.default_namespace = NS
            node << el.document.create_element('create', 'node' => id)
          end
          stream.write(el)
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 4 rubygems

Version Path
diaspora-vines-0.2.0.develop.4 lib/vines/stanza/pubsub/create.rb
diaspora-vines-0.2.0.develop.3 lib/vines/stanza/pubsub/create.rb
diaspora-vines-0.2.0.develop.2 lib/vines/stanza/pubsub/create.rb
diaspora-vines-0.2.0.develop.1 lib/vines/stanza/pubsub/create.rb
diaspora-vines-0.1.28 lib/vines/stanza/pubsub/create.rb
lygneo-vines-0.1.5 lib/vines/stanza/pubsub/create.rb
lygneo-vines-0.1.1 lib/vines/stanza/pubsub/create.rb
diaspora-vines-0.1.27 lib/vines/stanza/pubsub/create.rb
diaspora-vines-0.1.26 lib/vines/stanza/pubsub/create.rb
diaspora-vines-0.1.25 lib/vines/stanza/pubsub/create.rb
diaspora-vines-0.1.24 lib/vines/stanza/pubsub/create.rb
vines-0.4.10 lib/vines/stanza/pubsub/create.rb
diaspora-vines-0.1.22 lib/vines/stanza/pubsub/create.rb
diaspora-vines-0.1.21 lib/vines/stanza/pubsub/create.rb
diaspora-vines-0.1.2 lib/vines/stanza/pubsub/create.rb
vines-0.4.9 lib/vines/stanza/pubsub/create.rb
vines-0.4.8 lib/vines/stanza/pubsub/create.rb
vines-0.4.7 lib/vines/stanza/pubsub/create.rb
vines-0.4.6 lib/vines/stanza/pubsub/create.rb
vinesmod-0.4.5.2 lib/vines/stanza/pubsub/create.rb