lib/apiculture/sinatra_instance_methods.rb in apiculture-0.0.17 vs lib/apiculture/sinatra_instance_methods.rb in apiculture-0.0.18
- old
+ new
@@ -1,15 +1,16 @@
require 'json'
# Some sugary methods for use within Sinatra, when responding to a request/rendering JSON
module Apiculture::SinatraInstanceMethods
NEWLINE = "\n"
+ DEFAULT = :__default__
# Convert the given structure to JSON, set the content-type and
# return the JSON string
- def json_response(structure, status: 200)
+ def json_response(structure, status: DEFAULT)
content_type :json
- status status
+ status(status) unless status == DEFAULT
JSON.pretty_generate(structure)
end
# Bail out from an action by sending a halt() via Sinatra. Is most useful for
# handling access denied, invalid resource and other types of situations