-
Notifications
You must be signed in to change notification settings - Fork 1
/
Globals.lua
36 lines (33 loc) · 914 Bytes
/
Globals.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
--[[
Global variables handler
@author ikubicki
]]
class 'Globals'
function Globals:get(name, alternative)
local response = api.get('/globalVariables/' .. name)
if response then
local char = string.sub(response.value, 1, 1)
if char == '{' or char == '"' then
return json.decode(response.value)
end
return response.value
end
return alternative
end
function Globals:set(name, value)
local response = api.put('/globalVariables/' .. name, {
name = name,
value = json.encode(value)
})
if not response then
response = api.post('/globalVariables', {
name = name,
value = json.encode(value)
})
end
if response ~= nil then
if response.type == 'ERROR' then
QuickApp:error('GLOBALS ERROR[' .. response.reason .. ']:', response.message)
end
end
end