class Blix::Rest::JsonFormatParser

Public Instance Methods

format_error(message) click to toggle source
# File lib/blix/rest/format_parser.rb, line 68
def format_error(message)
  MultiJson.dump({"error"=>message.to_s}) rescue "{\"error\":\"Internal Formatting Error\"}"
end
format_response(value, response) click to toggle source
# File lib/blix/rest/format_parser.rb, line 72
def format_response(value, response)
  if value.is_a?(RawJsonString)
    response.content = if _options[:nodata]
                         value.to_s
                       else
                         "{\"data\":#{value}}"
                       end
  else
    begin
      response.content = if _options[:nodata]
                           MultiJson.dump(value)
                         else
                           MultiJson.dump('data' => value)
                       end
    rescue Exception => e
      ::Blix::Rest.logger << e.to_s
      response.set(500, format_error('Internal Formatting Error'))
    end
  end
end
set_default_headers(headers) click to toggle source
# File lib/blix/rest/format_parser.rb, line 62
def set_default_headers(headers)
  headers[CACHE_CONTROL] = CACHE_NO_STORE
  headers[PRAGMA]       = NO_CACHE
  headers[CONTENT_TYPE] = CONTENT_TYPE_JSON
end