yatbcpp  0.0.1
Yet another Telegram Bot CPP Library
Voice_fromJson.cc
Go to the documentation of this file.
1 // From JSON Specialication //
4 #include <jsoncpp/json/json.h>
5 #include "types/telegram_type.h"
7 #include "types/Voice.h"
8 
9 using namespace std;
10 
11 namespace yatbcpp {
17  template<>Voice fromJson(Json::Value Data) {
18  if (!Data.isMember("file_id")) {
19  throw essential_key_missing("Voice::file_id is missing");
20  }
21  if (!Data.isMember("duration")) {
22  throw essential_key_missing("Voice::duration is missing");
23  }
24 
25  std::string file_id = Data["file_id"].asString();
26  std::int32_t duration = Data["duration"].asInt();
27 
28  Voice ret(file_id, duration);
29 
30  if (Data.isMember("mime_type")) {
31  ret.setMime_type(Data["mime_type"].asString());
32  }
33  if (Data.isMember("file_size")) {
34  ret.setFile_size(Data["file_size"].asInt());
35  }
36  return ret;
37  }
38 }
void setMime_type(const std::optional< std::string > &mime_type)
Definition: Voice.cc:31
Voice fromJson(Json::Value Data)
Definition: Bot.h:27
void setFile_size(const std::optional< std::int32_t > &file_size)
Definition: Voice.cc:35