めんどくさくなったから一括でコミットするけど許してくれ
This commit is contained in:
@@ -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 <cocoatweet/api/status/status.h>
|
||||
#include <cocoatweet/api/favorite/favorite.h>
|
||||
#include <cocoatweet/oauth/oauth.h>
|
||||
|
||||
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:
|
||||
|
||||
@@ -11,7 +11,6 @@ void Create::id(const std::string& _id) {
|
||||
}
|
||||
|
||||
void Create::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _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
|
||||
|
||||
@@ -11,7 +11,6 @@ void Destroy::id(const std::string& _id) {
|
||||
}
|
||||
|
||||
void Destroy::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _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
|
||||
|
||||
@@ -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<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||
std::function<void(std::string)> _callback) {
|
||||
std::function<void(std::string)> _callback) {
|
||||
// エンドポイントへのパラメータにOAuthパラメータを付加して署名作成
|
||||
auto oauth = _oauth.lock();
|
||||
auto oauthParam = oauth->oauthParam();
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
namespace CocoaTweet::API::Interface {
|
||||
class HttpPost {
|
||||
public:
|
||||
|
||||
protected:
|
||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
||||
std::map<std::string, std::string> bodyParam_;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef COCOATWEET_API_MEDIA_UPLOAD_H_
|
||||
#define COCOATWEET_API_MEDIA_UPLOAD_H_
|
||||
|
||||
#include <cocoatweet/api/interface/postInterface.h>
|
||||
|
||||
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<CocoaTweet::OAuth::OAuth1> _oauth, Command _command);
|
||||
}
|
||||
} // namespace CocoaTweet::API::Medias
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <cocoatweet/api/model/tweet.h>
|
||||
#include <cocoatweet/exception/tweetNotFoundException.h>
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
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<int>() == 144) {
|
||||
throw CocoaTweet::Exception::TweetNotFoundException(message.get<std::string>().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
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef COCOATWEET_API_MODEL_TWEET_H_
|
||||
#define COCOATWEET_API_MODEL_TWEET_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
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
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "cocoatweet/api/status/destroy.h"
|
||||
#include <cocoatweet/api/model/tweet.h>
|
||||
#include <iostream>
|
||||
namespace CocoaTweet::API::Statuses {
|
||||
Destroy::Destroy() {}
|
||||
@@ -8,8 +9,11 @@ void Destroy::id(const std::string _id) {
|
||||
}
|
||||
|
||||
void Destroy::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _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
|
||||
|
||||
@@ -2,15 +2,23 @@
|
||||
#define COCOATWEET_API_STATUSES_DESTROY_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "cocoatweet/api/interface/httpPost.h"
|
||||
//#include "cocoatweet/oauth/oauth.h"
|
||||
#include <cocoatweet/api/interface/httpPost.h>
|
||||
|
||||
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<CocoaTweet::OAuth::OAuth1> _oauth : pointer to oauth object
|
||||
/// @param[out] none
|
||||
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
|
||||
@@ -12,8 +12,7 @@ void Update::status(const std::string _status) {
|
||||
}
|
||||
|
||||
void Update::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _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
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#include <cocoatweet/exception/exception.h>
|
||||
|
||||
namespace CocoaTweet::Exception{
|
||||
class AuthenticateException final: Exception{
|
||||
using Exception::Exception;
|
||||
};
|
||||
}
|
||||
namespace CocoaTweet::Exception {
|
||||
class AuthenticateException final : Exception {
|
||||
using Exception::Exception;
|
||||
};
|
||||
} // namespace CocoaTweet::Exception
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,15 +4,18 @@
|
||||
#include <string>
|
||||
#include <exception>
|
||||
|
||||
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
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#include <cocoatweet/exception/exception.h>
|
||||
|
||||
namespace CocoaTweet::Exception{
|
||||
class RateLimitException final: Exception{
|
||||
using Exception::Exception;
|
||||
};
|
||||
}
|
||||
namespace CocoaTweet::Exception {
|
||||
class RateLimitException final : Exception {
|
||||
using Exception::Exception;
|
||||
};
|
||||
} // namespace CocoaTweet::Exception
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#include <cocoatweet/exception/exception.h>
|
||||
|
||||
namespace CocoaTweet::Exception{
|
||||
class TweetDuplicateException final: Exception{
|
||||
using Exception::Exception;
|
||||
};
|
||||
}
|
||||
namespace CocoaTweet::Exception {
|
||||
class TweetDuplicateException final : Exception {
|
||||
using Exception::Exception;
|
||||
};
|
||||
} // namespace CocoaTweet::Exception
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#include <cocoatweet/exception/exception.h>
|
||||
|
||||
namespace CocoaTweet::Exception{
|
||||
class TweetNotFoundException final: Exception{
|
||||
using Exception::Exception;
|
||||
};
|
||||
}
|
||||
namespace CocoaTweet::Exception {
|
||||
class TweetNotFoundException final : Exception {
|
||||
using Exception::Exception;
|
||||
};
|
||||
} // namespace CocoaTweet::Exception
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
#include <cocoatweet/exception/exception.h>
|
||||
|
||||
namespace CocoaTweet::Exception{
|
||||
class TweetTooLongException final: Exception{
|
||||
using Exception::Exception;
|
||||
};
|
||||
}
|
||||
namespace CocoaTweet::Exception {
|
||||
class TweetTooLongException final : Exception {
|
||||
using Exception::Exception;
|
||||
};
|
||||
} // namespace CocoaTweet::Exception
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user