Model::TweetからHttpPostにエラーハンドリングを移動した(#67)
This commit is contained in:
@@ -13,9 +13,8 @@ void Create::id(const std::string& _id) {
|
|||||||
|
|
||||||
CocoaTweet::API::Model::Tweet Create::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
CocoaTweet::API::Model::Tweet Create::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
CocoaTweet::API::Model::Tweet tweet;
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
HttpPost::process(_oauth,
|
HttpPost::process(_oauth, [&tweet](const std::string& _rcv) {
|
||||||
[&tweet](const unsigned int _responseCode, const std::string& _rcv) {
|
tweet = CocoaTweet::API::Model::Tweet(_rcv);
|
||||||
tweet = CocoaTweet::API::Model::Tweet(_responseCode, _rcv);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return tweet;
|
return tweet;
|
||||||
|
|||||||
@@ -14,9 +14,8 @@ void Destroy::id(const std::string& _id) {
|
|||||||
CocoaTweet::API::Model::Tweet Destroy::process(
|
CocoaTweet::API::Model::Tweet Destroy::process(
|
||||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
CocoaTweet::API::Model::Tweet tweet;
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
HttpPost::process(_oauth,
|
HttpPost::process(_oauth, [&tweet](const std::string& _rcv) {
|
||||||
[&tweet](const unsigned int _responseCode, const std::string& _rcv) {
|
tweet = CocoaTweet::API::Model::Tweet(_rcv);
|
||||||
tweet = CocoaTweet::API::Model::Tweet(_responseCode, _rcv);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return tweet;
|
return tweet;
|
||||||
|
|||||||
@@ -12,9 +12,8 @@ protected:
|
|||||||
std::map<std::string, std::string> bodyParam_;
|
std::map<std::string, std::string> bodyParam_;
|
||||||
std::string url_;
|
std::string url_;
|
||||||
std::string contentType_;
|
std::string contentType_;
|
||||||
virtual void process(
|
virtual void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
std::function<void(const std::string&)> _callback) = 0;
|
||||||
std::function<void(const unsigned int, const std::string&)> _callback) = 0;
|
|
||||||
static size_t curlCallback_(char* _ptr, size_t _size, size_t _nmemb, std::string* _stream) {
|
static size_t curlCallback_(char* _ptr, size_t _size, size_t _nmemb, std::string* _stream) {
|
||||||
int realsize = _size * _nmemb;
|
int realsize = _size * _nmemb;
|
||||||
_stream->append(_ptr, realsize);
|
_stream->append(_ptr, realsize);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ extern "C" {
|
|||||||
|
|
||||||
namespace CocoaTweet::API::Interface {
|
namespace CocoaTweet::API::Interface {
|
||||||
void HttpGet::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
void HttpGet::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||||
std::function<void(const unsigned int, const std::string&)> _callback) {
|
std::function<void(const std::string&)> _callback) {
|
||||||
auto url = url_;
|
auto url = url_;
|
||||||
|
|
||||||
// エンドポイントへのパラメータにOAuthパラメータを付加して署名作成
|
// エンドポイントへのパラメータにOAuthパラメータを付加して署名作成
|
||||||
@@ -92,7 +92,7 @@ void HttpGet::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (_callback) {
|
if (_callback) {
|
||||||
_callback(responseCode, rcv);
|
_callback(rcv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace CocoaTweet::API::Interface
|
} // namespace CocoaTweet::API::Interface
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ protected:
|
|||||||
/// @param[in] std::function<void(const unsigned int, const std::string&)> _callback :
|
/// @param[in] std::function<void(const unsigned int, const std::string&)> _callback :
|
||||||
/// callback method for processing to response
|
/// callback method for processing to response
|
||||||
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||||
std::function<void(const unsigned int, const std::string&)> _callback);
|
std::function<void(const std::string&)> _callback);
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Interface
|
} // namespace CocoaTweet::API::Interface
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
#include <cocoatweet/api/interface/httpPost.h>
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
#include "cocoatweet/util/util.h"
|
#include "cocoatweet/util/util.h"
|
||||||
|
#include <cocoatweet/exception/tweetNotFoundException.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 <iterator>
|
#include <iterator>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -15,7 +21,7 @@ extern "C" {
|
|||||||
|
|
||||||
namespace CocoaTweet::API::Interface {
|
namespace CocoaTweet::API::Interface {
|
||||||
void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||||
std::function<void(const unsigned int, const std::string&)> _callback) {
|
std::function<void(const std::string&)> _callback) {
|
||||||
// エンドポイントへのパラメータにOAuthパラメータを付加して署名作成
|
// エンドポイントへのパラメータにOAuthパラメータを付加して署名作成
|
||||||
auto oauth = _oauth.lock();
|
auto oauth = _oauth.lock();
|
||||||
auto oauthParam = oauth->oauthParam();
|
auto oauthParam = oauth->oauthParam();
|
||||||
@@ -103,8 +109,29 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((responseCode / 100) == 4) {
|
||||||
|
auto j = nlohmann::json::parse(rcv);
|
||||||
|
auto error = j["errors"][0]["code"];
|
||||||
|
auto message = j["errors"][0]["message"];
|
||||||
|
if (j.count("error") != 0) {
|
||||||
|
// この形式はエラーコードを持たないのでエラー種別が特定できない
|
||||||
|
throw new CocoaTweet::Exception::Exception(j["error"]);
|
||||||
|
}
|
||||||
|
if (error.get<int>() == 144) {
|
||||||
|
throw CocoaTweet::Exception::TweetNotFoundException(message.get<std::string>().c_str());
|
||||||
|
} else if (error.get<int>() == 32) {
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (_callback) {
|
if (_callback) {
|
||||||
_callback(responseCode, rcv);
|
_callback(rcv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace CocoaTweet::API::Interface
|
} // namespace CocoaTweet::API::Interface
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ protected:
|
|||||||
/// @param[in] std::function<void(const unsigned int, const std::string&)> _callback :
|
/// @param[in] std::function<void(const unsigned int, const std::string&)> _callback :
|
||||||
/// callback method for processing to response
|
/// callback method for processing to response
|
||||||
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||||
std::function<void(const unsigned int, const std::string&)> _callback);
|
std::function<void(const std::string&)> _callback);
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Interface
|
} // namespace CocoaTweet::API::Interface
|
||||||
|
|
||||||
|
|||||||
@@ -43,9 +43,8 @@ CocoaTweet::API::Model::MediaStore Upload::process(
|
|||||||
bodyParam_.insert_or_assign(
|
bodyParam_.insert_or_assign(
|
||||||
"media_type", mimeType.at(std::filesystem::path(media_).extension().string<char>()));
|
"media_type", mimeType.at(std::filesystem::path(media_).extension().string<char>()));
|
||||||
|
|
||||||
HttpPost::process(_oauth,
|
HttpPost::process(_oauth, [&media](const std::string& _rcv) {
|
||||||
[&media](const unsigned int _responseCode, const std::string& _rsv) {
|
media = CocoaTweet::API::Model::MediaStore::parse(_rcv);
|
||||||
media = CocoaTweet::API::Model::MediaStore::parse(_responseCode, _rsv);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
bodyParam_.insert_or_assign("media_id", media.id());
|
bodyParam_.insert_or_assign("media_id", media.id());
|
||||||
@@ -63,7 +62,7 @@ CocoaTweet::API::Model::MediaStore Upload::process(
|
|||||||
bodyParam_.insert_or_assign("command", "APPEND");
|
bodyParam_.insert_or_assign("command", "APPEND");
|
||||||
bodyParam_.insert_or_assign("segment_index", std::to_string(segment));
|
bodyParam_.insert_or_assign("segment_index", std::to_string(segment));
|
||||||
bodyParam_.insert_or_assign("media", data.substr(segment * chunk, chunk));
|
bodyParam_.insert_or_assign("media", data.substr(segment * chunk, chunk));
|
||||||
HttpPost::process(_oauth, [](const unsigned int _responseCode, const std::string& _rsv) {
|
HttpPost::process(_oauth, [](const std::string& _rsv) {
|
||||||
// std::cout << _responseCode << std::endl << _rsv<< std::endl;
|
// std::cout << _responseCode << std::endl << _rsv<< std::endl;
|
||||||
});
|
});
|
||||||
segment++;
|
segment++;
|
||||||
@@ -76,10 +75,8 @@ CocoaTweet::API::Model::MediaStore Upload::process(
|
|||||||
bodyParam_.insert_or_assign("command", "FINALIZE");
|
bodyParam_.insert_or_assign("command", "FINALIZE");
|
||||||
bodyParam_.erase("segment_index");
|
bodyParam_.erase("segment_index");
|
||||||
bodyParam_.erase("media");
|
bodyParam_.erase("media");
|
||||||
HttpPost::process(_oauth,
|
HttpPost::process(_oauth, [&media](const std::string& _rcv) {
|
||||||
[&media](const unsigned int _responseCode, const std::string& _rsv) {
|
media = CocoaTweet::API::Model::MediaStore::parse(_rcv);
|
||||||
std::cout << _responseCode << std::endl << _rsv << std::endl;
|
|
||||||
media = CocoaTweet::API::Model::MediaStore::parse(_responseCode, _rsv);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,10 @@
|
|||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
|
|
||||||
namespace CocoaTweet::API::Model {
|
namespace CocoaTweet::API::Model {
|
||||||
MediaStore MediaStore::parse(const unsigned int _responseCode, const std::string& _json) {
|
MediaStore MediaStore::parse(const std::string& _json) {
|
||||||
auto j = nlohmann::json::parse(_json);
|
auto j = nlohmann::json::parse(_json);
|
||||||
MediaStore media;
|
MediaStore media;
|
||||||
|
|
||||||
if (_responseCode / 100 == 2) {
|
|
||||||
if (j.count("media_id_string") != 0) {
|
if (j.count("media_id_string") != 0) {
|
||||||
media.id(j["media_id_string"]);
|
media.id(j["media_id_string"]);
|
||||||
}
|
}
|
||||||
@@ -26,9 +25,6 @@ MediaStore MediaStore::parse(const unsigned int _responseCode, const std::string
|
|||||||
media.state(j["processing_info"]["state"]);
|
media.state(j["processing_info"]["state"]);
|
||||||
media.remain(j["processing_info"]["check_after_secs"].get<unsigned int>());
|
media.remain(j["processing_info"]["check_after_secs"].get<unsigned int>());
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new CocoaTweet::Exception::Exception(j["error"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return media;
|
return media;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,18 +15,13 @@ public:
|
|||||||
MediaStore(const MediaStore&) = default;
|
MediaStore(const MediaStore&) = default;
|
||||||
|
|
||||||
/// @brief constructor for create object from json response
|
/// @brief constructor for create object from json response
|
||||||
/// @param[in] const unsigned int _responseCode : http status code which received when post
|
|
||||||
/// request
|
|
||||||
/// @param[in] const std::string& _json : received content from twitter endpoint
|
/// @param[in] const std::string& _json : received content from twitter endpoint
|
||||||
MediaStore(const unsigned int _responseCode, const std::string& _json)
|
MediaStore(const std::string& _json) : MediaStore(MediaStore::parse(_json)) {}
|
||||||
: MediaStore(MediaStore::parse(_responseCode, _json)) {}
|
|
||||||
|
|
||||||
/// @brief response parser for MediaStore object
|
/// @brief response parser for MediaStore object
|
||||||
/// @param[in] const unsigned int _responseCode : http status code which received when post
|
|
||||||
/// request
|
|
||||||
/// @param[in] const std::string& _json : received content from twitter endpoint
|
/// @param[in] const std::string& _json : received content from twitter endpoint
|
||||||
/// @param[out] CocoaTweet::API::Model::MediaStore
|
/// @param[out] CocoaTweet::API::Model::MediaStore
|
||||||
static MediaStore parse(const unsigned int _responseCode, const std::string& _json);
|
static MediaStore parse(const std::string& _json);
|
||||||
|
|
||||||
/// @brief set id of tweet
|
/// @brief set id of tweet
|
||||||
/// @param[in] const std::string _id : media id to set
|
/// @param[in] const std::string _id : media id to set
|
||||||
|
|||||||
@@ -1,36 +1,15 @@
|
|||||||
#include <cocoatweet/api/model/tweet.h>
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
#include <cocoatweet/exception/tweetNotFoundException.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"
|
||||||
|
|
||||||
namespace CocoaTweet::API::Model {
|
namespace CocoaTweet::API::Model {
|
||||||
Tweet Tweet::parse(const unsigned int _responseCode, const std::string& _json) {
|
Tweet Tweet::parse(const std::string& _json) {
|
||||||
auto j = nlohmann::json::parse(_json);
|
auto j = nlohmann::json::parse(_json);
|
||||||
Tweet tweet;
|
Tweet tweet;
|
||||||
|
|
||||||
if (_responseCode == 200) {
|
|
||||||
tweet.id(j["id_str"]);
|
tweet.id(j["id_str"]);
|
||||||
tweet.createdAt(j["created_at"]);
|
tweet.createdAt(j["created_at"]);
|
||||||
tweet.text(j["text"]);
|
tweet.text(j["text"]);
|
||||||
tweet.source(j["source"]);
|
tweet.source(j["source"]);
|
||||||
} else {
|
|
||||||
auto error = j["errors"][0]["code"];
|
|
||||||
auto message = j["errors"][0]["message"];
|
|
||||||
if (error.get<int>() == 144) {
|
|
||||||
throw CocoaTweet::Exception::TweetNotFoundException(message.get<std::string>().c_str());
|
|
||||||
} else if (error.get<int>() == 32) {
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return tweet;
|
return tweet;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,18 +15,13 @@ public:
|
|||||||
Tweet(const Tweet&) = default;
|
Tweet(const Tweet&) = default;
|
||||||
|
|
||||||
/// @brief constructor for create object from json response
|
/// @brief constructor for create object from json response
|
||||||
/// @param[in] const unsigned int _responseCode : http status code which received when post
|
|
||||||
/// request
|
|
||||||
/// @param[in] const std::string& _json : received content from twitter endpoint
|
/// @param[in] const std::string& _json : received content from twitter endpoint
|
||||||
Tweet(const unsigned int _responseCode, const std::string& _json)
|
Tweet(const std::string& _json) : Tweet(Tweet::parse(_json)) {}
|
||||||
: Tweet(Tweet::parse(_responseCode, _json)) {}
|
|
||||||
|
|
||||||
/// @brief response parser for tweet object
|
/// @brief response parser for tweet object
|
||||||
/// @param[in] const unsigned int _responseCode : http status code which received when post
|
|
||||||
/// request
|
|
||||||
/// @param[in] const std::string& _json : received content from twitter endpoint
|
/// @param[in] const std::string& _json : received content from twitter endpoint
|
||||||
/// @param[out] CocoaTweet::API::Model::Tweet
|
/// @param[out] CocoaTweet::API::Model::Tweet
|
||||||
static Tweet parse(const unsigned int _responseCode, const std::string& _json);
|
static Tweet parse(const std::string& _json);
|
||||||
|
|
||||||
/// @brief set id of tweet
|
/// @brief set id of tweet
|
||||||
/// @param[in] const std::string _id : tweet id to set
|
/// @param[in] const std::string _id : tweet id to set
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ void Destroy::id(const std::string _id) {
|
|||||||
CocoaTweet::API::Model::Tweet Destroy::process(
|
CocoaTweet::API::Model::Tweet Destroy::process(
|
||||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
CocoaTweet::API::Model::Tweet tweet;
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
HttpPost::process(_oauth,
|
HttpPost::process(_oauth, [&tweet](const std::string& _rcv) {
|
||||||
[&tweet](const unsigned int _responseCode, const std::string& _rsv) {
|
tweet = CocoaTweet::API::Model::Tweet::parse(_rcv);
|
||||||
tweet = CocoaTweet::API::Model::Tweet::parse(_responseCode, _rsv);
|
|
||||||
});
|
});
|
||||||
return tweet;
|
return tweet;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,20 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Statuses {
|
namespace CocoaTweet::API::Statuses {
|
||||||
Retweet::Retweet(){}
|
Retweet::Retweet() {}
|
||||||
|
|
||||||
void Retweet::id(const std::string& _id){
|
void Retweet::id(const std::string& _id) {
|
||||||
contentType_ = "application/x-www-form-urlencoded";
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
url_ = "https://api.twitter.com/1.1/statuses/retweet/" + _id + ".json";
|
url_ = "https://api.twitter.com/1.1/statuses/retweet/" + _id + ".json";
|
||||||
}
|
}
|
||||||
|
|
||||||
CocoaTweet::API::Model::Tweet Retweet::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth){
|
CocoaTweet::API::Model::Tweet Retweet::process(
|
||||||
|
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
CocoaTweet::API::Model::Tweet tweet;
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
HttpPost::process(_oauth,
|
HttpPost::process(_oauth, [&tweet](const std::string& _rcv) {
|
||||||
[&tweet](const unsigned int _responseCode, const std::string& _rcv) {
|
tweet = CocoaTweet::API::Model::Tweet(_rcv);
|
||||||
tweet = CocoaTweet::API::Model::Tweet(_responseCode, _rcv);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return tweet;
|
return tweet;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
#include <cocoatweet/api/model/tweet.h>
|
#include <cocoatweet/api/model/tweet.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Statuses {
|
namespace CocoaTweet::API::Statuses {
|
||||||
class Retweet : public CocoaTweet::API::Interface::HttpPost{
|
class Retweet : public CocoaTweet::API::Interface::HttpPost {
|
||||||
public:
|
public:
|
||||||
Retweet();
|
Retweet();
|
||||||
|
|
||||||
void id(const std::string& _id);
|
void id(const std::string& _id);
|
||||||
|
|
||||||
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
};
|
};
|
||||||
}
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -79,7 +79,8 @@ CocoaTweet::API::Model::Tweet Status::Retweet(const std::string& _id) const {
|
|||||||
return retweet.process(oauth_);
|
return retweet.process(oauth_);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CocoaTweet::API::Model::Tweet> Status::UserTimeline(const std::string& _screenName) const{
|
std::vector<CocoaTweet::API::Model::Tweet> Status::UserTimeline(
|
||||||
|
const std::string& _screenName) const {
|
||||||
CocoaTweet::API::Statuses::UserTimeline userTimeline;
|
CocoaTweet::API::Statuses::UserTimeline userTimeline;
|
||||||
userTimeline.screenName(_screenName);
|
userTimeline.screenName(_screenName);
|
||||||
return userTimeline.process(oauth_);
|
return userTimeline.process(oauth_);
|
||||||
|
|||||||
@@ -55,9 +55,8 @@ void Update::failDMCommands(bool _fail) {
|
|||||||
|
|
||||||
CocoaTweet::API::Model::Tweet Update::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
CocoaTweet::API::Model::Tweet Update::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
CocoaTweet::API::Model::Tweet tweet;
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
HttpPost::process(_oauth,
|
HttpPost::process(_oauth, [&tweet](const std::string& _rcv) {
|
||||||
[&tweet](const unsigned int _responseCode, const std::string& _rsv) {
|
tweet = CocoaTweet::API::Model::Tweet::parse(_rcv);
|
||||||
tweet = CocoaTweet::API::Model::Tweet::parse(_responseCode, _rsv);
|
|
||||||
});
|
});
|
||||||
return tweet;
|
return tweet;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ void UserTimeline::screenName(const std::string& _screenName) {
|
|||||||
std::vector<CocoaTweet::API::Model::Tweet> UserTimeline::process(
|
std::vector<CocoaTweet::API::Model::Tweet> UserTimeline::process(
|
||||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||||
std::vector<CocoaTweet::API::Model::Tweet> tweet;
|
std::vector<CocoaTweet::API::Model::Tweet> tweet;
|
||||||
HttpGet::process(_oauth, [&tweet](const unsigned int _responseCode, const std::string& _rsv) {
|
HttpGet::process(_oauth, [&tweet](const std::string& _rcv) {
|
||||||
auto json = nlohmann::json::parse(_rsv);
|
auto json = nlohmann::json::parse(_rcv);
|
||||||
for (auto j : json) {
|
for (auto j : json) {
|
||||||
tweet.push_back(CocoaTweet::API::Model::Tweet::parse(_responseCode, j.dump()));
|
tweet.push_back(CocoaTweet::API::Model::Tweet::parse(j.dump()));
|
||||||
std::cout << j.dump() << std::endl;
|
std::cout << j.dump() << std::endl;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ BOOST_AUTO_TEST_CASE(test02) {
|
|||||||
"source" : "Twitter for Android"
|
"source" : "Twitter for Android"
|
||||||
})";
|
})";
|
||||||
|
|
||||||
CocoaTweet::API::Model::Tweet tweet(200, json);
|
CocoaTweet::API::Model::Tweet tweet(json);
|
||||||
BOOST_TEST(tweet.id() == "1234567890");
|
BOOST_TEST(tweet.id() == "1234567890");
|
||||||
BOOST_TEST(tweet.createdAt() == "Thu Mar 04 00:00:00 +0000 2021");
|
BOOST_TEST(tweet.createdAt() == "Thu Mar 04 00:00:00 +0000 2021");
|
||||||
BOOST_TEST(tweet.text() == "tweet");
|
BOOST_TEST(tweet.text() == "tweet");
|
||||||
@@ -42,7 +42,7 @@ BOOST_AUTO_TEST_CASE(test03) {
|
|||||||
}]
|
}]
|
||||||
})";
|
})";
|
||||||
|
|
||||||
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(401, json),
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(json),
|
||||||
CocoaTweet::Exception::AuthenticateException);
|
CocoaTweet::Exception::AuthenticateException);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ BOOST_AUTO_TEST_CASE(test04) {
|
|||||||
}]
|
}]
|
||||||
})";
|
})";
|
||||||
|
|
||||||
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(429, json),
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(json),
|
||||||
CocoaTweet::Exception::RateLimitException);
|
CocoaTweet::Exception::RateLimitException);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE(test05) {
|
|||||||
}]
|
}]
|
||||||
})";
|
})";
|
||||||
|
|
||||||
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(403, json),
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(json),
|
||||||
CocoaTweet::Exception::RateLimitException);
|
CocoaTweet::Exception::RateLimitException);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(test06) {
|
|||||||
}]
|
}]
|
||||||
})";
|
})";
|
||||||
|
|
||||||
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(403, json),
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(json),
|
||||||
CocoaTweet::Exception::TweetTooLongException);
|
CocoaTweet::Exception::TweetTooLongException);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE(test07) {
|
|||||||
}]
|
}]
|
||||||
})";
|
})";
|
||||||
|
|
||||||
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(403, json),
|
BOOST_CHECK_THROW(CocoaTweet::API::Model::Tweet(json),
|
||||||
CocoaTweet::Exception::TweetDuplicateException);
|
CocoaTweet::Exception::TweetDuplicateException);
|
||||||
}
|
}
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|||||||
Reference in New Issue
Block a user