Sha256: 216f85042a54c207d1733cd45cd58d95613f294bc2aa6a2f33a0a92d2cc36722

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

require 'sinatra/base'
require 'fake_sqs/helper'
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']
        queue_name = Helper::queue_from_url(params['QueueUrl'])
        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.2 lib/fake_sqs/web_interface.rb