about summary refs log tree commit diff stats
path: root/src/user.cpp
blob: 81091237520fc4c3d6dc1d7d5c62721668ec8fb9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "user.h"
#include <json.hpp>
#include "codes.h"

namespace twitter {

  user::user(std::string data)
  {
    try
    {
      auto json = nlohmann::json::parse(data);
      _id = json["id"].get<user_id>();
      _screen_name = json["screen_name"].get<std::string>();
      _name = json["name"].get<std::string>();
      _protected = json["protected"].get<bool>();
    } catch (const std::invalid_argument& error)
    {
      std::throw_with_nested(malformed_object("user", data));
    } catch (const std::domain_error& error)
    {
      std::throw_with_nested(malformed_object("user", data));
    }
  }

}