yatbcpp  0.0.1
Yet another Telegram Bot CPP Library
Video_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/Video.h"
8 
9 using namespace std;
10 
11 namespace yatbcpp {
17  template<> Video fromJson(Json::Value Data) {
18  if (!Data.isMember("file_id")) {
19  throw essential_key_missing("Video::file_id is missing");
20  }
21  if (!Data.isMember("width")) {
22  throw essential_key_missing("Video::width is missing");
23  }
24  if (!Data.isMember("height")) {
25  throw essential_key_missing("Video::height is missing");
26  }
27  if (!Data.isMember("duration")) {
28  throw essential_key_missing("Video::duration is missing");
29  }
30 
31  std::string file_id = Data["file_id"].asString();
32  std::int32_t width = Data["width"].asInt();
33  std::int32_t height = Data["height"].asInt();
34  std::int32_t duration = Data["duration"].asInt();
35 
36  Video ret(file_id, width, height, duration);
37 
38  if (Data.isMember("thumb")) {
39  ret.setThumb(fromJson<PhotoSize>(Data["thumb"]));
40  }
41  if (Data.isMember("mime_type")) {
42  ret.setMime_type(Data["mime_type"].asString());
43  }
44  if (Data.isMember("file_size")) {
45  ret.setFile_size(Data["file_size"].asInt());
46  }
47  return ret;
48  }
49 }
void setFile_size(const std::optional< std::int32_t > &file_size)
Definition: Video.cc:40
void setThumb(const std::optional< PhotoSize > &thumb)
Definition: Video.cc:32
Definition: Bot.h:27
void setMime_type(const std::optional< std::string > &mime_type)
Definition: Video.cc:36
Video fromJson(Json::Value Data)