forked from TFNRP/statuspage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.lua
42 lines (35 loc) · 936 Bytes
/
util.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
37
38
39
40
41
42
function APIFetchData(url)
local response = {
timeout = false
}
PerformHttpRequest(url, function (code, result, headers)
response.code = code
if code ~= 200 then
response.timeout = true
else
response.data = result
end
end, 'GET')
while response.data == nil and not response.timeout do
Citizen.Wait(0)
end
if response.timeout then
return false, response
end
local success, object = pcall(function ()
return json.decode(response.data)
end)
if not success or type(object) ~= 'table' then
return false, response, object
end
return object
end
function APIFetchLastIncident(url)
local data, response, object = APIFetchData(url)
if not data then
return data, response, object
end
local incidents = data.incidents
local first = incidents[1]
return first
end