code format
This commit is contained in:
@@ -8,22 +8,21 @@
|
||||
namespace CocoaTweet::API {
|
||||
API::API(CocoaTweet::Authentication::Key _key) {
|
||||
swapKey(_key);
|
||||
|
||||
}
|
||||
|
||||
void API::swapKey(const CocoaTweet::Authentication::Key _key){
|
||||
if(_key.authType() == CocoaTweet::Authentication::Key::OAUTH10A){
|
||||
oauth_ = std::make_shared<CocoaTweet::Authentication::OAuth1>(_key);
|
||||
}else if(_key.authType() == CocoaTweet::Authentication::Key::OAUTH2){
|
||||
oauth_ = std::make_shared<CocoaTweet::Authentication::Bearer>(_key);
|
||||
void API::swapKey(const CocoaTweet::Authentication::Key _key) {
|
||||
if (_key.authType() == CocoaTweet::Authentication::Key::OAUTH10A) {
|
||||
oauth_ = std::make_shared<CocoaTweet::Authentication::OAuth1>(_key);
|
||||
} else if (_key.authType() == CocoaTweet::Authentication::Key::OAUTH2) {
|
||||
oauth_ = std::make_shared<CocoaTweet::Authentication::Bearer>(_key);
|
||||
}
|
||||
user_ = Users::User(oauth_);
|
||||
status_ = Statuses::Status(oauth_);
|
||||
favorite_ = Favorites::Favorite(oauth_);
|
||||
media_ = Medias::Media(oauth_);
|
||||
directMessage_ = DirectMessages::DirectMessage(oauth_);
|
||||
oauth1_ = OAuth1::OAuth(oauth_);
|
||||
oauth2_ = OAuth2::OAuth2(oauth_);
|
||||
oauth1_ = OAuth1::OAuth(oauth_);
|
||||
oauth2_ = OAuth2::OAuth2(oauth_);
|
||||
}
|
||||
|
||||
// const std::string& API::generateBearerToken() const {
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
#include <cocoatweet/api/directMessage/new.h>
|
||||
|
||||
namespace CocoaTweet::API::DirectMessages {
|
||||
DirectMessage::DirectMessage(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
DirectMessage::DirectMessage(
|
||||
std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ public:
|
||||
DirectMessage() = default;
|
||||
|
||||
/// @brief constructor which finally should to be called.
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> : pointer to OAuth object
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> : pointer to
|
||||
/// OAuth object
|
||||
DirectMessage(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
void messageCreate(const std::string& _recipient, const std::string& _message);
|
||||
|
||||
@@ -17,7 +17,8 @@ public:
|
||||
void message(const std::string& _message);
|
||||
|
||||
/// @brief process request for endpoint
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer to oauth object
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer
|
||||
/// to oauth object
|
||||
/// @param[out] CocoaTweet::API::Model::Tweet : request result
|
||||
void process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@ void Create::id(const std::string& _id) {
|
||||
bodyParam_.insert_or_assign("id", _id);
|
||||
}
|
||||
|
||||
CocoaTweet::API::Model::Tweet Create::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
CocoaTweet::API::Model::Tweet Create::process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
CocoaTweet::API::Model::Tweet tweet;
|
||||
HttpPost::process(_oauth, [&tweet](const std::string& _rcv) {
|
||||
tweet = CocoaTweet::API::Model::Tweet(_rcv);
|
||||
|
||||
@@ -9,7 +9,8 @@ class Create : public CocoaTweet::API::Interface::HttpPost {
|
||||
public:
|
||||
Create();
|
||||
void id(const std::string& _id);
|
||||
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
CocoaTweet::API::Model::Tweet process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -9,7 +9,8 @@ class Destroy : public CocoaTweet::API::Interface::HttpPost {
|
||||
public:
|
||||
Destroy();
|
||||
void id(const std::string& _id);
|
||||
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
CocoaTweet::API::Model::Tweet process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -109,7 +109,7 @@ void HttpGet::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBas
|
||||
std::cout << rcv << std::endl;
|
||||
#endif
|
||||
if ((responseCode / 100) == 4) {
|
||||
auto j = nlohmann::json::parse(rcv);
|
||||
auto j = nlohmann::json::parse(rcv);
|
||||
if (j.count("error") != 0) {
|
||||
// この形式はエラーコードを持たないのでエラー種別が特定できない
|
||||
throw new CocoaTweet::Exception::Exception(j["error"]);
|
||||
@@ -117,7 +117,7 @@ void HttpGet::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBas
|
||||
|
||||
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) {
|
||||
@@ -130,10 +130,12 @@ void HttpGet::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBas
|
||||
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());
|
||||
}else if(error.get<int>() == 170){
|
||||
throw CocoaTweet::Exception::MissingRequiredParamException(message.get<std::string>().c_str());
|
||||
}else if(error.get<int>() == 220){
|
||||
throw CocoaTweet::Exception::CredentialNotAllowedException(message.get<std::string>().c_str());
|
||||
} else if (error.get<int>() == 170) {
|
||||
throw CocoaTweet::Exception::MissingRequiredParamException(
|
||||
message.get<std::string>().c_str());
|
||||
} else if (error.get<int>() == 220) {
|
||||
throw CocoaTweet::Exception::CredentialNotAllowedException(
|
||||
message.get<std::string>().c_str());
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ class HttpGet : public virtual HttpBase {
|
||||
public:
|
||||
protected:
|
||||
/// @brief Send HTTP/POST using OAuth object
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer to OAuth object to
|
||||
/// authenticate
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer
|
||||
/// to OAuth object to authenticate
|
||||
/// @param[in] std::function<void(const unsigned int, const std::string&)> _callback :
|
||||
/// callback method for processing to response
|
||||
void process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth,
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace CocoaTweet::API::Interface {
|
||||
void HttpPost::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth,
|
||||
std::function<void(const std::string&)> _callback) {
|
||||
// エンドポイントへのパラメータにOAuthパラメータを付加して署名作成
|
||||
auto oauth = _oauth.lock();
|
||||
auto oauth = _oauth.lock();
|
||||
// auto oauthParam = oauth->oauthParam();
|
||||
// auto sigingParam = oauthParam;
|
||||
// if (contentType_ == "application/x-www-form-urlencoded") {
|
||||
@@ -71,7 +71,6 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBa
|
||||
// oauthHeader += CocoaTweet::Util::join(tmp, ",");
|
||||
// }
|
||||
|
||||
|
||||
auto oauthHeader = std::string();
|
||||
if (contentType_ == "application/x-www-form-urlencoded") {
|
||||
oauthHeader = oauth->calculateAuthHeader(bodyParam_, "POST", url_);
|
||||
@@ -128,12 +127,12 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBa
|
||||
std::cout << rcv << std::endl;
|
||||
#endif
|
||||
if ((responseCode / 100) == 4) {
|
||||
auto j = nlohmann::json::parse(rcv);
|
||||
auto j = nlohmann::json::parse(rcv);
|
||||
if (j.count("error") != 0) {
|
||||
// この形式はエラーコードを持たないのでエラー種別が特定できない
|
||||
throw new CocoaTweet::Exception::Exception(j["error"]);
|
||||
}
|
||||
|
||||
|
||||
auto error = j["errors"][0]["code"];
|
||||
auto message = j["errors"][0]["message"];
|
||||
if (error.get<int>() == 144) {
|
||||
@@ -148,10 +147,12 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBa
|
||||
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());
|
||||
}else if(error.get<int>() == 170){
|
||||
throw CocoaTweet::Exception::MissingRequiredParamException(message.get<std::string>().c_str());
|
||||
}else if(error.get<int>() == 220){
|
||||
throw CocoaTweet::Exception::CredentialNotAllowedException(message.get<std::string>().c_str());
|
||||
} else if (error.get<int>() == 170) {
|
||||
throw CocoaTweet::Exception::MissingRequiredParamException(
|
||||
message.get<std::string>().c_str());
|
||||
} else if (error.get<int>() == 220) {
|
||||
throw CocoaTweet::Exception::CredentialNotAllowedException(
|
||||
message.get<std::string>().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ class HttpPost : public HttpBase {
|
||||
public:
|
||||
protected:
|
||||
/// @brief Send HTTP/POST using OAuth object
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer to OAuth object to
|
||||
/// authenticate
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer
|
||||
/// to OAuth object to authenticate
|
||||
/// @param[in] std::function<void(const unsigned int, const std::string&)> _callback :
|
||||
/// callback method for processing to response
|
||||
void process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth,
|
||||
|
||||
@@ -16,7 +16,8 @@ public:
|
||||
Media() = default;
|
||||
|
||||
/// @brief constructor which finally should to be called.
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> : pointer to OAuth object
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> : pointer to
|
||||
/// OAuth object
|
||||
Media(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
CocoaTweet::API::Model::MediaStore upload(const std::string& _file) const;
|
||||
|
||||
@@ -26,11 +26,12 @@ public:
|
||||
void mediaId(const std::string& _mediaId);
|
||||
|
||||
/// @brief upload media
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer to OAuth object for
|
||||
/// authenticate
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer
|
||||
/// to OAuth object for authenticate
|
||||
/// @param[out] CocoaTweet::API::Model::MediaStore : media upload result. use id() for post
|
||||
/// tweet.
|
||||
CocoaTweet::API::Model::MediaStore process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
CocoaTweet::API::Model::MediaStore process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
} // namespace CocoaTweet::API::Medias
|
||||
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
#include "oauthToken.h"
|
||||
|
||||
namespace CocoaTweet::API::Model{
|
||||
namespace CocoaTweet::API::Model {
|
||||
|
||||
OAuthToken::OAuthToken(): oauthToken_(""), oauthTokenSecret_(""){}
|
||||
OAuthToken::OAuthToken(const std::string _oauthToken, const std::string& _oauthTokenSecret): oauthToken_(_oauthToken), oauthTokenSecret_(_oauthTokenSecret) {}
|
||||
const std::string& OAuthToken::oauthToken() const {
|
||||
return oauthToken_;
|
||||
}
|
||||
const std::string& OAuthToken::oauthTokenSecret() const{
|
||||
return oauthTokenSecret_;
|
||||
}
|
||||
void OAuthToken::oauthToken(const std::string& _oauthToken) {
|
||||
oauthToken_ = _oauthToken;
|
||||
}
|
||||
void OAuthToken::oauthTokenSecret(const std::string& _oauthTokenSecret){
|
||||
oauthTokenSecret_ = _oauthTokenSecret;
|
||||
}
|
||||
}
|
||||
OAuthToken::OAuthToken() : oauthToken_(""), oauthTokenSecret_("") {}
|
||||
OAuthToken::OAuthToken(const std::string _oauthToken, const std::string& _oauthTokenSecret)
|
||||
: oauthToken_(_oauthToken), oauthTokenSecret_(_oauthTokenSecret) {}
|
||||
const std::string& OAuthToken::oauthToken() const {
|
||||
return oauthToken_;
|
||||
}
|
||||
const std::string& OAuthToken::oauthTokenSecret() const {
|
||||
return oauthTokenSecret_;
|
||||
}
|
||||
void OAuthToken::oauthToken(const std::string& _oauthToken) {
|
||||
oauthToken_ = _oauthToken;
|
||||
}
|
||||
void OAuthToken::oauthTokenSecret(const std::string& _oauthTokenSecret) {
|
||||
oauthTokenSecret_ = _oauthTokenSecret;
|
||||
}
|
||||
} // namespace CocoaTweet::API::Model
|
||||
@@ -1,20 +1,20 @@
|
||||
#ifndef COCOATWEET_API_MODEL_OAUTHTOKEN_H_
|
||||
#define COCOATWEET_API_MODEL_OAUTHTOKEN_H_
|
||||
#include<string>
|
||||
#include <string>
|
||||
|
||||
namespace CocoaTweet::API::Model{
|
||||
class OAuthToken{
|
||||
std::string oauthToken_;
|
||||
std::string oauthTokenSecret_;
|
||||
namespace CocoaTweet::API::Model {
|
||||
class OAuthToken {
|
||||
std::string oauthToken_;
|
||||
std::string oauthTokenSecret_;
|
||||
|
||||
public:
|
||||
OAuthToken();
|
||||
OAuthToken(const std::string _oauthToken, const std::string& _oauthTokenSecret);
|
||||
const std::string& oauthToken() const;
|
||||
const std::string& oauthTokenSecret() const;
|
||||
void oauthToken(const std::string& _oauthToken);
|
||||
void oauthTokenSecret(const std::string& _oauthTokenSecret);
|
||||
};
|
||||
}
|
||||
public:
|
||||
OAuthToken();
|
||||
OAuthToken(const std::string _oauthToken, const std::string& _oauthTokenSecret);
|
||||
const std::string& oauthToken() const;
|
||||
const std::string& oauthTokenSecret() const;
|
||||
void oauthToken(const std::string& _oauthToken);
|
||||
void oauthTokenSecret(const std::string& _oauthTokenSecret);
|
||||
};
|
||||
} // namespace CocoaTweet::API::Model
|
||||
|
||||
#endif
|
||||
@@ -2,32 +2,33 @@
|
||||
#include <cocoatweet/util/util.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace CocoaTweet::API::OAuth1{
|
||||
AccessToken::AccessToken(){
|
||||
contentType_ = "application/x-www-form-urlencoded";
|
||||
url_ = "https://api.twitter.com/oauth/access_token";
|
||||
}
|
||||
namespace CocoaTweet::API::OAuth1 {
|
||||
AccessToken::AccessToken() {
|
||||
contentType_ = "application/x-www-form-urlencoded";
|
||||
url_ = "https://api.twitter.com/oauth/access_token";
|
||||
}
|
||||
|
||||
void AccessToken::oauthVerifier(const std::string& _verifier){
|
||||
bodyParam_.insert_or_assign("oauth_verifier", _verifier);
|
||||
}
|
||||
void AccessToken::oauthVerifier(const std::string& _verifier) {
|
||||
bodyParam_.insert_or_assign("oauth_verifier", _verifier);
|
||||
}
|
||||
|
||||
void AccessToken::oauthToken(const CocoaTweet::API::Model::OAuthToken _token){
|
||||
oauthToken_ = _token;
|
||||
}
|
||||
void AccessToken::oauthToken(const CocoaTweet::API::Model::OAuthToken _token) {
|
||||
oauthToken_ = _token;
|
||||
}
|
||||
|
||||
const CocoaTweet::API::Model::OAuthToken AccessToken::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth){
|
||||
CocoaTweet::API::Model::OAuthToken oauthToken;
|
||||
HttpPost::process(_oauth, [&oauthToken](const std::string& _rcv){
|
||||
auto mp = CocoaTweet::Util::parse(_rcv, '&', '=');
|
||||
if(mp.count("oauth_token")){
|
||||
oauthToken.oauthToken(mp.at("oauth_token"));
|
||||
}
|
||||
if(mp.count("oauth_token_secret")){
|
||||
oauthToken.oauthTokenSecret(mp.at("oauth_token_secret"));
|
||||
}
|
||||
std::cout << _rcv << std::endl;
|
||||
});
|
||||
return oauthToken;
|
||||
const CocoaTweet::API::Model::OAuthToken AccessToken::process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
CocoaTweet::API::Model::OAuthToken oauthToken;
|
||||
HttpPost::process(_oauth, [&oauthToken](const std::string& _rcv) {
|
||||
auto mp = CocoaTweet::Util::parse(_rcv, '&', '=');
|
||||
if (mp.count("oauth_token")) {
|
||||
oauthToken.oauthToken(mp.at("oauth_token"));
|
||||
}
|
||||
}
|
||||
if (mp.count("oauth_token_secret")) {
|
||||
oauthToken.oauthTokenSecret(mp.at("oauth_token_secret"));
|
||||
}
|
||||
std::cout << _rcv << std::endl;
|
||||
});
|
||||
return oauthToken;
|
||||
}
|
||||
} // namespace CocoaTweet::API::OAuth1
|
||||
@@ -3,18 +3,20 @@
|
||||
|
||||
#include <cocoatweet/api/interface/httpPost.h>
|
||||
#include <cocoatweet/api/model/oauthToken.h>
|
||||
namespace CocoaTweet::API::OAuth1{
|
||||
class AccessToken: public CocoaTweet::API::Interface::HttpPost {
|
||||
namespace CocoaTweet::API::OAuth1 {
|
||||
class AccessToken : public CocoaTweet::API::Interface::HttpPost {
|
||||
private:
|
||||
CocoaTweet::API::Model::OAuthToken oauthToken_;
|
||||
CocoaTweet::API::Model::OAuthToken oauthToken_;
|
||||
|
||||
public:
|
||||
AccessToken();
|
||||
AccessToken();
|
||||
|
||||
void oauthVerifier(const std::string& _verifier);
|
||||
void oauthToken(const CocoaTweet::API::Model::OAuthToken _token);
|
||||
void oauthVerifier(const std::string& _verifier);
|
||||
void oauthToken(const CocoaTweet::API::Model::OAuthToken _token);
|
||||
|
||||
const CocoaTweet::API::Model::OAuthToken process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) ;
|
||||
};
|
||||
}
|
||||
const CocoaTweet::API::Model::OAuthToken process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
} // namespace CocoaTweet::API::OAuth1
|
||||
|
||||
#endif
|
||||
@@ -3,31 +3,33 @@
|
||||
#include <iostream>
|
||||
#include <cocoatweet/util/util.h>
|
||||
|
||||
namespace CocoaTweet::API::OAuth1{
|
||||
Authorize::Authorize(){
|
||||
contentType_ = "application/x-www-form-urlencoded";
|
||||
url_ = "https://api.twitter.com/oauth/authorize";
|
||||
}
|
||||
namespace CocoaTweet::API::OAuth1 {
|
||||
Authorize::Authorize() {
|
||||
contentType_ = "application/x-www-form-urlencoded";
|
||||
url_ = "https://api.twitter.com/oauth/authorize";
|
||||
}
|
||||
|
||||
void Authorize::oauthToken(const std::string& _oauthToken){
|
||||
bodyParam_.insert_or_assign("oauth_token", _oauthToken);
|
||||
}
|
||||
void Authorize::oauthToken(const std::string& _oauthToken) {
|
||||
bodyParam_.insert_or_assign("oauth_token", _oauthToken);
|
||||
}
|
||||
|
||||
void Authorize::forceLogin(const bool _forceLogin){
|
||||
bodyParam_.insert_or_assign("force_login", std::to_string(static_cast<int>(_forceLogin)));
|
||||
}
|
||||
void Authorize::forceLogin(const bool _forceLogin) {
|
||||
bodyParam_.insert_or_assign("force_login", std::to_string(static_cast<int>(_forceLogin)));
|
||||
}
|
||||
|
||||
void Authorize::screenName(const std::string& _screenName){
|
||||
bodyParam_.insert_or_assign("screen_name", _screenName);
|
||||
}
|
||||
void Authorize::screenName(const std::string& _screenName) {
|
||||
bodyParam_.insert_or_assign("screen_name", _screenName);
|
||||
}
|
||||
|
||||
const std::string Authorize::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> __unused__) {
|
||||
std::vector<std::string> tmp;
|
||||
std::string query = "";
|
||||
for (const auto& [key, value] : bodyParam_) {
|
||||
tmp.push_back(key + "=" + value);
|
||||
query = CocoaTweet::Util::join(tmp, "&");
|
||||
}
|
||||
return url_ + "?" + query;;
|
||||
}
|
||||
}
|
||||
const std::string Authorize::process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> __unused__) {
|
||||
std::vector<std::string> tmp;
|
||||
std::string query = "";
|
||||
for (const auto& [key, value] : bodyParam_) {
|
||||
tmp.push_back(key + "=" + value);
|
||||
query = CocoaTweet::Util::join(tmp, "&");
|
||||
}
|
||||
return url_ + "?" + query;
|
||||
;
|
||||
}
|
||||
} // namespace CocoaTweet::API::OAuth1
|
||||
@@ -2,19 +2,20 @@
|
||||
#define COCOATWEET_API_OAUTH1_AUTHORIZE_H
|
||||
|
||||
#include <cocoatweet/api/interface/httpPost.h>
|
||||
namespace CocoaTweet::API::OAuth1{
|
||||
class Authorize: public CocoaTweet::API::Interface::HttpPost {
|
||||
namespace CocoaTweet::API::OAuth1 {
|
||||
class Authorize : public CocoaTweet::API::Interface::HttpPost {
|
||||
public:
|
||||
Authorize();
|
||||
Authorize();
|
||||
|
||||
void oauthToken(const std::string& _oauthToken);
|
||||
void oauthToken(const std::string& _oauthToken);
|
||||
|
||||
void forceLogin(const bool _forceLogin);
|
||||
void forceLogin(const bool _forceLogin);
|
||||
|
||||
void screenName(const std::string& _screenName);
|
||||
void screenName(const std::string& _screenName);
|
||||
|
||||
const std::string process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> __unused__) ;
|
||||
};
|
||||
}
|
||||
const std::string process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> __unused__);
|
||||
};
|
||||
} // namespace CocoaTweet::API::OAuth1
|
||||
|
||||
#endif
|
||||
@@ -2,34 +2,36 @@
|
||||
#include <cocoatweet/authentication/authenticate.h>
|
||||
|
||||
namespace CocoaTweet::API::OAuth1 {
|
||||
OAuth::OAuth(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth){
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
OAuth::OAuth(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
|
||||
CocoaTweet::API::Model::OAuthToken OAuth::requestToken(const std::string& _oauthCallback) const{
|
||||
auto key = oauth_.lock()->key();
|
||||
key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A);
|
||||
auto oauth = std::make_shared<CocoaTweet::Authentication::OAuth1>(key);
|
||||
CocoaTweet::API::Model::OAuthToken OAuth::requestToken(
|
||||
const std::string& _oauthCallback) const {
|
||||
auto key = oauth_.lock()->key();
|
||||
key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A);
|
||||
auto oauth = std::make_shared<CocoaTweet::Authentication::OAuth1>(key);
|
||||
|
||||
CocoaTweet::API::OAuth1::RequestToken requestToken;
|
||||
requestToken.oauthCallback(_oauthCallback);
|
||||
return requestToken.process(oauth);
|
||||
}
|
||||
CocoaTweet::API::OAuth1::RequestToken requestToken;
|
||||
requestToken.oauthCallback(_oauthCallback);
|
||||
return requestToken.process(oauth);
|
||||
}
|
||||
|
||||
const std::string OAuth::authorize(const CocoaTweet::API::Model::OAuthToken _oauthToken) const{
|
||||
CocoaTweet::API::OAuth1::Authorize authorize;
|
||||
authorize.oauthToken(_oauthToken.oauthToken());
|
||||
return authorize.process(oauth_);
|
||||
}
|
||||
const std::string OAuth::authorize(const CocoaTweet::API::Model::OAuthToken _oauthToken) const {
|
||||
CocoaTweet::API::OAuth1::Authorize authorize;
|
||||
authorize.oauthToken(_oauthToken.oauthToken());
|
||||
return authorize.process(oauth_);
|
||||
}
|
||||
|
||||
const CocoaTweet::API::Model::OAuthToken OAuth::accessToken(const CocoaTweet::API::Model::OAuthToken _oauthToken, const std::string _verifier) const{
|
||||
auto key = oauth_.lock()->key();
|
||||
key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A);
|
||||
key.accessToken(_oauthToken.oauthToken());
|
||||
key.accessTokenSecret(_oauthToken.oauthTokenSecret());
|
||||
auto oauth = std::make_shared<CocoaTweet::Authentication::OAuth1>(key);
|
||||
CocoaTweet::API::OAuth1::AccessToken accessToken;
|
||||
accessToken.oauthVerifier(_verifier);
|
||||
return accessToken.process(oauth);
|
||||
}
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
const CocoaTweet::API::Model::OAuthToken OAuth::accessToken(
|
||||
const CocoaTweet::API::Model::OAuthToken _oauthToken, const std::string _verifier) const {
|
||||
auto key = oauth_.lock()->key();
|
||||
key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A);
|
||||
key.accessToken(_oauthToken.oauthToken());
|
||||
key.accessTokenSecret(_oauthToken.oauthTokenSecret());
|
||||
auto oauth = std::make_shared<CocoaTweet::Authentication::OAuth1>(key);
|
||||
CocoaTweet::API::OAuth1::AccessToken accessToken;
|
||||
accessToken.oauthVerifier(_verifier);
|
||||
return accessToken.process(oauth);
|
||||
}
|
||||
} // namespace CocoaTweet::API::OAuth1
|
||||
|
||||
@@ -15,16 +15,17 @@ class OAuth : public groupInterface {
|
||||
public:
|
||||
/// @brief primary constructor
|
||||
OAuth() = default;
|
||||
|
||||
|
||||
/// @brief constructor which finally should to be called.
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> : pointer to OAuth object
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> : pointer to
|
||||
/// OAuth object
|
||||
OAuth(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
CocoaTweet::API::Model::OAuthToken requestToken(const std::string& _oauthCallback) const;
|
||||
const std::string authorize(const CocoaTweet::API::Model::OAuthToken _oauthToken) const;
|
||||
const CocoaTweet::API::Model::OAuthToken accessToken(const CocoaTweet::API::Model::OAuthToken _oauthToken, const std::string _verifier) const;
|
||||
|
||||
const CocoaTweet::API::Model::OAuthToken accessToken(
|
||||
const CocoaTweet::API::Model::OAuthToken _oauthToken, const std::string _verifier) const;
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
} // namespace CocoaTweet::API::OAuth1
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,28 +2,29 @@
|
||||
#include <cocoatweet/util/util.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace CocoaTweet::API::OAuth1{
|
||||
RequestToken::RequestToken(){
|
||||
contentType_ = "application/x-www-form-urlencoded";
|
||||
url_ = "https://api.twitter.com/oauth/request_token";
|
||||
}
|
||||
namespace CocoaTweet::API::OAuth1 {
|
||||
RequestToken::RequestToken() {
|
||||
contentType_ = "application/x-www-form-urlencoded";
|
||||
url_ = "https://api.twitter.com/oauth/request_token";
|
||||
}
|
||||
|
||||
void RequestToken::oauthCallback(const std::string& _oauthCallback){
|
||||
bodyParam_.insert_or_assign("oauth_callback", _oauthCallback);
|
||||
}
|
||||
void RequestToken::oauthCallback(const std::string& _oauthCallback) {
|
||||
bodyParam_.insert_or_assign("oauth_callback", _oauthCallback);
|
||||
}
|
||||
|
||||
CocoaTweet::API::Model::OAuthToken RequestToken::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth){
|
||||
CocoaTweet::API::Model::OAuthToken oauthToken;
|
||||
HttpPost::process(_oauth, [&oauthToken](const std::string& _rcv){
|
||||
auto mp = CocoaTweet::Util::parse(_rcv, '&', '=');
|
||||
if(mp.count("oauth_token")){
|
||||
oauthToken.oauthToken(mp.at("oauth_token"));
|
||||
}
|
||||
if(mp.count("oauth_token_secret")){
|
||||
oauthToken.oauthTokenSecret(mp.at("oauth_token_secret"));
|
||||
}
|
||||
std::cout << _rcv << std::endl;
|
||||
});
|
||||
return oauthToken;
|
||||
CocoaTweet::API::Model::OAuthToken RequestToken::process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
CocoaTweet::API::Model::OAuthToken oauthToken;
|
||||
HttpPost::process(_oauth, [&oauthToken](const std::string& _rcv) {
|
||||
auto mp = CocoaTweet::Util::parse(_rcv, '&', '=');
|
||||
if (mp.count("oauth_token")) {
|
||||
oauthToken.oauthToken(mp.at("oauth_token"));
|
||||
}
|
||||
}
|
||||
if (mp.count("oauth_token_secret")) {
|
||||
oauthToken.oauthTokenSecret(mp.at("oauth_token_secret"));
|
||||
}
|
||||
std::cout << _rcv << std::endl;
|
||||
});
|
||||
return oauthToken;
|
||||
}
|
||||
} // namespace CocoaTweet::API::OAuth1
|
||||
@@ -4,14 +4,15 @@
|
||||
#include <cocoatweet/api/interface/httpPost.h>
|
||||
#include <cocoatweet/api/model/oauthToken.h>
|
||||
|
||||
namespace CocoaTweet::API::OAuth1{
|
||||
class RequestToken: public CocoaTweet::API::Interface::HttpPost {
|
||||
public:
|
||||
RequestToken();
|
||||
void oauthCallback(const std::string& _oauthCallback);
|
||||
namespace CocoaTweet::API::OAuth1 {
|
||||
class RequestToken : public CocoaTweet::API::Interface::HttpPost {
|
||||
public:
|
||||
RequestToken();
|
||||
void oauthCallback(const std::string& _oauthCallback);
|
||||
|
||||
CocoaTweet::API::Model::OAuthToken process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
}
|
||||
CocoaTweet::API::Model::OAuthToken process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
} // namespace CocoaTweet::API::OAuth1
|
||||
|
||||
#endif
|
||||
@@ -2,15 +2,15 @@
|
||||
#include <cocoatweet/authentication/basic.h>
|
||||
|
||||
namespace CocoaTweet::API::OAuth2 {
|
||||
OAuth2::OAuth2(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth){
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
OAuth2::OAuth2(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
|
||||
const std::string OAuth2::token() const{
|
||||
auto key = oauth_.lock()->key();
|
||||
auto oauth = std::make_shared<CocoaTweet::Authentication::Basic>(key);
|
||||
const std::string OAuth2::token() const {
|
||||
auto key = oauth_.lock()->key();
|
||||
auto oauth = std::make_shared<CocoaTweet::Authentication::Basic>(key);
|
||||
|
||||
CocoaTweet::API::OAuth2::Token token;
|
||||
return token.process(oauth);
|
||||
}
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
CocoaTweet::API::OAuth2::Token token;
|
||||
return token.process(oauth);
|
||||
}
|
||||
} // namespace CocoaTweet::API::OAuth2
|
||||
|
||||
@@ -13,14 +13,14 @@ class OAuth2 : public groupInterface {
|
||||
public:
|
||||
/// @brief primary constructor
|
||||
OAuth2() = default;
|
||||
|
||||
|
||||
/// @brief constructor which finally should to be called.
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> : pointer to OAuth object
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> : pointer to
|
||||
/// OAuth object
|
||||
OAuth2(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
const std::string token() const;
|
||||
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
} // namespace CocoaTweet::API::OAuth2
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
#include <cocoatweet/api/oauth2/token.h>
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
namespace CocoaTweet::API::OAuth2 {
|
||||
Token::Token() {
|
||||
contentType_ = "application/x-www-form-urlencoded";
|
||||
url_ = "https://api.twitter.com/oauth2/token";
|
||||
|
||||
namespace CocoaTweet::API::OAuth2{
|
||||
Token::Token(){
|
||||
contentType_ = "application/x-www-form-urlencoded";
|
||||
url_ = "https://api.twitter.com/oauth2/token";
|
||||
bodyParam_.insert_or_assign("grant_type", "client_credentials");
|
||||
}
|
||||
|
||||
bodyParam_.insert_or_assign("grant_type", "client_credentials");
|
||||
}
|
||||
|
||||
|
||||
|
||||
const std::string Token::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
const std::string Token::process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
auto basic = std::make_shared<CocoaTweet::Authentication::Basic>(_oauth.lock()->key());
|
||||
std::string bearer = "";
|
||||
HttpPost::process(basic, [&bearer](const std::string& _rcv) {
|
||||
@@ -22,4 +20,4 @@ const std::string Token::process(std::weak_ptr<CocoaTweet::Authentication::Authe
|
||||
return bearer;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace CocoaTweet::API::OAuth2
|
||||
@@ -4,12 +4,13 @@
|
||||
#include <cocoatweet/api/interface/httpPost.h>
|
||||
#include <cocoatweet/authentication/basic.h>
|
||||
|
||||
namespace CocoaTweet::API::OAuth2{
|
||||
class Token: public CocoaTweet::API::Interface::HttpPost{
|
||||
public:
|
||||
Token();
|
||||
const std::string process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
}
|
||||
namespace CocoaTweet::API::OAuth2 {
|
||||
class Token : public CocoaTweet::API::Interface::HttpPost {
|
||||
public:
|
||||
Token();
|
||||
const std::string process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
} // namespace CocoaTweet::API::OAuth2
|
||||
|
||||
#endif
|
||||
@@ -18,9 +18,11 @@ public:
|
||||
void id(const std::string _id);
|
||||
|
||||
/// @brief process request for endpoint
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer to oauth object
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer
|
||||
/// to oauth object
|
||||
/// @param[out] CocoaTweet::API::Model::Tweet : request result
|
||||
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
CocoaTweet::API::Model::Tweet process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@ public:
|
||||
|
||||
void id(const std::string& _id);
|
||||
|
||||
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
CocoaTweet::API::Model::Tweet process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@ public:
|
||||
Status() = default;
|
||||
|
||||
/// @brief constructor which finally should to be called.
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> : pointer to OAuth object
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> : pointer to
|
||||
/// OAuth object
|
||||
Status(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
/// @brief send request to statuses/update with specified status
|
||||
|
||||
@@ -11,7 +11,8 @@ public:
|
||||
|
||||
void id(const std::string& _id);
|
||||
|
||||
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
CocoaTweet::API::Model::Tweet process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
|
||||
|
||||
@@ -53,7 +53,8 @@ void Update::failDMCommands(bool _fail) {
|
||||
bodyParam_.insert_or_assign("fail_dmcommands", std::to_string(_fail));
|
||||
}
|
||||
|
||||
CocoaTweet::API::Model::Tweet Update::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
CocoaTweet::API::Model::Tweet Update::process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
CocoaTweet::API::Model::Tweet tweet;
|
||||
HttpPost::process(_oauth, [&tweet](const std::string& _rcv) {
|
||||
tweet = CocoaTweet::API::Model::Tweet::parse(_rcv);
|
||||
|
||||
@@ -40,9 +40,11 @@ public:
|
||||
void failDMCommands(bool _fail);
|
||||
|
||||
/// @brief process request for endpoint
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer to oauth object
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer
|
||||
/// to oauth object
|
||||
/// @param[out] CocoaTweet::API::Model::Tweet : request result
|
||||
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
CocoaTweet::API::Model::Tweet process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
private:
|
||||
std::string status_;
|
||||
|
||||
@@ -19,7 +19,8 @@ public:
|
||||
void screenName(const std::string& _screenName);
|
||||
|
||||
/// @brief process request for endpoint
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer to oauth object
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer
|
||||
/// to oauth object
|
||||
/// @param[out] std::vector<CocoaTweet::API::Model::Tweet> : request result
|
||||
std::vector<CocoaTweet::API::Model::Tweet> process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
@@ -9,14 +9,14 @@ Show::Show() {
|
||||
}
|
||||
|
||||
void Show::screenName(const std::string& _screenName) {
|
||||
if(bodyParam_.count("user_id") > 0){
|
||||
if (bodyParam_.count("user_id") > 0) {
|
||||
bodyParam_.erase("user_id");
|
||||
}
|
||||
bodyParam_.insert_or_assign("screen_name", _screenName);
|
||||
}
|
||||
|
||||
void Show::id(const std::string& _id) {
|
||||
if(bodyParam_.count("screen_name") > 0){
|
||||
if (bodyParam_.count("screen_name") > 0) {
|
||||
bodyParam_.erase("screen_name");
|
||||
}
|
||||
bodyParam_.insert_or_assign("id", _id);
|
||||
@@ -31,4 +31,4 @@ CocoaTweet::API::Model::User Show::process(
|
||||
return user;
|
||||
}
|
||||
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
} // namespace CocoaTweet::API::Users
|
||||
|
||||
@@ -23,7 +23,8 @@ public:
|
||||
void screenName(const std::string& _screenName);
|
||||
|
||||
/// @brief process request for endpoint
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer to oauth object
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer
|
||||
/// to oauth object
|
||||
/// @param[out] CocoaTweet::API::Model::User : request result
|
||||
CocoaTweet::API::Model::User process(
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
@@ -31,6 +32,6 @@ public:
|
||||
private:
|
||||
std::string status_;
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
} // namespace CocoaTweet::API::Users
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include <cocoatweet/api/user/user.h>
|
||||
#include <cocoatweet/api/user/show.h>
|
||||
|
||||
namespace CocoaTweet::API::Users{
|
||||
User::User(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
namespace CocoaTweet::API::Users {
|
||||
User::User(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
|
||||
CocoaTweet::API::Model::User User::show(const std::string& _screenName)const{
|
||||
CocoaTweet::API::Users::Show show;
|
||||
show.screenName(_screenName);
|
||||
return show.process(oauth_);
|
||||
}
|
||||
}
|
||||
CocoaTweet::API::Model::User User::show(const std::string& _screenName) const {
|
||||
CocoaTweet::API::Users::Show show;
|
||||
show.screenName(_screenName);
|
||||
return show.process(oauth_);
|
||||
}
|
||||
} // namespace CocoaTweet::API::Users
|
||||
@@ -13,14 +13,14 @@ class User : public groupInterface {
|
||||
public:
|
||||
/// @brief primary constructor
|
||||
User() = default;
|
||||
|
||||
|
||||
/// @brief constructor which finally should to be called.
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> : pointer to OAuth object
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> : pointer to
|
||||
/// OAuth object
|
||||
User(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
CocoaTweet::API::Model::User show(const std::string& _screenName) const;
|
||||
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
} // namespace CocoaTweet::API::Users
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,8 +27,8 @@ OAuth1::OAuth1() {
|
||||
method_ = AuthenticationMethod::OAUTH10A;
|
||||
}
|
||||
|
||||
OAuth1::OAuth1(const Key _key){
|
||||
key_ = _key;
|
||||
OAuth1::OAuth1(const Key _key) {
|
||||
key_ = _key;
|
||||
method_ = AuthenticationMethod::OAUTH10A;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,6 @@ const std::string OAuth1::version() const {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
|
||||
std::map<std::string, std::string> OAuth1::oauthParam() const {
|
||||
auto tmp = std::map<std::string, std::string>{{"oauth_nonce", nonce()},
|
||||
{"oauth_signature_method", method()},
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <cocoatweet/authentication/authenticator.h>
|
||||
|
||||
namespace CocoaTweet::Authentication {
|
||||
class OAuth1: public AuthenticatorBase {
|
||||
class OAuth1 : public AuthenticatorBase {
|
||||
public:
|
||||
OAuth1();
|
||||
OAuth1(const Key _key);
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
const std::string& _url);
|
||||
|
||||
// const std::string& generateBearerToken();
|
||||
|
||||
|
||||
const std::string calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
||||
const std::string& _method, const std::string& _url);
|
||||
|
||||
@@ -28,7 +28,6 @@ public:
|
||||
std::map<std::string, std::string> oauthParam() const;
|
||||
std::string hmacSha1(std::string _key, std::string _data);
|
||||
const std::string base64(const std::string& _raw);
|
||||
|
||||
};
|
||||
} // namespace CocoaTweet::Authentication
|
||||
|
||||
|
||||
@@ -2,22 +2,17 @@
|
||||
#define COCOATWEET_AUTHENTICATION_AUTHENTICATORBASE_H
|
||||
|
||||
#include <cocoatweet/authentication/key.h>
|
||||
namespace CocoaTweet::Authentication{
|
||||
class AuthenticatorBase{
|
||||
namespace CocoaTweet::Authentication {
|
||||
class AuthenticatorBase {
|
||||
public:
|
||||
enum class AuthenticationMethod{
|
||||
OAUTH10A,
|
||||
OAUTH2,
|
||||
BASIC,
|
||||
PLAIN,
|
||||
NONE
|
||||
};
|
||||
|
||||
enum class AuthenticationMethod { OAUTH10A, OAUTH2, BASIC, PLAIN, NONE };
|
||||
|
||||
virtual const std::string calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
||||
const std::string& _method, const std::string& _url) = 0;
|
||||
|
||||
const Key key() const{
|
||||
return key_;
|
||||
const std::string& _method,
|
||||
const std::string& _url) = 0;
|
||||
|
||||
const Key key() const {
|
||||
return key_;
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -29,6 +24,6 @@ protected:
|
||||
return realsize;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace CocoaTweet::Authentication
|
||||
|
||||
#endif
|
||||
|
||||
@@ -27,20 +27,18 @@ Basic::Basic() {
|
||||
method_ = AuthenticationMethod::BASIC;
|
||||
}
|
||||
|
||||
Basic::Basic(const Key _key){
|
||||
key_ = _key;
|
||||
Basic::Basic(const Key _key) {
|
||||
key_ = _key;
|
||||
method_ = AuthenticationMethod::BASIC;
|
||||
}
|
||||
const std::string Basic::calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
||||
const std::string& _method,
|
||||
const std::string& _url) {
|
||||
|
||||
const std::string& _method,
|
||||
const std::string& _url) {
|
||||
auto signature = key_.consumerKey() + ":" + key_.consumerSecret();
|
||||
auto k64Signature = base64(signature);
|
||||
auto authHeader = std::string("Authorization: Basic ") + k64Signature;
|
||||
|
||||
return authHeader;
|
||||
|
||||
}
|
||||
|
||||
const std::string Basic::base64(const std::string& _raw) {
|
||||
@@ -73,5 +71,4 @@ const std::string Basic::base64(const std::string& _raw) {
|
||||
return base64;
|
||||
}
|
||||
|
||||
|
||||
} // namespace CocoaTweet::Authentication
|
||||
|
||||
@@ -8,17 +8,16 @@
|
||||
#include <cocoatweet/authentication/authenticator.h>
|
||||
|
||||
namespace CocoaTweet::Authentication {
|
||||
class Basic: public AuthenticatorBase {
|
||||
class Basic : public AuthenticatorBase {
|
||||
public:
|
||||
Basic();
|
||||
Basic(const Key _key);
|
||||
|
||||
// const std::string& generateBearerToken();
|
||||
|
||||
|
||||
const std::string calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
||||
const std::string& _method, const std::string& _url);
|
||||
const std::string base64(const std::string& _raw);
|
||||
|
||||
};
|
||||
} // namespace CocoaTweet::Authentication
|
||||
|
||||
|
||||
@@ -27,18 +27,16 @@ Bearer::Bearer() {
|
||||
method_ = AuthenticationMethod::OAUTH2;
|
||||
}
|
||||
|
||||
Bearer::Bearer(const Key _key){
|
||||
key_ = _key;
|
||||
Bearer::Bearer(const Key _key) {
|
||||
key_ = _key;
|
||||
method_ = AuthenticationMethod::OAUTH2;
|
||||
}
|
||||
const std::string Bearer::calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
||||
const std::string& _method,
|
||||
const std::string& _url) {
|
||||
|
||||
auto authHeader = std::string("Authorization: Bearer ") + key_.bearerToken();
|
||||
auto authHeader = std::string("Authorization: Bearer ") + key_.bearerToken();
|
||||
|
||||
return authHeader;
|
||||
|
||||
}
|
||||
|
||||
} // namespace CocoaTweet::Authentication
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
#include <cocoatweet/authentication/authenticator.h>
|
||||
|
||||
namespace CocoaTweet::Authentication {
|
||||
class Bearer: public AuthenticatorBase {
|
||||
class Bearer : public AuthenticatorBase {
|
||||
public:
|
||||
Bearer();
|
||||
Bearer(const Key _key);
|
||||
|
||||
|
||||
const std::string calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
||||
const std::string& _method, const std::string& _url);
|
||||
};
|
||||
|
||||
@@ -7,10 +7,7 @@
|
||||
namespace CocoaTweet::Authentication {
|
||||
class Key {
|
||||
public:
|
||||
enum AUTH_TYPE{
|
||||
OAUTH10A,
|
||||
OAUTH2
|
||||
};
|
||||
enum AUTH_TYPE { OAUTH10A, OAUTH2 };
|
||||
|
||||
private:
|
||||
std::string consumerKey_;
|
||||
@@ -18,17 +15,21 @@ private:
|
||||
std::string accessToken_;
|
||||
std::string accessTokenSecret_;
|
||||
std::string bearerToken_;
|
||||
AUTH_TYPE authType_;
|
||||
AUTH_TYPE authType_;
|
||||
|
||||
public:
|
||||
Key() : consumerKey_(""), consumerSecret_(""), accessToken_(""), accessTokenSecret_("") {}
|
||||
Key(const std::string& _consumerKey, const std::string& _consumerSecret,
|
||||
const std::string& _accessToken, const std::string& _accessTokenSecret, const AUTH_TYPE _authType = AUTH_TYPE::OAUTH10A)
|
||||
const std::string& _accessToken, const std::string& _accessTokenSecret,
|
||||
const AUTH_TYPE _authType = AUTH_TYPE::OAUTH10A)
|
||||
: consumerKey_(_consumerKey),
|
||||
consumerSecret_(_consumerSecret),
|
||||
accessToken_(_accessToken),
|
||||
accessTokenSecret_(_accessTokenSecret), authType_(_authType) {}
|
||||
Key(const std::string& _consumerKey, const std::string& _consumerSecret, const AUTH_TYPE _authType = AUTH_TYPE::OAUTH2)
|
||||
: consumerKey_(_consumerKey), consumerSecret_(_consumerSecret), authType_(_authType){}
|
||||
accessTokenSecret_(_accessTokenSecret),
|
||||
authType_(_authType) {}
|
||||
Key(const std::string& _consumerKey, const std::string& _consumerSecret,
|
||||
const AUTH_TYPE _authType = AUTH_TYPE::OAUTH2)
|
||||
: consumerKey_(_consumerKey), consumerSecret_(_consumerSecret), authType_(_authType) {}
|
||||
|
||||
void consumerKey(const std::string& _consumerKey) {
|
||||
consumerKey_ = _consumerKey;
|
||||
|
||||
@@ -3,9 +3,8 @@
|
||||
|
||||
#include <cocoatweet/authentication/authenticator.h>
|
||||
|
||||
namespace CocoaTweet::Authentication{
|
||||
class Plain: public AuthenticatorBase {
|
||||
};
|
||||
}
|
||||
namespace CocoaTweet::Authentication {
|
||||
class Plain : public AuthenticatorBase {};
|
||||
} // namespace CocoaTweet::Authentication
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,18 +5,18 @@
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
namespace CocoaTweet::Authentication{
|
||||
class Auth: public groupInterface {
|
||||
namespace CocoaTweet::Authentication {
|
||||
class Auth : public groupInterface {
|
||||
public:
|
||||
enum AuthType { OAuth, Bearer };
|
||||
|
||||
Auth();
|
||||
Auth(Key _key);
|
||||
authorize(const bool app_only);
|
||||
|
||||
Auth();
|
||||
Auth(Key _key);
|
||||
authorize(const bool app_only);
|
||||
|
||||
private:
|
||||
Key key_;
|
||||
}
|
||||
Key key_;
|
||||
}
|
||||
} // namespace CocoaTweet::Authentication
|
||||
|
||||
#endif
|
||||
+24
-24
@@ -36,34 +36,34 @@ std::string join(const std::vector<std::string> _vec, const std::string& _delim)
|
||||
return str;
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::string> parse(const std::string str, const char _delim,
|
||||
const char _conn) {
|
||||
int first = 0;
|
||||
int last = str.find_first_of(_delim);
|
||||
std::vector<std::string> result;
|
||||
|
||||
std::unordered_map<std::string, std::string> parse(const std::string str, const char _delim, const char _conn){
|
||||
int first = 0;
|
||||
int last = str.find_first_of(_delim);
|
||||
std::vector<std::string> result;
|
||||
|
||||
while (first < str.size()) {
|
||||
result.push_back(str.substr(first, last - first));
|
||||
first = last + 1;
|
||||
last = str.find_first_of(_delim, first);
|
||||
if (last == std::string::npos) last = str.size();
|
||||
}
|
||||
while (first < str.size()) {
|
||||
result.push_back(str.substr(first, last - first));
|
||||
first = last + 1;
|
||||
last = str.find_first_of(_delim, first);
|
||||
if (last == std::string::npos) last = str.size();
|
||||
}
|
||||
|
||||
auto mp = std::unordered_map<std::string, std::string>();
|
||||
for(auto elm: result){
|
||||
int pos = elm.find_first_of(_conn);
|
||||
auto mp = std::unordered_map<std::string, std::string>();
|
||||
for (auto elm : result) {
|
||||
int pos = elm.find_first_of(_conn);
|
||||
|
||||
std::cout << pos << std::endl;
|
||||
if(pos == std::string::npos){
|
||||
mp.insert_or_assign(elm, "");
|
||||
}else{
|
||||
auto key = elm.substr(0, pos);
|
||||
auto val = elm.substr(pos + 1);
|
||||
mp.insert_or_assign(key, val);
|
||||
}
|
||||
}
|
||||
std::cout << pos << std::endl;
|
||||
if (pos == std::string::npos) {
|
||||
mp.insert_or_assign(elm, "");
|
||||
} else {
|
||||
auto key = elm.substr(0, pos);
|
||||
auto val = elm.substr(pos + 1);
|
||||
mp.insert_or_assign(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
return mp;
|
||||
return mp;
|
||||
}
|
||||
|
||||
} // namespace CocoaTweet::Util
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
namespace CocoaTweet::Util {
|
||||
std::string urlEncode(const std::string& _str);
|
||||
std::string join(const std::vector<std::string> _vec, const std::string& _delim);
|
||||
std::unordered_map<std::string, std::string> parse(const std::string str, const char _delim, const char _conn);
|
||||
std::unordered_map<std::string, std::string> parse(const std::string str, const char _delim,
|
||||
const char _conn);
|
||||
} // namespace CocoaTweet::Util
|
||||
|
||||
#endif
|
||||
|
||||
+35
-12
@@ -2,35 +2,58 @@
|
||||
#include <iostream>
|
||||
#include <cocoatweet/exception/exception.h>
|
||||
|
||||
#include <cocoatweet/api/oauth1/requestToken.h>
|
||||
#include <cocoatweet/api/oauth1/authorize.h>
|
||||
#include <cocoatweet/api/oauth1/accessToken.h>
|
||||
#include <cocoatweet/api/oauth2/token.h>
|
||||
#include <cocoatweet/authentication/authenticate.h>
|
||||
|
||||
auto main() -> int {
|
||||
// Generate Key object
|
||||
// auto consumerKey = "your consumer key";
|
||||
// auto consumerSecret = "your consumer secret";
|
||||
// auto accessToken = "your access token";
|
||||
// auto accessTokenSecret = "your access token secret";
|
||||
// CocoaTweet::OAuth::Key key = CocoaTweet::OAuth::Key(consumerKey,
|
||||
// CocoaTweet::Authentication::Key key = CocoaTweet::Authentication::Key(consumerKey,
|
||||
// consumerSecret,
|
||||
// accessToken,
|
||||
// accessTokenSecret);
|
||||
|
||||
// also can generate Key object from JSON file
|
||||
// CocoaTweet::OAuth::Key key = CocoaTweet::OAuth::Key::fromJsonFile("api_key.json");
|
||||
try {
|
||||
// also can generate Key object from JSON file
|
||||
CocoaTweet::Authentication::Key key =
|
||||
CocoaTweet::Authentication::Key::fromJsonFile("api_key.json");
|
||||
std::shared_ptr<CocoaTweet::Authentication::OAuth1> oauth =
|
||||
std::make_shared<CocoaTweet::Authentication::OAuth1>(key);
|
||||
|
||||
// Generate API Entry object using Key object
|
||||
// CocoaTweet::API::API api(key);
|
||||
// Generate API Entry object using Key object
|
||||
CocoaTweet::API::API api(key);
|
||||
auto bearerToken = api.oauth2().token();
|
||||
key.bearerToken(bearerToken);
|
||||
key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH2);
|
||||
api.swapKey(key);
|
||||
|
||||
// if you want to access api using Bearer Token, call this for get BearerToken;
|
||||
// NOTE: call this, always authenticate with Bearer Token, which is Read Only Token
|
||||
// try {
|
||||
auto user = api.user().show("milkcocoa9692");
|
||||
std::cout << user.id() << std::endl;
|
||||
// api.directMessage().messageCreate(
|
||||
// user.id(),
|
||||
// "これはクソみたいなスパムDMです。\nCocoaTwitterLibraryで、user/"
|
||||
// "showが叩けるようになったので、外部サービスでuser_idを調べずともscreen_"
|
||||
// "nameで引っ張ってきてクソDMを投げられるようになりました👏\nその記念にAPIから発砲🔫←センス最"
|
||||
// "悪\nhttps://github.com/koron0902/CocoaTweet");
|
||||
// if you want to access api using Bearer Token, call this for get BearerToken;
|
||||
// NOTE: call this, always authenticate with Bearer Token, which is Read Only Token
|
||||
// try {
|
||||
// api.generateBearerToken();
|
||||
|
||||
// Now, you can use a twitter api
|
||||
// auto status = api.status().update("Hello Twitter World via Cocoa Twitter Library");
|
||||
auto status = api.status().update("Hello Twitter World via Cocoa Twitter Library!!");
|
||||
// std::cout << status.id() << std::endl;
|
||||
// api.favorite().create(status.id());
|
||||
// api.favorite().destroy(status.id());
|
||||
// api.status().destroy(status.id());
|
||||
// auto timeline = api.status().userTimeline("milkcocoa0902");
|
||||
// } catch (CocoaTweet::Exception::Exception e) {
|
||||
// std::cout << e.what() << std::endl;
|
||||
// }
|
||||
} catch (CocoaTweet::Exception::Exception e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ BOOST_AUTO_TEST_CASE(test01) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test02) {
|
||||
CocoaTweet::Authentication::Key key("consumerKey", "consumerSecret", "accessToken",
|
||||
"accessTokenSecret");
|
||||
"accessTokenSecret");
|
||||
|
||||
BOOST_TEST(key.consumerKey() == "consumerKey");
|
||||
BOOST_TEST(key.consumerSecret() == "consumerSecret");
|
||||
|
||||
Reference in New Issue
Block a user