-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathapiclient.lua
52 lines (42 loc) · 1.42 KB
/
apiclient.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
43
44
45
46
47
48
49
50
51
52
print( "// API Client 0.1 //" )
TebexApiClient = {}
TebexApiClient.__index = TebexApiClient
function TebexApiClient:init(baseUrl, secret, timeout)
local apiclient = {}
setmetatable(apiclient,TebexApiClient)
apiclient.baseUrl = baseUrl
apiclient.secret = secret;
if (timeout == nil) then
timeout = 5000
end
apiclient.timeout = timeout
return apiclient
end
function TebexApiClient:get(endpoint, success, failure)
PerformHttpRequest(self.baseUrl .. endpoint, function(code, body, headers)
if (body == nil) then
Tebex.err("There was a problem sending this request. Please try again " .. code)
return
end
tBody = json.decode(body)
if (code == 200 or code == 204) then
success(tBody)
return
end
failure(tBody)
end, 'GET', '', { ['X-Buycraft-Secret'] = apiclient.secret })
end
function TebexApiClient:delete(endpoint, success, failure)
PerformHttpRequest(self.baseUrl .. endpoint, function(code, body, headers)
if (body == nil) then
Tebex.err("There was a problem sending this request. Please try again")
return
end
tBody = json.decode(body)
if (code == 200 or code == 204) then
success(tBody)
return
end
failure(tBody)
end, 'DELETE', '', { ['X-Buycraft-Secret'] = apiclient.secret })
end