added seperate class for ip request and dynu request

This commit is contained in:
2019-06-18 11:23:24 +02:00
parent 0e8783d354
commit 07ce161155
6 changed files with 93 additions and 24 deletions

32
src/api/DynuAPI.cpp Normal file
View File

@ -0,0 +1,32 @@
//
// Created by lukas on 18.06.19.
//
#include "DynuAPI.h"
int DynuAPI::refreshIp(std:: string ip) {
static std::string dynuapikey = "88vNpMfDhMM2YYDNfWR1DNYfRX9W6fYg";
static std::string domainid = "8506047"; //id of the dynu domain
static std::string domainname = "luki.dynu.net";
Hashmap<std::string, std::string> args;
args.add("name", domainname);
args.add("ipv4Address", ip);
std::vector<std::string> headers;
headers.push_back("accept: application/json");
headers.push_back("User-Agent: Mozilla/5.0 (compatible; Rigor/1.0.0; http://rigor.com)");
headers.push_back("API-Key: " + dynuapikey);
std::string dynurepl = request("https://api.dynu.com/v2/dns/" + domainid, true, args, headers);
std::cout << "[DEBUG] api reply:: " << dynurepl << std::endl;
if (dynurepl != "{\"statusCode\":200}") {
return -1;
} else {
return 1;
}
}

20
src/api/DynuAPI.h Normal file
View File

@ -0,0 +1,20 @@
//
// Created by lukas on 18.06.19.
//
#ifndef IPREFRESHER_DYNUAPI_H
#define IPREFRESHER_DYNUAPI_H
#include "API.h"
class DynuAPI : API{
public:
int refreshIp(std::string ip);
private:
};
#endif //IPREFRESHER_DYNUAPI_H

9
src/api/IPAPI.cpp Normal file
View File

@ -0,0 +1,9 @@
//
// Created by lukas on 18.06.19.
//
#include "IPAPI.h"
std::string IPAPI::getGlobalIp() {
return request("https://api.ipify.org");
}

19
src/api/IPAPI.h Normal file
View File

@ -0,0 +1,19 @@
//
// Created by lukas on 18.06.19.
//
#ifndef IPREFRESHER_IPAPI_H
#define IPREFRESHER_IPAPI_H
#include <string>
#include "API.h"
class IPAPI : API{
public:
std::string getGlobalIp();
};
#endif //IPREFRESHER_IPAPI_H