diff --git a/src/cocoatweet/api/api.h b/src/cocoatweet/api/api.h index 8b2dfdc..c45eb67 100644 --- a/src/cocoatweet/api/api.h +++ b/src/cocoatweet/api/api.h @@ -1,15 +1,24 @@ #ifndef COCOATWEET_API_H_ #define COCOATWEET_API_H_ -#include "cocoatweet/api/status/status.h" -#include "cocoatweet/api/favorite/favorite.h" -#include "cocoatweet/oauth/oauth.h" +#include +#include +#include namespace CocoaTweet::API { +/// @brief Twitter API Entry Point class API { public: + /// @brief primary constructor + /// @param[in] _key Twitter API Key typed CocoaTweet::OAuth::Key API(CocoaTweet::OAuth::Key _key); + + /// @brief Getter for Grouped by Statuses/* + /// @param[out] Status object typed CocoaTweet::API::Statuses::Status Statuses::Status status() const; + + /// @brief Getter for Grouped by Favorites/* + /// @param[out] Favorite object typed CococaTweet::API::Favorites::Favorite Favorites::Favorite favorite() const; private: diff --git a/src/cocoatweet/api/favorite/create.cc b/src/cocoatweet/api/favorite/create.cc index 5aff1ab..75e8f4f 100644 --- a/src/cocoatweet/api/favorite/create.cc +++ b/src/cocoatweet/api/favorite/create.cc @@ -11,7 +11,6 @@ void Create::id(const std::string& _id) { } void Create::process(std::weak_ptr _oauth) { - HttpPost::process(_oauth, - [](const std::string& _srv) { std::cout << _srv << std::endl; }); + HttpPost::process(_oauth, [](const std::string& _srv) { std::cout << _srv << std::endl; }); } } // namespace CocoaTweet::API::Favorites diff --git a/src/cocoatweet/api/favorite/destroy.cc b/src/cocoatweet/api/favorite/destroy.cc index 5e9ce99..a808463 100644 --- a/src/cocoatweet/api/favorite/destroy.cc +++ b/src/cocoatweet/api/favorite/destroy.cc @@ -11,7 +11,6 @@ void Destroy::id(const std::string& _id) { } void Destroy::process(std::weak_ptr _oauth) { - HttpPost::process(_oauth, - [](const std::string& _srv) { std::cout << _srv << std::endl; }); + HttpPost::process(_oauth, [](const std::string& _srv) { std::cout << _srv << std::endl; }); } } // namespace CocoaTweet::API::Favorites diff --git a/src/cocoatweet/api/interface/httpPost.cc b/src/cocoatweet/api/interface/httpPost.cc index fe4272f..56ab08f 100644 --- a/src/cocoatweet/api/interface/httpPost.cc +++ b/src/cocoatweet/api/interface/httpPost.cc @@ -10,15 +10,14 @@ extern "C" { } namespace CocoaTweet::API::Interface { -size_t HttpPost::curlCallback_(char* _ptr, size_t _size, size_t _nmemb, - std::string* _stream) { +size_t HttpPost::curlCallback_(char* _ptr, size_t _size, size_t _nmemb, std::string* _stream) { int realsize = _size * _nmemb; _stream->append(_ptr, realsize); return realsize; } void HttpPost::process(std::weak_ptr _oauth, - std::function _callback) { + std::function _callback) { // エンドポイントへのパラメータにOAuthパラメータを付加して署名作成 auto oauth = _oauth.lock(); auto oauthParam = oauth->oauthParam(); diff --git a/src/cocoatweet/api/interface/httpPost.h b/src/cocoatweet/api/interface/httpPost.h index faedf2b..ed3b676 100644 --- a/src/cocoatweet/api/interface/httpPost.h +++ b/src/cocoatweet/api/interface/httpPost.h @@ -7,7 +7,6 @@ namespace CocoaTweet::API::Interface { class HttpPost { public: - protected: std::weak_ptr oauth_; std::map bodyParam_; diff --git a/src/cocoatweet/api/media/upload.cc b/src/cocoatweet/api/media/upload.cc new file mode 100644 index 0000000..e69de29 diff --git a/src/cocoatweet/api/media/upload.h b/src/cocoatweet/api/media/upload.h new file mode 100644 index 0000000..d2c7554 --- /dev/null +++ b/src/cocoatweet/api/media/upload.h @@ -0,0 +1,22 @@ +#ifndef COCOATWEET_API_MEDIA_UPLOAD_H_ +#define COCOATWEET_API_MEDIA_UPLOAD_H_ + +#include + +namespace CocoaTweet::API::Medias { +class Upload : public postInterface { +public: + enum Command : class st::string { + INIT = "INIT", + APPEND = "APPEND", + FINALIZE = "FINALIZE", + }; + + Upload::Upload(); + void media(const std::string& _media); + void mediaId(const std::string _mediaId); + void process(std::weak_ptr _oauth, Command _command); +} +} // namespace CocoaTweet::API::Medias + +#endif \ No newline at end of file diff --git a/src/cocoatweet/api/model/tweet.cc b/src/cocoatweet/api/model/tweet.cc new file mode 100644 index 0000000..590b579 --- /dev/null +++ b/src/cocoatweet/api/model/tweet.cc @@ -0,0 +1,33 @@ +#include +#include +#include "nlohmann/json.hpp" + +#include + +namespace CocoaTweet::API::Model { +Tweet Tweet::parse(const unsigned int _responseCode, const std::string& _json) { + auto j = nlohmann::json::parse(_json); + Tweet tweet; + + if (_responseCode == 200) { + Tweet tweet; + tweet.id(j["id_str"]); + } else { + auto error = j["errors"][0]["code"]; + auto message = j["errors"][0]["message"]; + if (error.get() == 144) { + throw CocoaTweet::Exception::TweetNotFoundException(message.get().c_str()); + } + } + + return tweet; +} + +void Tweet::id(const std::string& _id) { + id_ = _id; +} + +const std::string& Tweet::id() const { + return id_; +} +} // namespace CocoaTweet::API::Model diff --git a/src/cocoatweet/api/model/tweet.h b/src/cocoatweet/api/model/tweet.h new file mode 100644 index 0000000..d039479 --- /dev/null +++ b/src/cocoatweet/api/model/tweet.h @@ -0,0 +1,22 @@ +#ifndef COCOATWEET_API_MODEL_TWEET_H_ +#define COCOATWEET_API_MODEL_TWEET_H_ + +#include + +namespace CocoaTweet::API::Model { +class Tweet final { +public: + Tweet() = default; + Tweet(const Tweet&) = default; + Tweet(const unsigned int _responseCode, const std::string& _json) + : Tweet(Tweet::parse(_responseCode, _json)) {} + static Tweet parse(const unsigned int _responseCode, const std::string& _json); + void id(const std::string& _id); + const std::string& id() const; + +private: + std::string id_; +}; +} // namespace CocoaTweet::API::Model + +#endif diff --git a/src/cocoatweet/api/status/destroy.cc b/src/cocoatweet/api/status/destroy.cc index c7bb1f5..339894a 100644 --- a/src/cocoatweet/api/status/destroy.cc +++ b/src/cocoatweet/api/status/destroy.cc @@ -1,4 +1,5 @@ #include "cocoatweet/api/status/destroy.h" +#include #include namespace CocoaTweet::API::Statuses { Destroy::Destroy() {} @@ -8,8 +9,11 @@ void Destroy::id(const std::string _id) { } void Destroy::process(std::weak_ptr _oauth) { - HttpPost::process(_oauth, - [](const std::string& _srv) { std::cout << _srv << std::endl; }); + CocoaTweet::API::Model::Tweet tweet; + HttpPost::process(_oauth, [&tweet](const std::string& _srv) { + tweet = CocoaTweet::API::Model::Tweet::parse(100, _srv); + }); + std::cout << "afw" << std::endl; } } // namespace CocoaTweet::API::Statuses diff --git a/src/cocoatweet/api/status/destroy.h b/src/cocoatweet/api/status/destroy.h index 9a625a0..24eab78 100644 --- a/src/cocoatweet/api/status/destroy.h +++ b/src/cocoatweet/api/status/destroy.h @@ -2,15 +2,23 @@ #define COCOATWEET_API_STATUSES_DESTROY_H_ #include - -#include "cocoatweet/api/interface/httpPost.h" -//#include "cocoatweet/oauth/oauth.h" +#include namespace CocoaTweet::API::Statuses { +/// @brief class for using status/destroy:id endpoint class Destroy : public CocoaTweet::API::Interface::HttpPost { public: + /// @brief primary constructor Destroy(); + + /// @brief set tweet id to destroy + /// @param[in] std::string _id : tweet id which should be destroy + /// @param[out] none void id(const std::string _id); + + /// @brief process request for endpoint + /// @param[in] std::weak_ptr _oauth : pointer to oauth object + /// @param[out] none void process(std::weak_ptr _oauth); }; } // namespace CocoaTweet::API::Statuses diff --git a/src/cocoatweet/api/status/update.cc b/src/cocoatweet/api/status/update.cc index 4c4fb40..5605524 100644 --- a/src/cocoatweet/api/status/update.cc +++ b/src/cocoatweet/api/status/update.cc @@ -12,8 +12,7 @@ void Update::status(const std::string _status) { } void Update::process(std::weak_ptr _oauth) { - HttpPost::process(_oauth, - [](const std::string& _srv) { std::cout << _srv << std::endl; }); + HttpPost::process(_oauth, [](const std::string& _srv) { std::cout << _srv << std::endl; }); } } // namespace CocoaTweet::API::Statuses diff --git a/src/cocoatweet/exception/authenticateException.h b/src/cocoatweet/exception/authenticateException.h index ecf4027..53f0a30 100644 --- a/src/cocoatweet/exception/authenticateException.h +++ b/src/cocoatweet/exception/authenticateException.h @@ -3,10 +3,10 @@ #include -namespace CocoaTweet::Exception{ - class AuthenticateException final: Exception{ - using Exception::Exception; - }; -} +namespace CocoaTweet::Exception { +class AuthenticateException final : Exception { + using Exception::Exception; +}; +} // namespace CocoaTweet::Exception #endif diff --git a/src/cocoatweet/exception/exception.h b/src/cocoatweet/exception/exception.h index 3e2572f..90683e3 100644 --- a/src/cocoatweet/exception/exception.h +++ b/src/cocoatweet/exception/exception.h @@ -4,15 +4,18 @@ #include #include -namespace CocoaTweet::Exception{ -class Exception: public std::exception{ - public: - Exception(const char* _msg):msg_(std::string(_msg)){} - const std::string& what(){return msg_;} - virtual ~Exception() = default; - protected: - std::string msg_; +namespace CocoaTweet::Exception { +class Exception : public std::exception { +public: + Exception(const char* _msg) : msg_(std::string(_msg)) {} + const std::string& what() { + return msg_; + } + virtual ~Exception() = default; + +protected: + std::string msg_; }; -} +} // namespace CocoaTweet::Exception #endif diff --git a/src/cocoatweet/exception/rateLimitException.h b/src/cocoatweet/exception/rateLimitException.h index 3457347..2021f49 100644 --- a/src/cocoatweet/exception/rateLimitException.h +++ b/src/cocoatweet/exception/rateLimitException.h @@ -3,10 +3,10 @@ #include -namespace CocoaTweet::Exception{ - class RateLimitException final: Exception{ - using Exception::Exception; - }; -} +namespace CocoaTweet::Exception { +class RateLimitException final : Exception { + using Exception::Exception; +}; +} // namespace CocoaTweet::Exception #endif diff --git a/src/cocoatweet/exception/tweetDuplicateException.h b/src/cocoatweet/exception/tweetDuplicateException.h index 385f82c..83a5433 100644 --- a/src/cocoatweet/exception/tweetDuplicateException.h +++ b/src/cocoatweet/exception/tweetDuplicateException.h @@ -3,10 +3,10 @@ #include -namespace CocoaTweet::Exception{ - class TweetDuplicateException final: Exception{ - using Exception::Exception; - }; -} +namespace CocoaTweet::Exception { +class TweetDuplicateException final : Exception { + using Exception::Exception; +}; +} // namespace CocoaTweet::Exception #endif diff --git a/src/cocoatweet/exception/tweetNotFoundException.h b/src/cocoatweet/exception/tweetNotFoundException.h index 05fd98d..6c576ab 100644 --- a/src/cocoatweet/exception/tweetNotFoundException.h +++ b/src/cocoatweet/exception/tweetNotFoundException.h @@ -3,10 +3,10 @@ #include -namespace CocoaTweet::Exception{ - class TweetNotFoundException final: Exception{ - using Exception::Exception; - }; -} +namespace CocoaTweet::Exception { +class TweetNotFoundException final : Exception { + using Exception::Exception; +}; +} // namespace CocoaTweet::Exception #endif diff --git a/src/cocoatweet/exception/tweetTooLongException.h b/src/cocoatweet/exception/tweetTooLongException.h index 2aaed1f..680bf1f 100644 --- a/src/cocoatweet/exception/tweetTooLongException.h +++ b/src/cocoatweet/exception/tweetTooLongException.h @@ -3,10 +3,10 @@ #include -namespace CocoaTweet::Exception{ - class TweetTooLongException final: Exception{ - using Exception::Exception; - }; -} +namespace CocoaTweet::Exception { +class TweetTooLongException final : Exception { + using Exception::Exception; +}; +} // namespace CocoaTweet::Exception #endif