Sha256: 48a46688fc73cc941ab0680cb937b3db1679e75c80bb2bd8ed287f28f9347b34

Contents?: true

Size: 1.08 KB

Versions: 14

Compression:

Stored size: 1.08 KB

Contents

module FakeSQS
  module Actions
    class SendMessageBatch

      def initialize(options = {})
        @server    = options.fetch(:server)
        @queues    = options.fetch(:queues)
        @responder = options.fetch(:responder)
      end

      def call(name, params)
        queue = @queues.get(name)

        messages = params.select { |k,v| k =~ /SendMessageBatchRequestEntry\.\d+\.MessageBody/ }

        results = {}

        messages.each do |key, value|
          id = key.split('.')[1]
          msg_id = params.fetch("SendMessageBatchRequestEntry.#{id}.Id")
          delay = params["SendMessageBatchRequestEntry.#{id}.DelaySeconds"]
          message = queue.send_message("MessageBody" => value, "DelaySeconds" => delay)
          results[msg_id] = message
        end

        @responder.call :SendMessageBatch do |xml|
          results.each do |msg_id, message|
            xml.SendMessageBatchResultEntry do
              xml.Id msg_id
              xml.MessageId message.id
              xml.MD5OfMessageBody message.md5
            end
          end
        end
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
fake_sqs-0.4.1 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.4.0 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.3.1 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.3.0 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.2.0 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.1.0 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.0.11 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.0.10 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.0.9 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.0.8 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.0.7 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.0.6 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.0.5 lib/fake_sqs/actions/send_message_batch.rb
fake_sqs-0.0.4 lib/fake_sqs/actions/send_message_batch.rb