diff --git a/external/3rd/library/webAPI/webAPI.cpp b/external/3rd/library/webAPI/webAPI.cpp index cf745df9..ecf84038 100644 --- a/external/3rd/library/webAPI/webAPI.cpp +++ b/external/3rd/library/webAPI/webAPI.cpp @@ -52,7 +52,7 @@ bool webAPI::setData(std::string &data) bool webAPI::submit(const int &reqType, const int &getPost, const int &respType) { - if (reqType == 0) // json request + if (reqType == DTYPE::JSON) // json request { if (!this->requestData.is_null()) { @@ -92,7 +92,7 @@ bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for struct curl_slist *slist = nullptr; // set the content type - if (mimeType == 0) + if (mimeType == DTYPE::JSON) { slist = curl_slist_append(slist, "Accept: application/json"); slist = curl_slist_append(slist, "Content-Type: application/json"); @@ -111,10 +111,10 @@ bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for switch (getPost) { - case 0: + case HTTP::GET: curl_easy_setopt(curl, CURLOPT_URL, std::string(this->uri + "?" + sRequest).c_str()); break; - case 1: + case HTTP::POST: curl_easy_setopt(curl, CURLOPT_POSTFIELDS, this->sRequest.c_str()); curl_easy_setopt(curl, CURLOPT_URL, this->uri.c_str()); break; diff --git a/external/3rd/library/webAPI/webAPI.h b/external/3rd/library/webAPI/webAPI.h index e9bb0d5a..e371129f 100644 --- a/external/3rd/library/webAPI/webAPI.h +++ b/external/3rd/library/webAPI/webAPI.h @@ -28,6 +28,9 @@ namespace StellaBellum { + enum HTTP { GET = 0, POST = 1 }; + enum DTYPE { JSON = 0, RAW = 1 }; + class webAPI { public: @@ -38,8 +41,8 @@ namespace StellaBellum webAPI(std::string endpoint, std::string userAgent = "StellaBellum webAPI"); ~webAPI(); - // submits the request - respType 0 is json, else raw, get = 0 post = 1 - bool submit(const int &reqType = 0, const int &getPost = 1, const int &respType = 0); + // submits the request + bool submit(const int &reqType = DTYPE::JSON, const int &getPost = HTTP::POST, const int &respType = DTYPE::JSON); // set the endpoint after object creation...or change the target if needed bool setEndpoint(const std::string endpoint); @@ -65,7 +68,7 @@ namespace StellaBellum // get json response slot template T getRespValue(std::string slot) { - if (!this->responseData.is_null() && !slot.empty() && this->responseData.count(slot)) + if (!this->responseData.is_null() && !slot.empty() && !this->responseData[slot].is_null()) { return this->responseData[slot].get(); } @@ -89,8 +92,8 @@ namespace StellaBellum // API endpoint std::string uri; - // fetcher - returns raw response direct from remote - 0 for get, 1 for post, 0 for json mime, 1 for standard - bool fetch(const int &getPost = 1, const int &mimeType = 0); + // fetcher - returns raw response direct from remote + bool fetch(const int &getPost = HTTP::POST, const int &mimeType = DTYPE::JSON); // cURL writeback callback static size_t writeCallback(void *contents, size_t size, size_t nmemb, void *userp);