· 6 years ago · Dec 31, 2019, 01:44 AM
1local Http = game:GetService('HttpService')
2
3
4-- USE THE "c!api" command to get the credentials!
5
6local Settings = {
7 Token = "324129048712304981723409",
8 Clan = "f9071d07-5e15-460e-b2bc-acf16e4cdead"
9}
10
11function AuthKey()
12 return Settings.Token
13end
14
15local URL = {
16 Domain = "https://clanlabs.co/api/",
17 --Domain = "http://localhost:5000/api/",
18 users = {
19 ['GET'] = {
20 ['GetProfile'] = function(id)
21 local url = "GetProfile/"
22 local headers = {
23 ['id'] = id,
24 ['auth'] = Settings.Token,
25 ['clan'] = Settings.Clan
26 }
27 return url, headers
28 end
29 },
30 ['POST'] = {
31 ['ChangeExperience'] = function(data)
32 local url = "ChangeExperience/"
33 local headers = {
34 ["id"] = data.Id,
35 ['auth'] = Settings.Token,
36 ['clan'] = Settings.Clan,
37 ['experience'] = data.XP
38 }
39 return url, headers
40 end,
41 }
42 }
43}
44function Decode(json)
45 local jsonTab = {} pcall(function ()
46 jsonTab = Http:JSONDecode(json)
47 end) return jsonTab
48end
49
50function Encode(data)
51 local jsonString = data pcall(function ()
52 jsonString = Http:JSONEncode(data)
53 end) return jsonString
54end
55
56function ConvertToString(data)
57 if data ~= nil then
58 for key, value in pairs(data) do
59 data[key] = tostring(value)
60 end
61 end
62 return data
63end
64
65Form = function(action, master, func, value)
66 local path = URL[master][action][func]
67 local headers = nil
68 if typeof(path) == 'function' then
69 path, headers = path(value)
70 end
71 local url = URL.Domain..master..'/'..path
72 print('URL:', url, 'was built.')
73 return url, headers
74end
75
76local API = {}
77
78function API:Execute(action, master, func, value)
79 --print('API ACCESS:', action)
80 if action == 'GET' then
81 local url, headers = Form(action, master, func, value)
82 headers = ConvertToString(headers)
83 local json = Http:GetAsync(url, false, headers)
84 local deconstruct = Decode(json)
85 if deconstruct then
86 return deconstruct
87 end
88 elseif action == 'POST' then
89 local url, headers = Form(action, master, func, value)
90 headers = ConvertToString(headers)
91 local json = Http:PostAsync(url, "", Enum.HttpContentType.TextPlain, false, headers)
92 local deconstruct = Decode(json)
93 if deconstruct then
94 return deconstruct
95 end
96 end
97end
98
99function API:GetProfile(id)
100 return API:Execute('GET', 'users', 'GetProfile', id)
101end
102
103function API:ChangeExperience(id, xp)
104 return API:Execute('POST', 'users', 'ChangeExperience', {Id= id, XP= xp})
105end
106
107--API:Execute('POST', 'users', 'AddXP', {Id = 114483301, XP = 10, Reason = "Got good!"})
108
109
110
111
112return API