From 5014ad408ace1dda89e0e9852db4a001b605c0a2 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 23 Feb 2018 11:20:55 -0500 Subject: Added ability to get blocklist --- src/client.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/client.cpp') diff --git a/src/client.cpp b/src/client.cpp index ccfd9a3..c2ef06f 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -591,7 +591,39 @@ namespace twitter { { return getFollowers(getUser().getID()); } - + + std::set client::getBlocks() const + { + long long cursor = -1; + std::set result; + + while (cursor != 0) + { + std::stringstream urlstream; + urlstream << "https://api.twitter.com/1.1/blocks/ids.json?cursor="; + urlstream << cursor; + + std::string url = urlstream.str(); + std::string response_data = get(*_oauth_client, url).perform(); + + try + { + nlohmann::json rjs = nlohmann::json::parse(response_data); + + cursor = rjs["next_cursor"].get(); + result.insert(std::begin(rjs["ids"]), std::end(rjs["ids"])); + } catch (const std::invalid_argument& error) + { + std::throw_with_nested(invalid_response(response_data)); + } catch (const std::domain_error& error) + { + std::throw_with_nested(invalid_response(response_data)); + } + } + + return result; + } + void client::follow(user_id toFollow) const { std::stringstream datastrstream; -- cgit 1.4.1