some code improvements
This commit is contained in:
parent
a3bf259fee
commit
b40b674c5c
@ -21,14 +21,12 @@ std::string API::request(std::string myurl) {
|
|||||||
std::string
|
std::string
|
||||||
API::request(std::string myurl, bool post, Hashmap<std::string, std::string> &map, std::vector<std::string> &headers) {
|
API::request(std::string myurl, bool post, Hashmap<std::string, std::string> &map, std::vector<std::string> &headers) {
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
CURLcode res;
|
|
||||||
|
|
||||||
|
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
|
|
||||||
struct curl_slist *list = nullptr;
|
struct curl_slist *list = nullptr;
|
||||||
for (int j = 0; j < headers.size(); ++j) {
|
for (int j = 0; j < headers.size(); ++j) {
|
||||||
list = curl_slist_append(list, headers.at(j).c_str());
|
list = curl_slist_append(list, headers.at((unsigned long)(j)).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string readString;
|
std::string readString;
|
||||||
@ -73,7 +71,7 @@ API::request(std::string myurl, bool post, Hashmap<std::string, std::string> &ma
|
|||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readString);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readString);
|
||||||
|
|
||||||
res = curl_easy_perform(curl);
|
curl_easy_perform(curl);
|
||||||
|
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ valuetype Hashmap<keytype, valuetype>::getValue(int position) {
|
|||||||
|
|
||||||
template<class keytype, class valuetype>
|
template<class keytype, class valuetype>
|
||||||
int Hashmap<keytype, valuetype>::size() {
|
int Hashmap<keytype, valuetype>::size() {
|
||||||
return keys.size();
|
return (int)(keys.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
#include "api/API.h"
|
#include "api/API.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
@ -24,7 +25,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
std::string ip = api.request("https://api.ipify.org");
|
std::string ip = api.request("https://api.ipify.org");
|
||||||
|
|
||||||
if (ip == "") {
|
if (ip.empty()) {
|
||||||
//no internet connection
|
//no internet connection
|
||||||
logger.logToLogfile("[WARNING] no internet connection");
|
logger.logToLogfile("[WARNING] no internet connection");
|
||||||
std::cout << "[WARNING] no internet connection" << std::endl;
|
std::cout << "[WARNING] no internet connection" << std::endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user