Class: Beeta::Resource::Generic
- Inherits:
-
Watts::Resource
- Object
- Watts::Resource
- Beeta::Resource::Generic
- Includes:
- Beeta
- Defined in:
- lib/beeta/resource.rb
Overview
The Generic resource, with some utility methods for the other Beeta resources.
Constant Summary
Constants included from Beeta
Instance Method Summary collapse
- #error_404 ⇒ Object
-
#json_body ⇒ Object
Returns the req_body, run through the JSON parser.
- #json_error(str, status = 400) ⇒ Object
- #json_resp(body, status = 200) ⇒ Object
-
#req_body ⇒ Object
Returns the body given with the request, as with a POST or PUT.
Methods included from Beeta
Instance Method Details
#error_404 ⇒ Object
13 14 15 |
# File 'lib/beeta/resource.rb', line 13 def error_404 @error_404 ||= json_resp({'error'=>'Not Found'}, 404) end |
#json_body ⇒ Object
Returns the req_body, run through the JSON parser. Returns nil if we can’t parse it.
24 25 26 27 28 29 30 31 |
# File 'lib/beeta/resource.rb', line 24 def json_body @json_body ||= begin JSON.parse(req_body) rescue JSON::ParserError nil end end |
#json_error(str, status = 400) ⇒ Object
42 43 44 |
# File 'lib/beeta/resource.rb', line 42 def json_error str, status = 400 json_resp({'error' => str}, status) end |
#json_resp(body, status = 200) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/beeta/resource.rb', line 33 def json_resp body, status = 200 js = JSON.unparse body [status, { 'Content-Type' => 'application/json', 'Content-Length' => js.size.to_s, }, [js]] end |
#req_body ⇒ Object
Returns the body given with the request, as with a POST or PUT.
18 19 20 |
# File 'lib/beeta/resource.rb', line 18 def req_body @req_body ||= env['rack.input'].read end |