about summary refs log tree commit diff stats
path: root/src/user.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-08-30 20:43:23 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-08-30 20:43:23 -0400
commit8584857578c3a2946a03de98ff3803431143297a (patch)
treee3cb3d9487a7b72a22e5dd50d91011d966a4ee15 /src/user.cpp
parenta9d33aa08df10102539e33c0c6d4334e9e99a470 (diff)
downloadlibtwittercpp-8584857578c3a2946a03de98ff3803431143297a.tar.gz
libtwittercpp-8584857578c3a2946a03de98ff3803431143297a.tar.bz2
libtwittercpp-8584857578c3a2946a03de98ff3803431143297a.zip
Refactored tweet and user classes
The only API-visible change is that these classes are no longer default constructible. Other than that, tweet now uses hatkirby::recptr to wrap its retweeted_status (tweet) and author (user) member objects, removing the need to implement the Rule of Five.
Diffstat (limited to 'src/user.cpp')
-rw-r--r--src/user.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/user.cpp b/src/user.cpp index d2fa592..8109123 100644 --- a/src/user.cpp +++ b/src/user.cpp
@@ -1,24 +1,25 @@
1#include "user.h" 1#include "user.h"
2#include <json.hpp> 2#include <json.hpp>
3#include "codes.h" 3#include "codes.h"
4#include "client.h"
5 4
6namespace twitter { 5namespace twitter {
7 6
8 user::user(std::string data) try 7 user::user(std::string data)
9 : _valid(true)
10 { 8 {
11 auto json = nlohmann::json::parse(data); 9 try
12 _id = json["id"].get<user_id>(); 10 {
13 _screen_name = json["screen_name"].get<std::string>(); 11 auto json = nlohmann::json::parse(data);
14 _name = json["name"].get<std::string>(); 12 _id = json["id"].get<user_id>();
15 _protected = json["protected"].get<bool>(); 13 _screen_name = json["screen_name"].get<std::string>();
16 } catch (const std::invalid_argument& error) 14 _name = json["name"].get<std::string>();
17 { 15 _protected = json["protected"].get<bool>();
18 std::throw_with_nested(malformed_object("user", data)); 16 } catch (const std::invalid_argument& error)
19 } catch (const std::domain_error& error) 17 {
20 { 18 std::throw_with_nested(malformed_object("user", data));
21 std::throw_with_nested(malformed_object("user", data)); 19 } catch (const std::domain_error& error)
20 {
21 std::throw_with_nested(malformed_object("user", data));
22 }
22 } 23 }
23 24
24}; 25}