From 4963c3dd55b765a33a16a77af432f2bfa12b8359 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 6 Aug 2018 16:15:35 -0400 Subject: Added ability to hydrate user objects --- src/client.cpp | 33 +++++++++++++++++++++++++++++++++ src/client.h | 2 ++ 2 files changed, 35 insertions(+) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index 0a4cf2a..3a01c90 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -384,4 +384,37 @@ namespace twitter { return result; } + std::list client::hydrateUsers(std::set ids) const + { + std::list result; + + while (!ids.empty()) + { + std::set cur; + + for (int i = 0; i < 100 && !ids.empty(); i++) + { + cur.insert(*std::begin(ids)); + ids.erase(std::begin(ids)); + } + + std::string datastr = "user_id=" + + OAuth::PercentEncode(implode(std::begin(cur), std::end(cur), ",")); + + std::string response = + post(auth_, + "https://api.twitter.com/1.1/users/lookup.json", + datastr).perform(); + + nlohmann::json rjs = nlohmann::json::parse(response); + + for (auto& single : rjs) + { + result.emplace_back(single.dump()); + } + } + + return result; + } + }; diff --git a/src/client.h b/src/client.h index 6eb8181..ba68e6b 100644 --- a/src/client.h +++ b/src/client.h @@ -57,6 +57,8 @@ namespace twitter { std::list hydrateTweets(std::set ids) const; + std::list hydrateUsers(std::set ids) const; + private: const auth& auth_; -- cgit 1.4.1