about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-08-06 16:15:35 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-08-06 16:15:35 -0400
commit4963c3dd55b765a33a16a77af432f2bfa12b8359 (patch)
tree4da1991c8e6ad784d1defb6e686ce92fd708a4a5
parentbc893794c5e7ec1a968c00a8538241278e8c8d34 (diff)
downloadlibtwittercpp-4963c3dd55b765a33a16a77af432f2bfa12b8359.tar.gz
libtwittercpp-4963c3dd55b765a33a16a77af432f2bfa12b8359.tar.bz2
libtwittercpp-4963c3dd55b765a33a16a77af432f2bfa12b8359.zip
Added ability to hydrate user objects
-rw-r--r--src/client.cpp33
-rw-r--r--src/client.h2
2 files changed, 35 insertions, 0 deletions
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 {
384 return result; 384 return result;
385 } 385 }
386 386
387 std::list<user> client::hydrateUsers(std::set<user_id> ids) const
388 {
389 std::list<user> result;
390
391 while (!ids.empty())
392 {
393 std::set<user_id> cur;
394
395 for (int i = 0; i < 100 && !ids.empty(); i++)
396 {
397 cur.insert(*std::begin(ids));
398 ids.erase(std::begin(ids));
399 }
400
401 std::string datastr = "user_id=" +
402 OAuth::PercentEncode(implode(std::begin(cur), std::end(cur), ","));
403
404 std::string response =
405 post(auth_,
406 "https://api.twitter.com/1.1/users/lookup.json",
407 datastr).perform();
408
409 nlohmann::json rjs = nlohmann::json::parse(response);
410
411 for (auto& single : rjs)
412 {
413 result.emplace_back(single.dump());
414 }
415 }
416
417 return result;
418 }
419
387}; 420};
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 {
57 57
58 std::list<tweet> hydrateTweets(std::set<tweet_id> ids) const; 58 std::list<tweet> hydrateTweets(std::set<tweet_id> ids) const;
59 59
60 std::list<user> hydrateUsers(std::set<user_id> ids) const;
61
60 private: 62 private:
61 63
62 const auth& auth_; 64 const auth& auth_;