mirror of
https://github.com/SWG-Source/src.git
synced 2026-08-03 03:16:01 -04:00
clean webapi
This commit is contained in:
+5
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Version: 1.3
|
||||
* Version: 1.5
|
||||
*
|
||||
* This code is just a simple wrapper around nlohmann's wonderful json lib
|
||||
* (https://github.com/nlohmann/json) and libcurl. While originally included directly,
|
||||
@@ -56,7 +56,8 @@ std::string webAPI::getString(const std::string &slot) {
|
||||
}
|
||||
|
||||
std::vector<std::string> webAPI::getStringVector(const std::string &slot) {
|
||||
if (!this->responseData.empty() && !slot.empty() && responseData.count(slot) && !this->responseData[slot].is_null()) {
|
||||
if (!this->responseData.empty() && !slot.empty() && responseData.count(slot) &&
|
||||
!this->responseData[slot].is_null()) {
|
||||
return this->responseData[slot].get<std::vector<std::string>>();
|
||||
}
|
||||
|
||||
@@ -107,7 +108,8 @@ bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for
|
||||
slist = curl_slist_append(slist, "charsets: utf-8");
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeCallback); // place the data into readBuffer using writeCallback
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
|
||||
writeCallback); // place the data into readBuffer using writeCallback
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); // specify readBuffer as the container for data
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
|
||||
|
||||
|
||||
Vendored
+9
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Version: 1.4
|
||||
* Version: 1.5
|
||||
*
|
||||
* This code is just a simple wrapper around nlohmann's wonderful json lib
|
||||
* (https://github.com/nlohmann/json) and libcurl. While originally included directly,
|
||||
@@ -23,7 +23,9 @@
|
||||
#ifdef WIN32
|
||||
#include <curl.h>
|
||||
#else
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#endif
|
||||
|
||||
namespace StellaBellum {
|
||||
@@ -45,7 +47,8 @@ namespace StellaBellum {
|
||||
~webAPI();
|
||||
|
||||
// submits the request
|
||||
bool submit(const int &reqType = DTYPE::JSON, const int &getPost = HTTP::POST, const int &respType = DTYPE::JSON);
|
||||
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);
|
||||
@@ -63,7 +66,8 @@ namespace StellaBellum {
|
||||
std::vector<std::string> getStringVector(const std::string &slot);
|
||||
|
||||
// set json key and value for request
|
||||
template<typename T> bool addJsonData(const std::string &key, const T &value) {
|
||||
template<typename T>
|
||||
bool addJsonData(const std::string &key, const T &value) {
|
||||
if (!key.empty() &&
|
||||
responseData.count(key) == 0) // only alow one of a given key for now, unless we support nesting later
|
||||
{
|
||||
@@ -75,7 +79,8 @@ namespace StellaBellum {
|
||||
}
|
||||
|
||||
// get json response slot
|
||||
template<typename T> T getNullableValue(const std::string &slot) {
|
||||
template<typename T>
|
||||
T getNullableValue(const std::string &slot) {
|
||||
if (!this->responseData.empty() && !slot.empty() && responseData.count(slot)) {
|
||||
return this->responseData[slot].get<T>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user