Tweetオブジェクトに機能追加
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
#include <cocoatweet/api/model/tweet.h>
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
#include <cocoatweet/exception/tweetNotFoundException.h>
|
#include <cocoatweet/exception/tweetNotFoundException.h>
|
||||||
#include <cocoatweet/exception/authenticateException.h>
|
#include <cocoatweet/exception/authenticateException.h>
|
||||||
|
#include <cocoatweet/exception/tweetDuplicateException.h>
|
||||||
|
#include <cocoatweet/exception/tweetTooLongException.h>
|
||||||
|
#include <cocoatweet/exception/rateLimitException.h>
|
||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -12,6 +15,9 @@ Tweet Tweet::parse(const unsigned int _responseCode, const std::string& _json) {
|
|||||||
|
|
||||||
if (_responseCode == 200) {
|
if (_responseCode == 200) {
|
||||||
tweet.id(j["id_str"]);
|
tweet.id(j["id_str"]);
|
||||||
|
tweet.createdAt(j["created_at"]);
|
||||||
|
tweet.text(j["text"]);
|
||||||
|
tweet.source(j["source"]);
|
||||||
} else {
|
} else {
|
||||||
auto error = j["errors"][0]["code"];
|
auto error = j["errors"][0]["code"];
|
||||||
auto message = j["errors"][0]["message"];
|
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<std::string>().c_str());
|
throw CocoaTweet::Exception::TweetNotFoundException(message.get<std::string>().c_str());
|
||||||
}else if(error.get<int>() == 32){
|
}else if(error.get<int>() == 32){
|
||||||
throw CocoaTweet::Exception::AuthenticateException(message.get<std::string>().c_str());
|
throw CocoaTweet::Exception::AuthenticateException(message.get<std::string>().c_str());
|
||||||
|
}else if(error.get<int>() == 187){
|
||||||
|
throw CocoaTweet::Exception::TweetDuplicateException(message.get<std::string>().c_str());
|
||||||
|
}else if(error.get<int>() == 88 || error.get<int>() == 185){
|
||||||
|
throw CocoaTweet::Exception::RateLimitException(message.get<std::string>().c_str());
|
||||||
|
}else if(error.get<int>() == 186){
|
||||||
|
throw CocoaTweet::Exception::TweetTooLongException(message.get<std::string>().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +41,27 @@ void Tweet::id(const std::string _id) {
|
|||||||
id_ = _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 {
|
const std::string Tweet::id() const {
|
||||||
return id_;
|
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
|
} // namespace CocoaTweet::API::Model
|
||||||
|
|||||||
@@ -12,10 +12,21 @@ public:
|
|||||||
: Tweet(Tweet::parse(_responseCode, _json)) {}
|
: Tweet(Tweet::parse(_responseCode, _json)) {}
|
||||||
static Tweet parse(const unsigned int _responseCode, const std::string& _json);
|
static Tweet parse(const unsigned int _responseCode, const std::string& _json);
|
||||||
void id(const std::string _id);
|
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 id() const;
|
||||||
|
const std::string createdAt() const;
|
||||||
|
const std::string text() const;
|
||||||
|
const std::string source() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string id_;
|
std::string id_;
|
||||||
|
std::string createdAt_;
|
||||||
|
std::string text_;
|
||||||
|
std::string source_;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Model
|
} // namespace CocoaTweet::API::Model
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user