var mpackages = config.catalog.mpackages.values.to_a
mpackages_sorter.sort(mpackages)
var response = new JsonArray.from(mpackages)
- res.json paginate(response, response.length, page, limit)
+ res.api_json(req, paginate(response, response.length, page, limit))
end
end
super APICatalogHandler
redef fun get(req, res) do
- res.json config.catalog.catalog_stats
+ res.api_json(req, config.catalog.catalog_stats)
end
end
if not config.catalog.tag2proj.has_key(tag) then continue
obj[tag] = config.catalog.tag2proj[tag].length
end
- res.json obj
+ res.api_json(req, obj)
end
end
mpackages_sorter.sort(mpackages)
var response = new JsonArray.from(mpackages)
obj["packages"] = paginate(response, response.length, page, limit)
- res.json obj
+ res.api_json(req, obj)
end
end
redef fun get(req, res) do
var person = get_person(req, res)
if person == null then return
- res.json person
+ res.api_json(req, person)
end
end
end
mpackages_sorter.sort(array)
var response = new JsonArray.from(array)
- res.json paginate(response, response.length, page, limit)
+ res.api_json(req, paginate(response, response.length, page, limit))
end
end
end
mpackages_sorter.sort(array)
var response = new JsonArray.from(array)
- res.json paginate(response, response.length, page, limit)
+ res.api_json(req, paginate(response, response.length, page, limit))
end
end
# Special case for packages (catalog view)
if mentity isa MPackage then
- res.raw_json mentity.to_full_catalog_json(plain=true, config.mainmodule, config.catalog)
+ res.raw_json mentity.to_full_catalog_json(config.catalog, plain = true, pretty = req.bool_arg("pretty"))
else
- res.raw_json mentity.to_full_json(config.mainmodule)
+ res.api_full_json(req, mentity)
end
end
end
super APIFeedBack
redef fun get(req, res) do
- res.json new JsonArray.from(config.stars.most_rated)
+ res.api_json(req, new JsonArray.from(config.stars.most_rated))
end
end
super APIFeedBack
redef fun get(req, res) do
- res.json new JsonArray.from(config.stars.best_rated)
+ res.api_json(req, new JsonArray.from(config.stars.best_rated))
end
end
super APIFeedBack
redef fun get(req, res) do
- res.json new JsonArray.from(config.stars.worst_rated)
+ res.api_json(req, new JsonArray.from(config.stars.worst_rated))
end
end
super APIFeedBack
redef fun get(req, res) do
- res.json new JsonArray.from(config.stars.users_ratings)
+ res.api_json(req, new JsonArray.from(config.stars.users_ratings))
end
end
redef fun get(req, res) do
var user = get_session_user(req)
if user == null then return
- res.json new JsonArray.from(user.ratings(config))
+ res.api_json(req, new JsonArray.from(user.ratings(config)))
end
end
var login = get_session_login(req)
var mentity = mentity_from_uri(req, res)
if mentity == null then return
- res.json mentity.ratings(config, login)
+ res.api_json(req, mentity.ratings(config, login))
end
end
if mentity == null then return
var dimension = req.param("dimension")
if dimension == null then return
- res.json mentity.ratings_by_dimension(config, dimension, login)
+ res.api_json(req, mentity.ratings_by_dimension(config, dimension, login))
end
redef fun post(req, res) do
else
config.stars.save new StarRating(login, mentity.full_name, dimension, rating)
end
- res.json mentity.ratings_by_dimension(config, dimension, login)
+ res.api_json(req, mentity.ratings_by_dimension(config, dimension, login))
end
end
redef fun post(req, res) do
var hl = new HtmlightVisitor
var hlcode = hl.highlightcode(req.body)
- res.json(hlcode)
+ res.api_json(req, hlcode)
end
end
res.api_error(404, "No metric for mentity `{mentity.full_name}`")
return
end
- res.json metrics
+ res.api_json(req, metrics)
end
end
var mentities = list_mentities(req)
mentities = sort_mentities(req, mentities)
mentities = limit_mentities(req, mentities)
- res.json new JsonArray.from(mentities)
+ res.api_json(req, new JsonArray.from(mentities))
end
end
var page = req.int_arg("p")
var limit = req.int_arg("n")
var response = new JsonArray.from(search(query, limit))
- res.json paginate(response, response.length, page, limit)
+ res.api_json(req, paginate(response, response.length, page, limit))
end
fun search(query: String, limit: nullable Int): Array[MEntity] do
mentities = filter_mentities(req, mentities)
mentities = randomize_mentities(req, mentities)
mentities = limit_mentities(req, mentities)
- res.json new JsonArray.from(mentities)
+ res.api_json(req, new JsonArray.from(mentities))
end
end
redef fun get(req, res) do
var mentity = mentity_from_uri(req, res)
if mentity == null then return
- res.raw_json mentity.to_full_json(config.view.mainmodule)
+ res.api_full_json(req, mentity)
end
end
obj["documentation"] = mdoc.html_documentation.write_to_string
obj["location"] = mdoc.location
end
- res.json obj
+ res.api_json(req, obj)
end
end
redef fun get(req, res) do
var mentity = mentity_from_uri(req, res)
if mentity == null then return
- res.json mentity.hierarchy_poset(config.view)[mentity]
+ res.api_json(req, mentity.hierarchy_poset(config.view)[mentity])
end
end
end
var mentities = new JsonArray
for e in lin do mentities.add e
- res.json mentities
+ res.api_json(req, mentities)
end
end
mentities = filter_mentities(req, mentities)
mentities = sort_mentities(req, mentities)
mentities = limit_mentities(req, mentities)
- res.json new JsonArray.from(mentities)
+ res.api_json(req, new JsonArray.from(mentities))
+ end
end
end
json(new APIError(status, message), status)
end
+ # Return `serializable` as a json string
+ #
+ # Uses `req` to define serialization options.
+ fun api_json(req: HttpRequest, serializable: nullable Serializable, status: nullable Int, plain, pretty: nullable Bool) do
+ json(serializable, status, plain, req.bool_arg("pretty"))
+ end
+
+ # Return the full version of `serializable` as a json string
+ #
+ # Uses `req` to define serializable options.
+ fun api_full_json(req: HttpRequest, serializable: nullable MEntity, status: nullable Int, plain, pretty: nullable Bool) do
+ if serializable == null then
+ json(null, status)
+ else
+ raw_json(serializable.serialize_to_full_json(
+ plain or else true, req.bool_arg("pretty") or else false), status)
+ end
+ end
# Write data as JSON and set the right content type header.
fun raw_json(json: nullable String, status: nullable Int) do
header["Content-Type"] = media_types["json"].as(not null)