Sha256: d3e82ab7b08b5ab5a26fc4426fe1b7afa1c158e55a07bddd3ffc64864c663d5c

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

require "nokogiri"

module Azure
  module ServiceBus
    module Queues
      class QueueSerializer
        attr_accessor :properties

        # Please note that order IS important
        PROPERTIES = [
          'DefaultMessageTimeToLive',
          'DuplicateDetectionHistoryTimeWindow',
          'EnableBatchedOperations',
          'EnableDeadLetteringOnMessageExpiration',
          'ExtensionData',
          'IsReadOnly',
          'LockDuration',
          'MaxDeliveryCount',
          'MaxSizeInMegabytes',
          'MessageCount',
          'Path',
          'RequiresDuplicateDetection',
          'RequiresSession',
          'SizeInBytes'
        ].freeze

        def initialize(properties={})
          @properties = properties
          yield self if block_given?
        end

        def to_xml
          doc = Nokogiri::XML::Builder.new do |xml|
            xml.entry(:xmlns => 'http://www.w3.org/2005/Atom') {
              xml.content(:type => 'application/xml') {
                xml.QueueDescription('xmlns' => 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect', 'xmlns:i' => 'http://www.w3.org/2001/XMLSchema-instance') {
                  PROPERTIES.each do |p|
                    unless @properties[p].nil?
                      xml.send(p, @properties[p].to_s)
                    end
                  end
                }
              }
            }
          end
          doc.to_xml
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
azure-0.1.1 lib/azure/service_bus/queues/queue_serializer.rb
azure-0.1.0 lib/azure/service_bus/queues/queue_serializer.rb