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 +++++++++++++++++++++++++++++++++- src/client.h | 4 +++- 2 files changed, 36 insertions(+), 2 deletions(-) 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; diff --git a/src/client.h b/src/client.h index c920f82..9282321 100644 --- a/src/client.h +++ b/src/client.h @@ -38,7 +38,9 @@ namespace twitter { std::set getFollowers(user_id id) const; std::set getFollowers(const user& u) const; std::set getFollowers() const; - + + std::set getBlocks() const; + void follow(user_id toFollow) const; void follow(const user& toFollow) const; -- cgit 1.4.1