From 9742f20199e256350bc9078d123ba922a3c8f790 Mon Sep 17 00:00:00 2001 From: keita Date: Thu, 4 Mar 2021 14:00:15 +0900 Subject: [PATCH] =?UTF-8?q?Tweet=E3=82=AA=E3=83=96=E3=82=B8=E3=82=A7?= =?UTF-8?q?=E3=82=AF=E3=83=88=E3=81=AB=E6=A9=9F=E8=83=BD=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cocoatweet/api/model/tweet.cc | 32 +++++++++++++++++++++++++++++++ src/cocoatweet/api/model/tweet.h | 11 +++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/cocoatweet/api/model/tweet.cc b/src/cocoatweet/api/model/tweet.cc index 3ee397e..5eb782a 100644 --- a/src/cocoatweet/api/model/tweet.cc +++ b/src/cocoatweet/api/model/tweet.cc @@ -1,6 +1,9 @@ #include #include #include +#include +#include +#include #include "nlohmann/json.hpp" #include @@ -12,6 +15,9 @@ Tweet Tweet::parse(const unsigned int _responseCode, const std::string& _json) { if (_responseCode == 200) { tweet.id(j["id_str"]); + tweet.createdAt(j["created_at"]); + tweet.text(j["text"]); + tweet.source(j["source"]); } else { auto error = j["errors"][0]["code"]; auto message = j["errors"][0]["message"]; @@ -19,6 +25,12 @@ Tweet Tweet::parse(const unsigned int _responseCode, const std::string& _json) { throw CocoaTweet::Exception::TweetNotFoundException(message.get().c_str()); }else if(error.get() == 32){ throw CocoaTweet::Exception::AuthenticateException(message.get().c_str()); + }else if(error.get() == 187){ + throw CocoaTweet::Exception::TweetDuplicateException(message.get().c_str()); + }else if(error.get() == 88 || error.get() == 185){ + throw CocoaTweet::Exception::RateLimitException(message.get().c_str()); + }else if(error.get() == 186){ + throw CocoaTweet::Exception::TweetTooLongException(message.get().c_str()); } } @@ -29,7 +41,27 @@ void Tweet::id(const std::string _id) { id_ = _id; } +void Tweet::createdAt(const std::string _at){ + createdAt_ = _at; +} + +void Tweet::text(const std::string _text){ + text_ = _text; +} +void Tweet::source(const std::string _source){ + source_ = _source; +} + const std::string Tweet::id() const { return id_; } +const std::string Tweet::createdAt() const { + return createdAt_; +} +const std::string Tweet::text() const { + return text_; +} +const std::string Tweet::source() const { + return source_; +} } // namespace CocoaTweet::API::Model diff --git a/src/cocoatweet/api/model/tweet.h b/src/cocoatweet/api/model/tweet.h index 085362d..0be1cbd 100644 --- a/src/cocoatweet/api/model/tweet.h +++ b/src/cocoatweet/api/model/tweet.h @@ -12,10 +12,21 @@ public: : Tweet(Tweet::parse(_responseCode, _json)) {} static Tweet parse(const unsigned int _responseCode, const std::string& _json); void id(const std::string _id); + void createdAt(const std::string _at); + void text(const std::string _text); + void source(const std::string _source); const std::string id() const; + const std::string createdAt() const; + const std::string text() const; + const std::string source() const; private: std::string id_; + std::string createdAt_; + std::string text_; + std::string source_; + + }; } // namespace CocoaTweet::API::Model