Sha256: 371821dcb01d8fee8c3d85ebd432516248be92759b54e44f3a0c817d2dd1ec6e

Contents?: true

Size: 493 Bytes

Versions: 3

Compression:

Stored size: 493 Bytes

Contents

require 'json'
require 'punky_brewster'

module PunkyBrewster
  class Server
    def self.call(env)
      headers = { 'Content-Type' => 'application/json' }

      begin
        beers = BeerListRequest.new.beers
        beers_properties = beers.map(&:to_h)
        body = JSON.generate(beers_properties)
        status = 200
      rescue => error
        body = JSON.generate(error: "#{error.class}: #{error}")
        status = 500
      end

      [status, headers, [body]]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
punky_brewster-1.3.1 lib/punky_brewster/server.rb
punky_brewster-1.3.0 lib/punky_brewster/server.rb
punky_brewster-1.2.0 lib/punky_brewster/server.rb