]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
web service: response helper methods
authorMatthias H <apoc@sixserv.org>
Mon, 12 Jan 2015 10:26:16 +0000 (11:26 +0100)
committerMatthias H <apoc@sixserv.org>
Mon, 12 Jan 2015 10:26:16 +0000 (11:26 +0100)
lib/rbot/core/webservice.rb

index 297771a8751035c8e961253969f05c4725df4c70..c3e61f49e2be43983d20b5e7c3004bcfda0bd3c8 100644 (file)
@@ -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