yatbcpp  0.0.1
Yet another Telegram Bot CPP Library
UserProfilePhotos_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"
9 
10 using namespace std;
11 
12 namespace yatbcpp {
18  template<> UserProfilePhotos fromJson(Json::Value Data) {
19  if (!Data.isMember("total_count")) {
20  throw essential_key_missing("UserProfilePhotos::total_count is missing");
21  }
22 
23  if (!Data.isMember("photos")) {
24  throw essential_key_missing("UserProfilePhotos::photos is missing");
25  }
26 
27  std::int32_t total_count = Data["total_count"].asInt();
28  std::vector<std::vector<PhotoSize>> photos;
29 // photos.reserve(Data["photos"].size());
30  //ok make sure that each photo maximal has 4 photosizes each
31  for (int i = 0; i < Data["photos"].size(); i++) {
32  std::vector<PhotoSize> photo;
33 // photo.reserve(Data["photos"][i].size());
34  for (int j = 0; j < Data["photos"][i].size(); j++) {
35  photo.push_back(fromJson<PhotoSize>(Data["photos"][i]));
36  }
37  if (photo.size() > 4) {
38  throw telegram_api_error(0,"More than 4 photo sizes for a photo have been found, please check telegram api for changes");
39  //Trow something like api error?
40  }
41  photos.push_back(photo);
42  }
43 
44  UserProfilePhotos ret(total_count, photos);
45 
46 
47  return ret;
48  }
49 }
UserProfilePhotos fromJson(Json::Value Data)
Definition: Bot.h:27