about summary refs log tree commit diff stats
path: root/src/user.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-08-20 13:56:23 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-08-20 13:56:23 -0400
commit69fc8d805396b889b5e8c1c88e8129d93db77d29 (patch)
tree6b807bd9332c65b65066e247d4d00fd5e4118d2e /src/user.cpp
parent442f1ee071152be04c4184473ddfee5040795b76 (diff)
downloadlibtwittercpp-69fc8d805396b889b5e8c1c88e8129d93db77d29.tar.gz
libtwittercpp-69fc8d805396b889b5e8c1c88e8129d93db77d29.tar.bz2
libtwittercpp-69fc8d805396b889b5e8c1c88e8129d93db77d29.zip
Updated API to use exceptions and make tweet/user objects more helpful
Diffstat (limited to 'src/user.cpp')
-rw-r--r--src/user.cpp48
1 files changed, 20 insertions, 28 deletions
diff --git a/src/user.cpp b/src/user.cpp index 0fa1e39..0b6e93a 100644 --- a/src/user.cpp +++ b/src/user.cpp
@@ -1,51 +1,43 @@
1#include "user.h" 1#include "user.h"
2#include <json.hpp> 2#include <json.hpp>
3 3#include "codes.h"
4using nlohmann::json; 4#include "client.h"
5 5
6namespace twitter { 6namespace twitter {
7 7
8 user::user() : _valid(false) 8 user::user(const client& tclient, std::string data) try
9 { 9 : _client(tclient)
10
11 }
12
13 user::user(std::string data) : _valid(true)
14 { 10 {
15 auto _data = json::parse(data); 11 auto json = nlohmann::json::parse(data);
16 _id = _data.at("id"); 12 _id = json["id"].get<user_id>();
17 _screen_name = _data.at("screen_name"); 13 _screen_name = json["screen_name"].get<std::string>();
18 _name = _data.at("name"); 14 _name = json["name"].get<std::string>();
19 } 15 } catch (const std::invalid_argument& error)
20
21 user_id user::getID() const
22 { 16 {
23 return _id; 17 std::throw_with_nested(malformed_object("user", data));
24 } 18 } catch (const std::domain_error& error)
25
26 std::string user::getScreenName() const
27 { 19 {
28 return _screen_name; 20 std::throw_with_nested(malformed_object("user", data));
29 } 21 }
30 22
31 std::string user::getName() const 23 std::set<user_id> user::getFriends() const
32 { 24 {
33 return _name; 25 return _client.getFriends(_id);
34 } 26 }
35 27
36 user::operator bool() const 28 std::set<user_id> user::getFollowers() const
37 { 29 {
38 return _valid; 30 return _client.getFollowers(_id);
39 } 31 }
40 32
41 bool user::operator==(const user& other) const 33 void user::follow() const
42 { 34 {
43 return _id == other._id; 35 _client.follow(_id);
44 } 36 }
45 37
46 bool user::operator!=(const user& other) const 38 void user::unfollow() const
47 { 39 {
48 return _id != other._id; 40 _client.unfollow(_id);
49 } 41 }
50 42
51}; 43};