clean webapi

This commit is contained in:
DarthArgus
2016-12-26 21:54:21 -06:00
parent c6c445b09b
commit 6eafb0d7f8
2 changed files with 14 additions and 7 deletions
+9 -4
View File
@@ -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>();
}