8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/monkey_party/rack/app.rb', line 8
def call(env)
@env = env
body, content_type = nil, nil
if request.params["subscriber"]
@results = MonkeyParty.list.create_subscribers([subscriber])
if results[0].valid?
@status = 201
else
@status = 421
end
else
@status = 412
end
if request.path =~ /.json$/
body = results[0].to_h.to_json
content_type = "application/json"
else
body = html_body
content_type = "text/html"
end
::Rack::Response.new(body || [], status, {
"Content-Type" => content_type
}).finish
end
|