Class: Blix::Rest::JsonFormatParser
Overview
the default json format parser
Instance Attribute Summary
Attributes inherited from FormatParser
#__custom_headers, #_format, #_options
Instance Method Summary
collapse
_types, #_types, accept_types
Instance Method Details
68
69
70
|
# 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
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# 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
|
62
63
64
65
66
|
# File 'lib/blix/rest/format_parser.rb', line 62
def ()
[CACHE_CONTROL] = CACHE_NO_STORE
[PRAGMA] = NO_CACHE
[CONTENT_TYPE] = CONTENT_TYPE_JSON
end
|