about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-08-06 16:06:12 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-08-06 16:06:12 -0400
commitbc893794c5e7ec1a968c00a8538241278e8c8d34 (patch)
tree0dbf0f46880c7c0ae093707ef7ec8a7b04ebd016 /src
parentb7bb942cadfe3d657895af1557b78acc2559947e (diff)
downloadlibtwittercpp-bc893794c5e7ec1a968c00a8538241278e8c8d34.tar.gz
libtwittercpp-bc893794c5e7ec1a968c00a8538241278e8c8d34.tar.bz2
libtwittercpp-bc893794c5e7ec1a968c00a8538241278e8c8d34.zip
User objects now contain whether the user is protected
Diffstat (limited to 'src')
-rw-r--r--src/user.cpp3
-rw-r--r--src/user.h38
2 files changed, 25 insertions, 16 deletions
diff --git a/src/user.cpp b/src/user.cpp index f9b02a1..d2fa592 100644 --- a/src/user.cpp +++ b/src/user.cpp
@@ -4,7 +4,7 @@
4#include "client.h" 4#include "client.h"
5 5
6namespace twitter { 6namespace twitter {
7 7
8 user::user(std::string data) try 8 user::user(std::string data) try
9 : _valid(true) 9 : _valid(true)
10 { 10 {
@@ -12,6 +12,7 @@ namespace twitter {
12 _id = json["id"].get<user_id>(); 12 _id = json["id"].get<user_id>();
13 _screen_name = json["screen_name"].get<std::string>(); 13 _screen_name = json["screen_name"].get<std::string>();
14 _name = json["name"].get<std::string>(); 14 _name = json["name"].get<std::string>();
15 _protected = json["protected"].get<bool>();
15 } catch (const std::invalid_argument& error) 16 } catch (const std::invalid_argument& error)
16 { 17 {
17 std::throw_with_nested(malformed_object("user", data)); 18 std::throw_with_nested(malformed_object("user", data));
diff --git a/src/user.h b/src/user.h index ef7d72e..acd62d0 100644 --- a/src/user.h +++ b/src/user.h
@@ -6,56 +6,64 @@
6#include <cassert> 6#include <cassert>
7 7
8namespace twitter { 8namespace twitter {
9 9
10 class client; 10 class client;
11 11
12 typedef unsigned long long user_id; 12 typedef unsigned long long user_id;
13 13
14 class user { 14 class user {
15 public: 15 public:
16 16
17 user() {} 17 user() {}
18 user(std::string data); 18 user(std::string data);
19 19
20 user_id getID() const 20 user_id getID() const
21 { 21 {
22 assert(_valid); 22 assert(_valid);
23 23
24 return _id; 24 return _id;
25 } 25 }
26 26
27 std::string getScreenName() const 27 std::string getScreenName() const
28 { 28 {
29 assert(_valid); 29 assert(_valid);
30 30
31 return _screen_name; 31 return _screen_name;
32 } 32 }
33 33
34 std::string getName() const 34 std::string getName() const
35 { 35 {
36 assert(_valid); 36 assert(_valid);
37 37
38 return _name; 38 return _name;
39 } 39 }
40 40
41 bool isProtected() const
42 {
43 assert(_valid);
44
45 return _protected;
46 }
47
41 bool operator==(const user& other) const 48 bool operator==(const user& other) const
42 { 49 {
43 return _id == other._id; 50 return _id == other._id;
44 } 51 }
45 52
46 bool operator!=(const user& other) const 53 bool operator!=(const user& other) const
47 { 54 {
48 return _id != other._id; 55 return _id != other._id;
49 } 56 }
50 57
51 private: 58 private:
52 59
53 bool _valid = false; 60 bool _valid = false;
54 user_id _id; 61 user_id _id;
55 std::string _screen_name; 62 std::string _screen_name;
56 std::string _name; 63 std::string _name;
64 bool _protected = false;
57 }; 65 };
58 66
59}; 67};
60 68
61#endif /* end of include guard: USER_H_BF3AB38C */ 69#endif /* end of include guard: USER_H_BF3AB38C */