From a61ca353cc2641e77f09a39f9f7804e871df63a0 Mon Sep 17 00:00:00 2001
From: Linventif <linventif@gmail.com>
Date: Sat, 23 Sep 2023 14:43:59 +0200
Subject: [PATCH] add http method

---
 lua/gmod_integration/shared/sh_http.lua | 27 ++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua
index 63a63be..0839291 100644
--- a/lua/gmod_integration/shared/sh_http.lua
+++ b/lua/gmod_integration/shared/sh_http.lua
@@ -17,17 +17,19 @@ end
 //
 
 local function sendHTTP(params)
+    gmInte.log("HTTP Request: " .. params.method .. " " .. params.endpoint, true)
+    gmInte.log("HTTP Body: " .. (params.body or "No body"), true)
     HTTP({
         url = "https://api.gmod-integration.com" .. params.endpoint,
         method = params.method,
         headers = {
             ["Content-Type"] = "application/json",
-            ["Content-Length"] = tostring(#params.body),
+            ["Content-Length"] = params.body and string.len(params.body) or 0,
             ["id"] = gmInte.config.id,
             ["token"] = gmInte.config.token,
             ["version"] = gmInte.version
         },
-        body = params.body,
+        body = params.body && params.body or "",
         type = "application/json",
         success = function(code, body, headers)
             if (gmInte.isCodeValid(code)) then
@@ -42,8 +44,7 @@ local function sendHTTP(params)
     })
 end
 
-function gmInte.fetch(endpoint, onSuccess)
-    gmInte.log("Fetching " .. endpoint, true)
+function gmInte.get(endpoint, onSuccess)
     sendHTTP({
         endpoint = endpoint,
         method = "GET",
@@ -52,7 +53,6 @@ function gmInte.fetch(endpoint, onSuccess)
 end
 
 function gmInte.post(endpoint, data, onSuccess)
-    gmInte.log("Posting " .. endpoint, true)
     sendHTTP({
         endpoint = endpoint,
         method = "POST",
@@ -61,6 +61,23 @@ function gmInte.post(endpoint, data, onSuccess)
     })
 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
 gmInte.fetch(