diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-08-05 13:21:23 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-08-05 13:21:23 -0400 |
| commit | 204181c5654cee745b6b1ba98675609e784f0ee1 (patch) | |
| tree | 6a09a6e0956fa91bfec0ac5f1ef1918773d1cf05 | |
| parent | 826961600aa23645ff9200e2c1802779eb68d835 (diff) | |
| download | libtwittercpp-204181c5654cee745b6b1ba98675609e784f0ee1.tar.gz libtwittercpp-204181c5654cee745b6b1ba98675609e784f0ee1.tar.bz2 libtwittercpp-204181c5654cee745b6b1ba98675609e784f0ee1.zip | |
Added ability to hydrate tweets
| -rw-r--r-- | src/client.cpp | 33 | ||||
| -rw-r--r-- | src/client.h | 2 |
2 files changed, 35 insertions, 0 deletions
| diff --git a/src/client.cpp b/src/client.cpp index b7eb9d1..0a4cf2a 100644 --- a/src/client.cpp +++ b/src/client.cpp | |||
| @@ -351,4 +351,37 @@ namespace twitter { | |||
| 351 | return *_configuration; | 351 | return *_configuration; |
| 352 | } | 352 | } |
| 353 | 353 | ||
| 354 | std::list<tweet> client::hydrateTweets(std::set<tweet_id> ids) const | ||
| 355 | { | ||
| 356 | std::list<tweet> result; | ||
| 357 | |||
| 358 | while (!ids.empty()) | ||
| 359 | { | ||
| 360 | std::set<tweet_id> cur; | ||
| 361 | |||
| 362 | for (int i = 0; i < 100 && !ids.empty(); i++) | ||
| 363 | { | ||
| 364 | cur.insert(*std::begin(ids)); | ||
| 365 | ids.erase(std::begin(ids)); | ||
| 366 | } | ||
| 367 | |||
| 368 | std::string datastr = "id=" + | ||
| 369 | OAuth::PercentEncode(implode(std::begin(cur), std::end(cur), ",")); | ||
| 370 | |||
| 371 | std::string response = | ||
| 372 | post(auth_, | ||
| 373 | "https://api.twitter.com/1.1/statuses/lookup.json", | ||
| 374 | datastr).perform(); | ||
| 375 | |||
| 376 | nlohmann::json rjs = nlohmann::json::parse(response); | ||
| 377 | |||
| 378 | for (auto& single : rjs) | ||
| 379 | { | ||
| 380 | result.emplace_back(single.dump()); | ||
| 381 | } | ||
| 382 | } | ||
| 383 | |||
| 384 | return result; | ||
| 385 | } | ||
| 386 | |||
| 354 | }; | 387 | }; |
| diff --git a/src/client.h b/src/client.h index 5e2ab1c..6eb8181 100644 --- a/src/client.h +++ b/src/client.h | |||
| @@ -55,6 +55,8 @@ namespace twitter { | |||
| 55 | return mentionsTimeline_; | 55 | return mentionsTimeline_; |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | std::list<tweet> hydrateTweets(std::set<tweet_id> ids) const; | ||
| 59 | |||
| 58 | private: | 60 | private: |
| 59 | 61 | ||
| 60 | const auth& auth_; | 62 | const auth& auth_; |
