2013-07-08 13:34:27 +02:00
|
|
|
local l = require("logger")
|
|
|
|
local ResponseClass = require("rest.response")
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
M.isApi = true
|
|
|
|
|
|
|
|
function M._global(d)
|
2013-07-08 16:53:45 +02:00
|
|
|
local r = ResponseClass.new(d)
|
|
|
|
local ba = d:getBlankArgument()
|
|
|
|
|
|
|
|
r:setSuccess("REST test API - default function called with blank argument: '" .. (ba or "<nil>") .. "'")
|
|
|
|
if ba ~= nil then r:addData("blank_argument", ba) end
|
|
|
|
|
2013-07-08 13:34:27 +02:00
|
|
|
return r
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.success(d)
|
2013-07-08 16:53:45 +02:00
|
|
|
local r = ResponseClass.new(d)
|
2013-07-09 01:49:56 +02:00
|
|
|
r:setSuccess("this successful response has been generated on purpose")
|
|
|
|
r:addData("url", "http://xkcd.com/349/")
|
2013-07-08 13:34:27 +02:00
|
|
|
return r
|
|
|
|
end
|
|
|
|
|
2013-07-08 19:02:20 +02:00
|
|
|
function M.fail(d)
|
|
|
|
local r = ResponseClass.new(d)
|
2013-07-09 01:49:56 +02:00
|
|
|
r:setFail("this failure has been generated on purpose")
|
|
|
|
r:addData("url", "http://xkcd.com/336/")
|
2013-07-08 19:02:20 +02:00
|
|
|
return r
|
|
|
|
end
|
|
|
|
|
2013-07-08 13:34:27 +02:00
|
|
|
function M.error(d)
|
2013-07-08 16:53:45 +02:00
|
|
|
local r = ResponseClass.new(d)
|
2013-07-08 13:34:27 +02:00
|
|
|
r:setError("this error has been generated on purpose")
|
2013-07-09 01:49:56 +02:00
|
|
|
r:addData("url", "http://xkcd.com/1024/")
|
2013-07-08 13:34:27 +02:00
|
|
|
return r
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.echo(d)
|
2013-07-08 16:53:45 +02:00
|
|
|
local r = ResponseClass.new(d)
|
2013-07-08 13:34:27 +02:00
|
|
|
r:setSuccess("request echo")
|
|
|
|
r:addData("request_data", d)
|
|
|
|
return r
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|