Sha256: 5ede7d58fec667d372a6b433ab054c5f000ced69dabf53a8b3c1cec20fdd6811

Contents?: true

Size: 1023 Bytes

Versions: 1

Compression:

Stored size: 1023 Bytes

Contents

require 'rubygems'
require File.join(File.dirname(__FILE__), 'ticket')

require 'sinatra/base'
require 'sinatra/options-route'
require 'sinatra/response-header-helpers'

module Rack
  module TicketOffice
    class Booth < Sinatra::Base
      register Sinatra::OptionsRoute
      helpers Sinatra::ResponseHeaderHelpers
      
      attr_writer :store, :counter
      
      def template(&block)
        @template = block
      end

      options_route "/?" do
        allow :post, :options
        halt
      end
      
      [:get, :put, :delete].each do |method|
        send(method, "/") do
          allow :post, :options
          halt 405
        end
      end
      
      post "/" do
        halt 500 unless request.env['REMOTE_USER']
        new_id = @counter.next
        ticket_initialiser = @template.call(new_id)
        ticket = @store.create(ticket_initialiser)
        ticket.key = new_id.to_s
        ticket.user = request.env['REMOTE_USER']
        ticket.save
        ""
      end
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kissifer-rack-ticket-office-0.0.1 lib/rack/ticket-office/booth.rb