Class: Staticd::JSONResponse
- Inherits:
-
Object
- Object
- Staticd::JSONResponse
- Defined in:
- lib/staticd/json_response.rb
Overview
Simple HTTP response constructor for JSON content.
Example:
response = JSONResponse.send(:success, {foo: :bar})
Class Method Summary collapse
Class Method Details
.send(type, content = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/staticd/json_response.rb', line 11 def self.send(type, content=nil) case type when :success @status = 200 @body = content when :success_no_content @status = 204 when :error @status = 403 @body = {error: content} else @status = 500 @body = {error: "Something went wrong on our side."} end json_body = @body ? JSON.generate(@body) : nil [@status, json_body] end |