Sha256: 9305b494670c952488fdc19d99c429040bddb27c214c09b4336fb66332ab47f1

Contents?: true

Size: 708 Bytes

Versions: 5

Compression:

Stored size: 708 Bytes

Contents

module CukeQ
  class WebApp
    attr_reader :uri

    def initialize(uri)
      @uri = uri
    end

    def run(callback)
      @callback = callback
      handler.run(self, :Host => @uri.host, :Port => @uri.port)
    end

    def call(env)
      log self.class, :called

      request = Rack::Request.new(env)

      unless request.post?
        return [405, {'Allow' => 'POST'}, []]
      end

      begin
        data = JSON.parse(request.body.read)
        @callback.call(data) if @callback
      rescue JSON::ParserError
        return [406, {'Content-Type' => 'application/json'}, []]
      end

      [202, {}, %w[ok]]
    end

    def handler
      Rack::Handler::Thin
    end

  end # App
end # CukeQ

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cukeq-0.0.1.dev5 lib/cukeq/webapp.rb
cukeq-0.0.1.dev4 lib/cukeq/webapp.rb
cukeq-0.0.1.dev3 lib/cukeq/webapp.rb
cukeq-0.0.1.dev2 lib/cukeq/webapp.rb
cukeq-0.0.1.dev lib/cukeq/webapp.rb