Class: PunkyBrewster::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/punky_brewster/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(env) ⇒ Object



21
22
23
# File 'lib/punky_brewster/server.rb', line 21

def self.call(env)
  self.new.call(env)
end

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/punky_brewster/server.rb', line 7

def call(env)
  headers = { 'Content-Type' => 'application/json' }

  begin
    body = BeerRepository.list.to_json
    status = 200
  rescue => error
    body = JSON.generate(error: "#{error.class}: #{error}")
    status = 500
  end

  [status, headers, [body]]
end