about summary refs log tree commit diff stats
path: root/src/user.cpp
blob: d2fa592129f1e7897c658c4c9c9e22e2b20b1b79 (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
#include "user.h"
#include <json.hpp>
#include "codes.h"
#include "client.h"

namespace twitter {

  user::user(std::string data) try
    : _valid(true)
  {
    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));
  }

};