diff options
author | Matthias H <apoc@sixserv.org> | 2015-01-12 11:26:16 +0100 |
---|---|---|
committer | Matthias H <apoc@sixserv.org> | 2015-01-12 11:26:16 +0100 |
commit | c5ee1de18a464075f00b6f348d494302f751e5e5 (patch) | |
tree | 22cedc7662ba30a4830ff630b193b9198a43083e | |
parent | 351856db71def8fdfc074c065a84a428b521f9f2 (diff) |
web service: response helper methods
-rw-r--r-- | lib/rbot/core/webservice.rb | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/rbot/core/webservice.rb b/lib/rbot/core/webservice.rb index 297771a8..c3e61f49 100644 --- a/lib/rbot/core/webservice.rb +++ b/lib/rbot/core/webservice.rb @@ -102,18 +102,26 @@ class Bot true end - # Sends a plaintext response - def send_plaintext(body, status=200) + # Sends a response with the specified body, status and content type. + def send_response(body, status, type) @res.status = status - @res['Content-Type'] = 'text/plain' + @res['Content-Type'] = type @res.body = body end + # Sends a plaintext response + def send_plaintext(body, status=200) + send_response(body, status, 'text/plain') + end + # Sends a json response def send_json(body, status=200) - @res.status = status - @res['Content-Type'] = 'application/json' - @res.body = body + send_response(body, status, 'application/json') + end + + # Sends a html response + def send_html(body, status=200) + send_response(body, status, 'text/html') end end |