Sha256: 397fed94b56cb7dcd906d5ba80be9cb15862c69b5d887c32f4262f8fbed35b80

Contents?: true

Size: 1.95 KB

Versions: 56

Compression:

Stored size: 1.95 KB

Contents

module Fog
  module AWS
    class SQS
      class Real
        require 'fog/aws/parsers/sqs/send_message'

        # Add a message to a queue
        #
        # ==== Parameters
        # * queue_url<~String> - Url of queue to add message to
        # * message<~String> - Message to add to queue
        #
        # ==== See Also
        # http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference/Query_QuerySendMessage.html
        #

        def send_message(queue_url, message)
          request({
            'Action'      => 'SendMessage',
            'MessageBody' => message,
            :path         => path_from_queue_url(queue_url),
            :parser       => Fog::Parsers::AWS::SQS::SendMessage.new
          })
        end
      end

      class Mock
        def send_message(queue_url, message)
          Excon::Response.new.tap do |response|
            if (queue = data[:queues][queue_url])
              response.status = 200

              now        = Time.now
              message_id = Fog::AWS::Mock.sqs_message_id
              md5        = OpenSSL::Digest::MD5.hexdigest(message)

              queue[:messages][message_id] = {
                'MessageId'  => message_id,
                'Body'       => message,
                'MD5OfBody'  => md5,
                'Attributes' => {
                  'SenderId'      => Fog::AWS::Mock.sqs_message_id,
                  'SentTimestamp' => now
                }
              }

              queue['Attributes']['LastModifiedTimestamp'] = now

              response.body = {
                'ResponseMetadata' => {
                  'RequestId' => Fog::AWS::Mock.request_id
                },
                'MessageId'        => message_id,
                'MD5OfMessageBody' => md5
              }
            else
              response.status = 404
              raise(Excon::Errors.status_error({:expects => 200}, response))
            end
          end
        end
      end
    end
  end
end

Version data entries

56 entries across 54 versions & 2 rubygems

Version Path
fog-aws-3.30.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.29.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.28.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.27.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.26.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.25.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.24.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.23.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.22.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.21.1 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.21.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.20.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.19.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.18.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.17.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.16.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.15.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.14.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.13.0 lib/fog/aws/requests/sqs/send_message.rb
fog-aws-3.12.0 lib/fog/aws/requests/sqs/send_message.rb