mirror of
https://github.com/SWG-Source/src.git
synced 2026-07-13 21:01:08 -04:00
if only i could get past the linker errors, this will work...
This commit is contained in:
+5
-8
@@ -1,12 +1,9 @@
|
||||
|
||||
#include "webAPI.h"
|
||||
|
||||
namespace webAPI
|
||||
{
|
||||
|
||||
// if status == success, returns "success", or slotName's contents if specified...
|
||||
// otherwise returns the "message" if no success
|
||||
std::string simplePost(std::string endpoint, std::string data, std::string slotName)
|
||||
std::string webAPI::simplePost(std::string endpoint, std::string data, std::string slotName)
|
||||
{
|
||||
nlohmann::json response = request(endpoint, data, 1);
|
||||
std::string output;
|
||||
@@ -37,7 +34,7 @@ std::string simplePost(std::string endpoint, std::string data, std::string slotN
|
||||
return output;
|
||||
}
|
||||
|
||||
nlohmann::json request(std::string endpoint, std::string data, int reqType, ...)
|
||||
nlohmann::json webAPI::request(std::string endpoint, std::string data, int reqType)
|
||||
{
|
||||
nlohmann::json response;
|
||||
|
||||
@@ -50,7 +47,7 @@ nlohmann::json request(std::string endpoint, std::string data, int reqType, ...)
|
||||
std::string readBuffer;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, endpoint.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
|
||||
|
||||
if (reqType == 1)
|
||||
@@ -82,9 +79,9 @@ nlohmann::json request(std::string endpoint, std::string data, int reqType, ...)
|
||||
}
|
||||
|
||||
// This is used by curl to grab the response and put it into a var
|
||||
size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
|
||||
size_t webAPI::writeCallback(void *contents, size_t size, size_t nmemb, void *userp)
|
||||
{
|
||||
((std::string*)userp)->append((char*)contents, size * nmemb);
|
||||
return size * nmemb;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -12,7 +12,7 @@ namespace webAPI
|
||||
//nlohmann::json get(char* endpoint, char* data);
|
||||
|
||||
nlohmann::json request(std::string endpoint, std::string data, int reqType); // 1 for post, 0 for get
|
||||
size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp);
|
||||
size_t writeCallback(void *contents, size_t size, size_t nmemb, void *userp);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user