access tokenが取得できるように
This commit is contained in:
@@ -1,18 +1,31 @@
|
||||
#include <cocoatweet/api/api.h>
|
||||
#include <cocoatweet/authentication/authenticate.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace CocoaTweet::API {
|
||||
API::API(CocoaTweet::OAuth::Key _key) {
|
||||
oauth_ = std::make_shared<CocoaTweet::OAuth::OAuth1>(_key);
|
||||
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{
|
||||
|
||||
}
|
||||
user_ = Users::User(oauth_);
|
||||
status_ = Statuses::Status(oauth_);
|
||||
favorite_ = Favorites::Favorite(oauth_);
|
||||
media_ = Medias::Media(oauth_);
|
||||
directMessage_ = DirectMessages::DirectMessage(oauth_);
|
||||
oauth1_ = OAuth1::OAuth(oauth_);
|
||||
}
|
||||
|
||||
const std::string& API::generateBearerToken() const {
|
||||
return oauth_->generateBearerToken();
|
||||
}
|
||||
// const std::string& API::generateBearerToken() const {
|
||||
// return oauth_->generateBearerToken();
|
||||
// }
|
||||
|
||||
Users::User API::user() const {
|
||||
return user_;
|
||||
@@ -33,4 +46,7 @@ Medias::Media API::media() const {
|
||||
DirectMessages::DirectMessage API::directMessage() const {
|
||||
return directMessage_;
|
||||
}
|
||||
OAuth1::OAuth API::oauth1() const {
|
||||
return oauth1_;
|
||||
}
|
||||
} // namespace CocoaTweet::API
|
||||
|
||||
@@ -6,15 +6,16 @@
|
||||
#include <cocoatweet/api/favorite/favorite.h>
|
||||
#include <cocoatweet/api/media/media.h>
|
||||
#include <cocoatweet/api/directMessage/directMessage.h>
|
||||
#include <cocoatweet/oauth/oauth.h>
|
||||
#include <cocoatweet/authentication/authenticator.h>
|
||||
#include <cocoatweet/api/oauth1/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);
|
||||
/// @param[in] _key Twitter API Key typed CocoaTweet::Authentication::Key
|
||||
API(CocoaTweet::Authentication::Key _key);
|
||||
|
||||
Users::User user() const;
|
||||
|
||||
@@ -29,7 +30,11 @@ public:
|
||||
Medias::Media media() const;
|
||||
|
||||
DirectMessages::DirectMessage directMessage() const;
|
||||
|
||||
OAuth1::OAuth oauth1() const;
|
||||
|
||||
const std::string& generateBearerToken() const;
|
||||
void swapKey(const CocoaTweet::Authentication::Key _key);
|
||||
|
||||
private:
|
||||
Users::User user_;
|
||||
@@ -37,7 +42,8 @@ private:
|
||||
Favorites::Favorite favorite_;
|
||||
Medias::Media media_;
|
||||
DirectMessages::DirectMessage directMessage_;
|
||||
std::shared_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
||||
OAuth1::OAuth oauth1_;
|
||||
std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> oauth_;
|
||||
};
|
||||
} // namespace CocoaTweet::API
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <cocoatweet/api/directMessage/new.h>
|
||||
|
||||
namespace CocoaTweet::API::DirectMessages {
|
||||
DirectMessage::DirectMessage(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
DirectMessage::DirectMessage(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define COCOATWEET_API_DIRECTMESSAGE_DIRECTMESSAGE_H_
|
||||
|
||||
#include "cocoatweet/api/interface/groupInterface.h"
|
||||
#include "cocoatweet/oauth/oauth.h"
|
||||
#include "cocoatweet/authentication/authenticator.h"
|
||||
#include <cocoatweet/api/model/tweet.h>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
@@ -15,8 +15,8 @@ public:
|
||||
DirectMessage() = default;
|
||||
|
||||
/// @brief constructor which finally should to be called.
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::OAuth::OAuth1> : pointer to OAuth object
|
||||
DirectMessage(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||
/// @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);
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ void New::message(const std::string& _message) {
|
||||
json_["event"]["message_create"]["message_data"]["text"] = _message;
|
||||
}
|
||||
|
||||
void New::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
void New::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
bodyParam_.insert_or_assign("data", json_.dump());
|
||||
HttpPost::process(_oauth, [](const std::string& _rcv) {});
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ public:
|
||||
void message(const std::string& _message);
|
||||
|
||||
/// @brief process request for endpoint
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _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::OAuth::OAuth1> _oauth);
|
||||
void process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
private:
|
||||
std::string status_;
|
||||
|
||||
@@ -11,7 +11,7 @@ void Create::id(const std::string& _id) {
|
||||
bodyParam_.insert_or_assign("id", _id);
|
||||
}
|
||||
|
||||
CocoaTweet::API::Model::Tweet Create::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _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,7 @@ class Create : public CocoaTweet::API::Interface::HttpPost {
|
||||
public:
|
||||
Create();
|
||||
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::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@ void Destroy::id(const std::string& _id) {
|
||||
}
|
||||
|
||||
CocoaTweet::API::Model::Tweet Destroy::process(
|
||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
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,7 @@ class Destroy : public CocoaTweet::API::Interface::HttpPost {
|
||||
public:
|
||||
Destroy();
|
||||
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::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "cocoatweet/api/favorite/destroy.h"
|
||||
|
||||
namespace CocoaTweet::API::Favorites {
|
||||
Favorite::Favorite(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
Favorite::Favorite(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
#define COCOATWEET_API_FAVORITE_FAVORITE_H_
|
||||
|
||||
#include "cocoatweet/api/interface/groupInterface.h"
|
||||
#include "cocoatweet/oauth/oauth.h"
|
||||
#include "cocoatweet/authentication/authenticator.h"
|
||||
#include <cocoatweet/api/model/tweet.h>
|
||||
|
||||
namespace CocoaTweet::API::Favorites {
|
||||
class Favorite : public groupInterface {
|
||||
public:
|
||||
Favorite() = default;
|
||||
Favorite(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||
Favorite(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
CocoaTweet::API::Model::Tweet create(const std::string& _id) const;
|
||||
CocoaTweet::API::Model::Tweet destroy(const std::string& _id) const;
|
||||
};
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
#define COCOATWEET_API_INTERFACE_GROUPINTERFACE_H_
|
||||
|
||||
#include <memory>
|
||||
#include "cocoatweet/oauth/oauth.h"
|
||||
#include "cocoatweet/authentication/authenticator.h"
|
||||
|
||||
namespace CocoaTweet::API {
|
||||
class groupInterface {
|
||||
protected:
|
||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> oauth_;
|
||||
};
|
||||
} // namespace CocoaTweet::API
|
||||
|
||||
|
||||
@@ -2,17 +2,18 @@
|
||||
#define COCOATWEET_API_INTERFACE_HTTPBASE_H_
|
||||
|
||||
#include <functional>
|
||||
#include "cocoatweet/oauth/oauth.h"
|
||||
#include <memory>
|
||||
#include "cocoatweet/authentication/authenticator.h"
|
||||
|
||||
namespace CocoaTweet::API::Interface {
|
||||
class HttpBase {
|
||||
public:
|
||||
protected:
|
||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> oauth_;
|
||||
std::map<std::string, std::string> bodyParam_;
|
||||
std::string url_;
|
||||
std::string contentType_;
|
||||
virtual void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||
virtual void process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth,
|
||||
std::function<void(const std::string&)> _callback) = 0;
|
||||
static size_t curlCallback_(char* _ptr, size_t _size, size_t _nmemb, std::string* _stream) {
|
||||
int realsize = _size * _nmemb;
|
||||
|
||||
@@ -21,7 +21,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
namespace CocoaTweet::API::Interface {
|
||||
void HttpGet::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||
void HttpGet::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth,
|
||||
std::function<void(const std::string&)> _callback) {
|
||||
auto url = url_;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define COCOATWEET_API_INTERFACE_HTTPGET_H_
|
||||
|
||||
#include <functional>
|
||||
#include "cocoatweet/oauth/oauth.h"
|
||||
#include "cocoatweet/authentication/authenticator.h"
|
||||
#include <cocoatweet/api/interface/httpBase.h>
|
||||
|
||||
namespace CocoaTweet::API::Interface {
|
||||
@@ -11,11 +11,11 @@ class HttpGet : public virtual HttpBase {
|
||||
public:
|
||||
protected:
|
||||
/// @brief Send HTTP/POST using OAuth object
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth : pointer to OAuth object to
|
||||
/// @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::OAuth::OAuth1> _oauth,
|
||||
void process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth,
|
||||
std::function<void(const std::string&)> _callback);
|
||||
};
|
||||
} // namespace CocoaTweet::API::Interface
|
||||
|
||||
@@ -21,22 +21,22 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
namespace CocoaTweet::API::Interface {
|
||||
void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||
void HttpPost::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth,
|
||||
std::function<void(const std::string&)> _callback) {
|
||||
// エンドポイントへのパラメータにOAuthパラメータを付加して署名作成
|
||||
auto oauth = _oauth.lock();
|
||||
auto oauthParam = oauth->oauthParam();
|
||||
auto sigingParam = oauthParam;
|
||||
if (contentType_ == "application/x-www-form-urlencoded") {
|
||||
for (const auto [k, v] : bodyParam_) {
|
||||
sigingParam.insert_or_assign(k, v);
|
||||
}
|
||||
}
|
||||
// auto oauthParam = oauth->oauthParam();
|
||||
// auto sigingParam = oauthParam;
|
||||
// if (contentType_ == "application/x-www-form-urlencoded") {
|
||||
// for (const auto [k, v] : bodyParam_) {
|
||||
// sigingParam.insert_or_assign(k, v);
|
||||
// }
|
||||
// }
|
||||
|
||||
auto signature = oauth->signature(sigingParam, "POST", url_);
|
||||
// auto signature = oauth->signature(sigingParam, "POST", url_);
|
||||
|
||||
// 作成した署名をエンドポイントへのパラメータ及びOAuthパラメータに登録
|
||||
oauthParam.merge(signature);
|
||||
// oauthParam.merge(signature);
|
||||
|
||||
// リクエストボディの構築
|
||||
std::string requestBody = "";
|
||||
@@ -60,13 +60,21 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||
}
|
||||
|
||||
// ヘッダの構築
|
||||
std::string oauthHeader = "authorization: OAuth ";
|
||||
{
|
||||
std::vector<std::string> tmp;
|
||||
for (const auto& [key, value] : oauthParam) {
|
||||
tmp.push_back(key + "=" + CocoaTweet::Util::urlEncode(value));
|
||||
}
|
||||
oauthHeader += CocoaTweet::Util::join(tmp, ",");
|
||||
// std::string oauthHeader = "authorization: OAuth ";
|
||||
// {
|
||||
// std::vector<std::string> tmp;
|
||||
// for (const auto& [key, value] : oauthParam) {
|
||||
// tmp.push_back(key + "=" + CocoaTweet::Util::urlEncode(value));
|
||||
// }
|
||||
// oauthHeader += CocoaTweet::Util::join(tmp, ",");
|
||||
// }
|
||||
|
||||
|
||||
auto oauthHeader = std::string();
|
||||
if (contentType_ == "application/x-www-form-urlencoded") {
|
||||
oauthHeader = oauth->calculateAuthHeader(bodyParam_, "POST", url_);
|
||||
} else {
|
||||
oauthHeader = oauth->calculateAuthHeader({}, "POST", url_);
|
||||
}
|
||||
|
||||
// do post
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define COCOATWEET_API_INTERFACE_HTTPPOST_H_
|
||||
|
||||
#include <functional>
|
||||
#include "cocoatweet/oauth/oauth.h"
|
||||
#include "cocoatweet/authentication/authenticator.h"
|
||||
#include <cocoatweet/api/interface/httpBase.h>
|
||||
|
||||
namespace CocoaTweet::API::Interface {
|
||||
@@ -11,11 +11,11 @@ class HttpPost : public HttpBase {
|
||||
public:
|
||||
protected:
|
||||
/// @brief Send HTTP/POST using OAuth object
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth : pointer to OAuth object to
|
||||
/// @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::OAuth::OAuth1> _oauth,
|
||||
void process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth,
|
||||
std::function<void(const std::string&)> _callback);
|
||||
};
|
||||
} // namespace CocoaTweet::API::Interface
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "cocoatweet/api/media/media.h"
|
||||
|
||||
namespace CocoaTweet::API::Medias {
|
||||
Media::Media(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
Media::Media(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define COCOATWEET_API_MEDIA_MEDIA_H_
|
||||
|
||||
#include "cocoatweet/api/interface/groupInterface.h"
|
||||
#include "cocoatweet/oauth/oauth.h"
|
||||
#include "cocoatweet/authentication/authenticator.h"
|
||||
#include <cocoatweet/api/model/mediaStore.h>
|
||||
#include <cocoatweet/api/media/upload.h>
|
||||
#include <vector>
|
||||
@@ -16,8 +16,8 @@ public:
|
||||
Media() = default;
|
||||
|
||||
/// @brief constructor which finally should to be called.
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::OAuth::OAuth1> : pointer to OAuth object
|
||||
Media(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||
/// @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;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ void Upload::media(const std::string& _media) {
|
||||
void Upload::mediaId(const std::string& _mediaId) {}
|
||||
|
||||
CocoaTweet::API::Model::MediaStore Upload::process(
|
||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
auto extension = std::filesystem::path(media_).extension().string<char>();
|
||||
if (mimeType.count(extension) == 0) {
|
||||
throw new CocoaTweet::Exception::UnsupportedMediaTypeException(
|
||||
|
||||
@@ -26,11 +26,11 @@ public:
|
||||
void mediaId(const std::string& _mediaId);
|
||||
|
||||
/// @brief upload media
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth : pointer to OAuth object for
|
||||
/// @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::OAuth::OAuth1> _oauth);
|
||||
CocoaTweet::API::Model::MediaStore process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
} // namespace CocoaTweet::API::Medias
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "oauthToken.h"
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef COCOATWEET_API_MODEL_OAUTHTOKEN_H_
|
||||
#define COCOATWEET_API_MODEL_OAUTHTOKEN_H_
|
||||
#include<string>
|
||||
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <cocoatweet/api/oauth1/accessToken.h>
|
||||
#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";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef COCOATWEET_API_OAUTH1_ACCESSTOKEN_H
|
||||
#define COCOATWEET_API_OAUTH1_ACCESSTOKEN_H
|
||||
|
||||
#include <cocoatweet/api/interface/httpPost.h>
|
||||
#include <cocoatweet/api/model/oauthToken.h>
|
||||
namespace CocoaTweet::API::OAuth1{
|
||||
class AccessToken: public CocoaTweet::API::Interface::HttpPost {
|
||||
private:
|
||||
CocoaTweet::API::Model::OAuthToken oauthToken_;
|
||||
public:
|
||||
AccessToken();
|
||||
|
||||
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) ;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <string>
|
||||
#include <cocoatweet/api/oauth1/authorize.h>
|
||||
#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";
|
||||
}
|
||||
|
||||
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::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;;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#ifndef COCOATWEET_API_OAUTH1_AUTHORIZE_H
|
||||
#define COCOATWEET_API_OAUTH1_AUTHORIZE_H
|
||||
|
||||
#include <cocoatweet/api/interface/httpPost.h>
|
||||
namespace CocoaTweet::API::OAuth1{
|
||||
class Authorize: public CocoaTweet::API::Interface::HttpPost {
|
||||
public:
|
||||
Authorize();
|
||||
|
||||
void oauthToken(const std::string& _oauthToken);
|
||||
|
||||
void forceLogin(const bool _forceLogin);
|
||||
|
||||
void screenName(const std::string& _screenName);
|
||||
|
||||
const std::string process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> __unused__) ;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
#include <cocoatweet/api/oauth1/oauth.h>
|
||||
#include <cocoatweet/authentication/authenticate.h>
|
||||
|
||||
namespace CocoaTweet::API::OAuth1 {
|
||||
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::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 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
|
||||
@@ -0,0 +1,30 @@
|
||||
#ifndef COCOATWEET_API_OAUTH1_OAUTH_H_
|
||||
#define COCOATWEET_API_OAUTH1_OAUTH_H_
|
||||
|
||||
#include "cocoatweet/api/interface/groupInterface.h"
|
||||
#include <cocoatweet/api/oauth1/accessToken.h>
|
||||
#include <cocoatweet/api/oauth1/requestToken.h>
|
||||
#include <cocoatweet/api/oauth1/authorize.h>
|
||||
#include <cocoatweet/api/model/oauthToken.h>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
namespace CocoaTweet::API::OAuth1 {
|
||||
/// @brief class for using users/show endpoint
|
||||
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
|
||||
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;
|
||||
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <cocoatweet/api/oauth1/requestToken.h>
|
||||
#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";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef COCOATWEET_API_OAUTH1_REQUESTTOKEN_H
|
||||
#define COCOATWEET_API_OAUTH1_REQUESTTOKEN_H
|
||||
|
||||
#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);
|
||||
|
||||
CocoaTweet::API::Model::OAuthToken process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -9,7 +9,7 @@ void Destroy::id(const std::string _id) {
|
||||
}
|
||||
|
||||
CocoaTweet::API::Model::Tweet Destroy::process(
|
||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
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);
|
||||
|
||||
@@ -18,9 +18,9 @@ public:
|
||||
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[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::OAuth::OAuth1> _oauth);
|
||||
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ void Retweet::id(const std::string& _id) {
|
||||
}
|
||||
|
||||
CocoaTweet::API::Model::Tweet Retweet::process(
|
||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
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);
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
|
||||
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::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "cocoatweet/api/status/userTimeline.h"
|
||||
|
||||
namespace CocoaTweet::API::Statuses {
|
||||
Status::Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
Status::Status(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define COCOATWEET_API_STATUS_STATUS_H_
|
||||
|
||||
#include "cocoatweet/api/interface/groupInterface.h"
|
||||
#include "cocoatweet/oauth/oauth.h"
|
||||
#include "cocoatweet/authentication/authenticator.h"
|
||||
#include <cocoatweet/api/model/tweet.h>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
@@ -28,8 +28,8 @@ public:
|
||||
Status() = default;
|
||||
|
||||
/// @brief constructor which finally should to be called.
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::OAuth::OAuth1> : pointer to OAuth object
|
||||
Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||
/// @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
|
||||
/// @details this function throws CocoaTweet::Exception::* if something happen
|
||||
|
||||
@@ -9,7 +9,7 @@ void Unretweet::id(const std::string& _id) {
|
||||
}
|
||||
|
||||
CocoaTweet::API::Model::Tweet Unretweet::process(
|
||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
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);
|
||||
|
||||
@@ -11,7 +11,7 @@ public:
|
||||
|
||||
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::Authentication::AuthenticatorBase> _oauth);
|
||||
};
|
||||
} // namespace CocoaTweet::API::Statuses
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ 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::OAuth::OAuth1> _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,9 @@ public:
|
||||
void failDMCommands(bool _fail);
|
||||
|
||||
/// @brief process request for endpoint
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _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::OAuth::OAuth1> _oauth);
|
||||
CocoaTweet::API::Model::Tweet process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
private:
|
||||
std::string status_;
|
||||
|
||||
@@ -13,7 +13,7 @@ void UserTimeline::screenName(const std::string& _screenName) {
|
||||
}
|
||||
|
||||
std::vector<CocoaTweet::API::Model::Tweet> UserTimeline::process(
|
||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
std::vector<CocoaTweet::API::Model::Tweet> tweet;
|
||||
HttpGet::process(_oauth, [&tweet](const std::string& _rcv) {
|
||||
auto json = nlohmann::json::parse(_rcv);
|
||||
|
||||
@@ -19,10 +19,10 @@ public:
|
||||
void screenName(const std::string& _screenName);
|
||||
|
||||
/// @brief process request for endpoint
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _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::OAuth::OAuth1> _oauth);
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
private:
|
||||
std::string status_;
|
||||
|
||||
@@ -23,7 +23,7 @@ void Show::id(const std::string& _id) {
|
||||
}
|
||||
|
||||
CocoaTweet::API::Model::User Show::process(
|
||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
CocoaTweet::API::Model::User user;
|
||||
HttpGet::process(_oauth, [&user](const std::string& _rcv) {
|
||||
user = CocoaTweet::API::Model::User::parse(_rcv);
|
||||
|
||||
@@ -23,10 +23,10 @@ public:
|
||||
void screenName(const std::string& _screenName);
|
||||
|
||||
/// @brief process request for endpoint
|
||||
/// @param[in] std::weak_ptr<CocoaTweet::OAuth::OAuth1> _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::OAuth::OAuth1> _oauth);
|
||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||
|
||||
private:
|
||||
std::string status_;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <cocoatweet/api/user/show.h>
|
||||
|
||||
namespace CocoaTweet::API::Users{
|
||||
User::User(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
||||
User::User(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||
oauth_ = _oauth;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define COCOATWEET_API_USER_USER_H_
|
||||
|
||||
#include "cocoatweet/api/interface/groupInterface.h"
|
||||
#include "cocoatweet/oauth/oauth.h"
|
||||
#include "cocoatweet/authentication/authenticator.h"
|
||||
#include <cocoatweet/api/model/user.h>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
@@ -15,8 +15,8 @@ public:
|
||||
User() = default;
|
||||
|
||||
/// @brief constructor which finally should to be called.
|
||||
/// @param[in] std::shared_ptr<CocoaTweet::OAuth::OAuth1> : pointer to OAuth object
|
||||
User(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||
/// @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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user