Sha256: 17fe94e13b10b4854d3a9465053cecf7f398f565a6c413048e525a1f50f20239

Contents?: true

Size: 924 Bytes

Versions: 13

Compression:

Stored size: 924 Bytes

Contents

require 'yaml'
require 'builder'
require 'securerandom'

module FakeSQS
  class ErrorResponse

    attr_reader :error

    def initialize(error)
      @error = error
    end

    def status
      @status ||= statuses.fetch(code)
    end

    def body
      xml = Builder::XmlMarkup.new(:index => 4)
      xml.ErrorResponse do
        xml.Error do
          xml.Type type
          xml.Code code
          xml.Message error.to_s
          xml.Detail
        end
        xml.RequestId SecureRandom.uuid
      end
    end

    private

    def code
      code = error.class.name.sub(/^FakeSQS::/, '')
      if statuses.has_key?(code)
        code
      else
        "InternalError"
      end
    end

    def type
      if status < 500
        "Sender"
      else
        "Receiver"
      end
    end

    def statuses
      @statuses ||= YAML.load_file(File.expand_path('../error_responses.yml', __FILE__))
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

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