2013-07-17 22:55:27 +02:00
|
|
|
local log = require('util.logger')
|
|
|
|
local settings = require('util.settings')
|
2013-08-28 18:33:48 +02:00
|
|
|
local printer = require('util.printer')
|
2013-07-17 22:55:27 +02:00
|
|
|
|
|
|
|
local M = {
|
|
|
|
isApi = true
|
|
|
|
}
|
|
|
|
|
|
|
|
function M._global_GET(request, response)
|
|
|
|
response:setSuccess()
|
|
|
|
for k,v in pairs(request:getAll()) do
|
|
|
|
local r,m = settings.get(k)
|
|
|
|
|
2013-07-29 13:48:56 +02:00
|
|
|
if r ~= nil then response:addData(k, r)
|
2013-07-17 22:55:27 +02:00
|
|
|
else response:addData(k, "could not read key ('" .. m .. "')")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function M._global_POST(request, response)
|
|
|
|
response:setSuccess()
|
|
|
|
for k,v in pairs(request:getAll()) do
|
|
|
|
local r,m = settings.set(k, v)
|
|
|
|
|
|
|
|
if r then response:addData(k, "ok")
|
|
|
|
else response:addData(k, "could not set key ('" .. m .. "')")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-27 00:25:43 +02:00
|
|
|
function M.all_GET(request, response)
|
2013-08-28 14:17:25 +02:00
|
|
|
response:setSuccess()
|
2013-07-27 00:25:43 +02:00
|
|
|
for k,v in pairs(settings.getAll()) do
|
|
|
|
response:addData(k,v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-28 18:33:48 +02:00
|
|
|
function M.supportedprinters_GET(request, response)
|
|
|
|
response:setSuccess()
|
|
|
|
for k,v in pairs(printer.supportedPrinters()) do
|
|
|
|
response:addData(k,v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.supportedbaudrates_GET(request, response)
|
|
|
|
response:setSuccess()
|
|
|
|
for k,v in pairs(printer.supportedBaudRates()) do
|
|
|
|
response:addData(k,v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-17 22:55:27 +02:00
|
|
|
return M
|