1 #ifndef YATBCPP_TELEGRAM_SIMPLEMETHODJSON_H 2 #define YATBCPP_TELEGRAM_SIMPLEMETHODJSON_H 5 #include <jsoncpp/json/json.h> 6 #include "../exceptions/telegram_api_error.h" 7 #include "../exceptions/curl_error.h" 8 #include "../types/telegram_type.h" 9 #include "../exceptions/essential_key_missing.h" 10 #include "../bot/Token.h" 25 static size_t WriteCallback(
void *contents,
size_t size,
size_t nmemb,
void *stringptr){
27 ((
string*)stringptr)->append((
char*)contents, size * nmemb);
39 string curl_payload( method_body.
toJson().toStyledString() );
44 struct curl_slist * curl_header_list =NULL;
45 curl_header_list = curl_slist_append( curl_header_list ,
"Content-Type: application/json" );
46 CURL* curl = curl_easy_init();
47 curl_easy_setopt(curl,CURLOPT_URL,api_url.c_str());
48 curl_easy_setopt(curl,CURLOPT_POSTFIELDS,curl_payload.c_str());
49 curl_easy_setopt(curl,CURLOPT_HTTPHEADER,curl_header_list);
51 curl_easy_setopt(curl,CURLOPT_WRITEDATA,&readBuffer);
53 CURLcode res = curl_easy_perform(curl);
54 reader.parse(readBuffer,Response);
58 if(Response.isMember(
"ok")){
59 curl_slist_free_all(curl_header_list);
60 curl_easy_cleanup(curl);
61 return Response[
"ok"].asBool();
64 curl_easy_cleanup(curl);
65 curl_slist_free_all(curl_header_list);
66 throw telegram_api_error(Response[
"error_code"].asInt(),Response[
"description"].asString());
90 #endif //YATBCPP_TELEGRAM_SIMPLEMETHODJSON_H
virtual Json::Value toJson()
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *stringptr)
static bool perform_simplerequestJSON(Token T, telegram_simplemethodJSON &method_body)
const std::string & getFunctionname() const
const std::string getToken() const
telegram_simplemethodJSON(std::string functionname)