mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-16 04:17:34 +00:00
add http method
This commit is contained in:
parent
d4ca8d4933
commit
a61ca353cc
|
@ -17,17 +17,19 @@ end
|
||||||
//
|
//
|
||||||
|
|
||||||
local function sendHTTP(params)
|
local function sendHTTP(params)
|
||||||
|
gmInte.log("HTTP Request: " .. params.method .. " " .. params.endpoint, true)
|
||||||
|
gmInte.log("HTTP Body: " .. (params.body or "No body"), true)
|
||||||
HTTP({
|
HTTP({
|
||||||
url = "https://api.gmod-integration.com" .. params.endpoint,
|
url = "https://api.gmod-integration.com" .. params.endpoint,
|
||||||
method = params.method,
|
method = params.method,
|
||||||
headers = {
|
headers = {
|
||||||
["Content-Type"] = "application/json",
|
["Content-Type"] = "application/json",
|
||||||
["Content-Length"] = tostring(#params.body),
|
["Content-Length"] = params.body and string.len(params.body) or 0,
|
||||||
["id"] = gmInte.config.id,
|
["id"] = gmInte.config.id,
|
||||||
["token"] = gmInte.config.token,
|
["token"] = gmInte.config.token,
|
||||||
["version"] = gmInte.version
|
["version"] = gmInte.version
|
||||||
},
|
},
|
||||||
body = params.body,
|
body = params.body && params.body or "",
|
||||||
type = "application/json",
|
type = "application/json",
|
||||||
success = function(code, body, headers)
|
success = function(code, body, headers)
|
||||||
if (gmInte.isCodeValid(code)) then
|
if (gmInte.isCodeValid(code)) then
|
||||||
|
@ -42,8 +44,7 @@ local function sendHTTP(params)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function gmInte.fetch(endpoint, onSuccess)
|
function gmInte.get(endpoint, onSuccess)
|
||||||
gmInte.log("Fetching " .. endpoint, true)
|
|
||||||
sendHTTP({
|
sendHTTP({
|
||||||
endpoint = endpoint,
|
endpoint = endpoint,
|
||||||
method = "GET",
|
method = "GET",
|
||||||
|
@ -52,7 +53,6 @@ function gmInte.fetch(endpoint, onSuccess)
|
||||||
end
|
end
|
||||||
|
|
||||||
function gmInte.post(endpoint, data, onSuccess)
|
function gmInte.post(endpoint, data, onSuccess)
|
||||||
gmInte.log("Posting " .. endpoint, true)
|
|
||||||
sendHTTP({
|
sendHTTP({
|
||||||
endpoint = endpoint,
|
endpoint = endpoint,
|
||||||
method = "POST",
|
method = "POST",
|
||||||
|
@ -61,6 +61,23 @@ function gmInte.post(endpoint, data, onSuccess)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function gmInte.put(endpoint, data, onSuccess)
|
||||||
|
sendHTTP({
|
||||||
|
endpoint = endpoint,
|
||||||
|
method = "PUT",
|
||||||
|
body = util.TableToJSON(data),
|
||||||
|
success = onSuccess
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
function gmInte.delete(endpoint, onSuccess)
|
||||||
|
sendHTTP({
|
||||||
|
endpoint = endpoint,
|
||||||
|
method = "DELETE",
|
||||||
|
success = onSuccess
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Fetch Example
|
// Fetch Example
|
||||||
gmInte.fetch(
|
gmInte.fetch(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user