Sha256: be26f9f08e10be5c2da0571bfda8fbb8dd98b6f91a0558240d87527007a592c6

Contents?: true

Size: 912 Bytes

Versions: 3

Compression:

Stored size: 912 Bytes

Contents

module Mirage
  class Server < Sinatra::Base
    get '/templates/:id/preview' do
      send_response(MockResponse.find_by_id(response_id), '', {}, '')
    end

    delete '/templates/:id' do
      synchronize do
        MockResponse.delete(response_id)
        REQUESTS.delete(response_id)
      end

      200
    end

    put '/templates/*' do |name|
      content_type :json
      name = "/#{name}"
      mock_response = synchronize do
        MockResponse.new(name, JSON.parse(request.body.read))
      end

      mock_response.requests_url = request.url.gsub("/templates#{name}", "/requests/#{mock_response.response_id}")
      {:id => mock_response.response_id}.to_json
    end


    delete '/templates' do
      synchronize do
        REQUESTS.clear
        MockResponse.delete_all
      end

      200
    end

    get '/templates/:id' do
      MockResponse.find_by_id(response_id).raw
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mirage-4.0.0.alpha10 server/routes/templates.rb
mirage-4.0.0.alpha9 server/routes/templates.rb
mirage-4.0.0.alpha8 server/routes/templates.rb