docs/refactor: add AI disclosure and clean up code style
This commit is contained in:
@@ -12,9 +12,6 @@ local JASPER_URL = "https://jasper.4sigma.it"
|
||||
--- @return string|nil error message
|
||||
local function curl(args)
|
||||
-- Append -w to get the HTTP status on a separate last line
|
||||
local full_args = vim.list_extend(vim.list_slice(args, 1), { "-s", "-w", "\n%{http_code}" })
|
||||
-- args already contains the URL; rebuild properly:
|
||||
-- Actually we receive the full arg list already. Add -w trick.
|
||||
table.insert(args, "-w")
|
||||
table.insert(args, "\n%{http_code}")
|
||||
|
||||
@@ -41,7 +38,8 @@ end
|
||||
local function get(path, token)
|
||||
return curl({
|
||||
"curl",
|
||||
"-H", "Authorization: Token " .. token,
|
||||
"-H",
|
||||
"Authorization: Token " .. token,
|
||||
JASPER_URL .. path,
|
||||
})
|
||||
end
|
||||
@@ -52,8 +50,11 @@ end
|
||||
--- @return table|nil, number, string|nil
|
||||
local function post(path, token, form)
|
||||
local args = {
|
||||
"curl", "-X", "POST",
|
||||
"-H", "Authorization: Token " .. token,
|
||||
"curl",
|
||||
"-X",
|
||||
"POST",
|
||||
"-H",
|
||||
"Authorization: Token " .. token,
|
||||
}
|
||||
if form then
|
||||
for k, v in pairs(form) do
|
||||
@@ -84,6 +85,9 @@ function M.get_timers(token)
|
||||
if status ~= 200 then
|
||||
return nil, "unexpected HTTP status " .. status
|
||||
end
|
||||
if not data then
|
||||
return nil, "empty response"
|
||||
end
|
||||
local timers_dict = data.data and data.data.timers
|
||||
if type(timers_dict) ~= "table" then
|
||||
return nil, "unexpected response shape"
|
||||
@@ -108,6 +112,9 @@ function M.start_timer(token, timer_id)
|
||||
if status ~= 200 then
|
||||
return false, "HTTP " .. status
|
||||
end
|
||||
if not data then
|
||||
return true, nil
|
||||
end
|
||||
if data.error ~= nil and data.error ~= vim.NIL then
|
||||
return false, tostring(data.error)
|
||||
end
|
||||
@@ -127,6 +134,9 @@ function M.stop_timer(token, timer_id)
|
||||
if status ~= 200 then
|
||||
return false, "HTTP " .. status
|
||||
end
|
||||
if not data then
|
||||
return true, nil
|
||||
end
|
||||
if data.error ~= nil and data.error ~= vim.NIL then
|
||||
return false, tostring(data.error)
|
||||
end
|
||||
@@ -140,17 +150,16 @@ end
|
||||
--- @return boolean ok
|
||||
--- @return string|nil error
|
||||
function M.create_timer(token, timer_id, attivita_id)
|
||||
local data, status, err = post(
|
||||
"/api/v1/timer/" .. timer_id .. "/attivita/",
|
||||
token,
|
||||
{ attivita_id = attivita_id }
|
||||
)
|
||||
local data, status, err = post("/api/v1/timer/" .. timer_id .. "/attivita/", token, { attivita_id = attivita_id })
|
||||
if err then
|
||||
return false, err
|
||||
end
|
||||
if status ~= 200 then
|
||||
return false, "HTTP " .. status
|
||||
end
|
||||
if not data then
|
||||
return true, nil
|
||||
end
|
||||
if data.error ~= nil and data.error ~= vim.NIL then
|
||||
return false, tostring(data.error)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user