Sha256: a5a268e726820c4a29b1dc946fb4e6a6d08ba5bac8accd94e23b1c75731c72d3

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'sinatra/base'
require 'fake_sqs/catch_errors'
require 'fake_sqs/error_response'

module FakeSQS
  class WebInterface < Sinatra::Base

    def self.handle(path, verbs, &block)
      verbs.each do |verb|
        send(verb, path, &block)
      end
    end

    configure do
      use FakeSQS::CatchErrors, response: ErrorResponse
    end

    helpers do
      def action
        params.fetch("Action")
      end
    end

    get "/ping" do
      200
    end

    delete "/" do
      settings.api.reset
      200
    end

    put "/" do
      settings.api.expire
      200
    end

    handle "/", [:get, :post] do
      if params['QueueUrl']
        uri = URI.parse(params['QueueUrl'])
        queue_name = uri.path.tr('/', '')
        return settings.api.call(action, request, queue_name, params) unless queue_name.empty?
      end

      settings.api.call(action, request, params)
    end

    handle "/:queue_name", [:get, :post] do |queue_name|
      settings.api.call(action, request, queue_name, params)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fake_sqs-0.4.3 lib/fake_sqs/web_interface.rb