Class: Custodian::API

Inherits:
Object
  • Object
show all
Defined in:
lib/custodian/api.rb

Overview

The API class is a Rack-compatible* application that encapsulates Custodian’s interface.

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object

Render the JSON representation of each sample.

env - A Hash of CGI-like headers describing the

environment under which the request was received.

Returns an Array describing the HTTP response.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/custodian/api.rb', line 17

def call(env)
  status = 200

  headers = {
    "Content-Type" => "application/json"
  }

  body = Custodian::Samplers.list.collect do |sampler|
    { description: sampler.description, sample: sampler.sample } if sampler.compatible?
  end.compact.to_json

  [status, headers, [body]]
end