From d3d0dc96fdba338836f2b6a9d034c9516ee21fae Mon Sep 17 00:00:00 2001 From: keita Date: Thu, 7 Oct 2021 21:26:24 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=82=AA=E3=83=96?= =?UTF-8?q?=E3=82=B8=E3=82=A7=E3=82=AF=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cocoatweet/api/model/user.cc | 97 ++++++++++++++++++++++++++++++++ src/cocoatweet/api/model/user.h | 5 +- src/main.cc | 15 +++-- 3 files changed, 105 insertions(+), 12 deletions(-) diff --git a/src/cocoatweet/api/model/user.cc b/src/cocoatweet/api/model/user.cc index 2f35f6c..ec0373e 100644 --- a/src/cocoatweet/api/model/user.cc +++ b/src/cocoatweet/api/model/user.cc @@ -7,6 +7,32 @@ CocoaTweet::API::Model::User User::parse(const std::string& _json) { User user; user.id(j["id_str"]); + user.name(j["name"]); + user.screenName(j["screen_name"]); + if (j["location"].is_null() == false) { + user.location(j["location"]); + } + + if (j["url"].is_null() == false) { + user.location(j["url"]); + } + + if (j["description"].is_null() == false) { + user.location(j["description"]); + } + + user.protectedUser(j["protected"]); + user.follower(j["followers_count"]); + user.follow(j["friends_count"]); + user.listed(j["listed_count"]); + user.favorite(j["favourites_count"]); + if (j["profile_banner_url"].is_null() == false) { + user.bannerUrl(j["profile_banner_url"]); + } + if (j["profile_image_url_https"].is_null() == false) { + user.iconUrl(j["profile_image_url_https"]); + } + return user; } @@ -25,9 +51,80 @@ void User::screenName(const std::string& _screen) { void User::location(const std::string& _location) { location_ = _location; } +void User::url(const std::string& _url) { + url_ = _url; +} +void User::description(const std::string& _description) { + description_ = _description; +} + +void User::protectedUser(const bool _protected) { + protectedUser_ = _protected; +} +void User::follower(const long _follower) { + follower_ = _follower; +} +void User::follow(const long _follow) { + follow_ = _follow; +} +void User::listed(const long _listed) { + listed_ = _listed; +} +void User::favorite(const long _favorite) { + favorite_ = _favorite; +} +void User::createdAt(const std::string& _created) { + createdAt_ = _created; +} +void User::bannerUrl(const std::string& _banner) { + bannerUrl_ = _banner; +} +void User::iconUrl(const std::string& _icon) { + iconUrl_ = _icon; +} const std::string& User::id() const { return id_; } +const std::string& User::name() const { + return name_; +} +const std::string& User::screenName() const { + return screenName_; +} +const std::string& User::location() const { + return location_; +} +const std::string& User::url() const { + return url_; +} +const std::string& User::description() const { + return description_; +} +bool User::protectedUser() const { + return protectedUser_; +} +long User::follower() const { + return follower_; +} +long User::follow() const { + return follow_; +} +long User::listed() const { + return listed_; +} +long User::favorite() const { + return favorite_; +} +const std::string& User::created() const { + return createdAt_; +} +const std::string& User::bannerUrl() const { + return bannerUrl_; +} +const std::string& User::icon() const { + return iconUrl_; +} + } // namespace CocoaTweet::API::Model diff --git a/src/cocoatweet/api/model/user.h b/src/cocoatweet/api/model/user.h index bac9a01..1a46630 100644 --- a/src/cocoatweet/api/model/user.h +++ b/src/cocoatweet/api/model/user.h @@ -34,7 +34,6 @@ public: void follow(const long _follow); void listed(const long _listed); void favorite(const long _favorite); - void tweet(const long _tweet); void createdAt(const std::string& _created); void bannerUrl(const std::string& _banner); void iconUrl(const std::string& _icon); @@ -50,9 +49,8 @@ public: long follow() const; long listed() const; long favorite() const; - long tweet() const; const std::string& created() const; - const std::string& banner() const; + const std::string& bannerUrl() const; const std::string& icon() const; private: @@ -67,7 +65,6 @@ private: long follow_; long listed_; long favorite_; - long tweet_; std::string createdAt_; std::string bannerUrl_; std::string iconUrl_; diff --git a/src/main.cc b/src/main.cc index 50c1b6d..8487682 100644 --- a/src/main.cc +++ b/src/main.cc @@ -29,20 +29,19 @@ auto main() -> int { // accessTokenSecret); // also can generate Key object from JSON file - CocoaTweet::OAuth::Key key = CocoaTweet::OAuth::Key::fromJsonFile("api_key.json"); - // auto oauth = CocoaTweet::OAuth::OAuth1(key); - // oauth.GenerateBearerToken(); + // CocoaTweet::OAuth::Key key = CocoaTweet::OAuth::Key::fromJsonFile("api_key.json"); - // std::cout << "sdfgwregfresgfresdwefgweragregreagretgreawgrt#$QTWREATGREWTGF$ERTF"; // Generate API Entry object using Key object - CocoaTweet::API::API api(key); - // std::cout << api.generateBearerToken() << std::endl; + // CocoaTweet::API::API api(key); + + // if you want to access api using Bearer Token, call this for get BearerToken; + // NOTE: call this, always authenticate with Bearer Token, which is Read Only Token + // api.generateBearerToken(); // Now, you can use a twitter api // auto status = api.status().update("Hello Twitter World via Cocoa Twitter Library"); // api.favorite().create(status.id()); // api.favorite().destroy(status.id()); // api.status().destroy(status.id()); - auto timeline = api.status().userTimeline("milkcocoa0902"); - std::cout << timeline[0].user().id(); + // auto timeline = api.status().userTimeline("milkcocoa0902"); }