about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp37
-rw-r--r--src/client.h3
2 files changed, 40 insertions, 0 deletions
diff --git a/src/client.cpp b/src/client.cpp index 820db80..b7eb9d1 100644 --- a/src/client.cpp +++ b/src/client.cpp
@@ -56,6 +56,11 @@ namespace twitter {
56 .perform()); 56 .perform());
57 } 57 }
58 58
59 tweet client::replyToTweet(std::string msg, const tweet& in_response_to, std::list<long> media_ids) const
60 {
61 return replyToTweet(msg, in_response_to.getID(), media_ids);
62 }
63
59 long client::uploadMedia(std::string media_type, const char* data, long data_length) const try 64 long client::uploadMedia(std::string media_type, const char* data, long data_length) const try
60 { 65 {
61 curl::curl_form form; 66 curl::curl_form form;
@@ -265,6 +270,38 @@ namespace twitter {
265 return getFollowers(getUser().getID()); 270 return getFollowers(getUser().getID());
266 } 271 }
267 272
273 std::set<user_id> client::getBlocks() const
274 {
275 long long cursor = -1;
276 std::set<user_id> result;
277
278 while (cursor != 0)
279 {
280 std::stringstream urlstream;
281 urlstream << "https://api.twitter.com/1.1/blocks/ids.json?cursor=";
282 urlstream << cursor;
283
284 std::string url = urlstream.str();
285 std::string response_data = get(auth_, url).perform();
286
287 try
288 {
289 nlohmann::json rjs = nlohmann::json::parse(response_data);
290
291 cursor = rjs["next_cursor"].get<long long>();
292 result.insert(std::begin(rjs["ids"]), std::end(rjs["ids"]));
293 } catch (const std::invalid_argument& error)
294 {
295 std::throw_with_nested(invalid_response(response_data));
296 } catch (const std::domain_error& error)
297 {
298 std::throw_with_nested(invalid_response(response_data));
299 }
300 }
301
302 return result;
303 }
304
268 void client::follow(user_id toFollow) const 305 void client::follow(user_id toFollow) const
269 { 306 {
270 std::stringstream datastrstream; 307 std::stringstream datastrstream;
diff --git a/src/client.h b/src/client.h index c0a63eb..5e2ab1c 100644 --- a/src/client.h +++ b/src/client.h
@@ -23,6 +23,7 @@ namespace twitter {
23 long uploadMedia(std::string media_type, const char* data, long data_length) const; 23 long uploadMedia(std::string media_type, const char* data, long data_length) const;
24 24
25 tweet replyToTweet(std::string msg, tweet_id in_response_to, std::list<long> media_ids = {}) const; 25 tweet replyToTweet(std::string msg, tweet_id in_response_to, std::list<long> media_ids = {}) const;
26 tweet replyToTweet(std::string msg, const tweet& in_response_to, std::list<long> media_ids = {}) const;
26 27
27 std::set<user_id> getFriends(user_id id) const; 28 std::set<user_id> getFriends(user_id id) const;
28 std::set<user_id> getFriends(const user& u) const; 29 std::set<user_id> getFriends(const user& u) const;
@@ -32,6 +33,8 @@ namespace twitter {
32 std::set<user_id> getFollowers(const user& u) const; 33 std::set<user_id> getFollowers(const user& u) const;
33 std::set<user_id> getFollowers() const; 34 std::set<user_id> getFollowers() const;
34 35
36 std::set<user_id> getBlocks() const;
37
35 void follow(user_id toFollow) const; 38 void follow(user_id toFollow) const;
36 void follow(const user& toFollow) const; 39 void follow(const user& toFollow) const;
37 40