Sha256: a7ba3a3fa754ff686bf926ebc279f8e96954a29ec29d64d7d321b89cd4f48fab

Contents?: true

Size: 994 Bytes

Versions: 1

Compression:

Stored size: 994 Bytes

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
      params['logger'] = logger
      if params['QueueUrl']
        queue = URI.parse(params['QueueUrl']).path.gsub(/\//, '')
        return settings.api.call(action, queue, params) unless queue.empty?
      end

      settings.api.call(action, params)
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

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