code format
This commit is contained in:
@@ -8,13 +8,12 @@
|
|||||||
namespace CocoaTweet::API {
|
namespace CocoaTweet::API {
|
||||||
API::API(CocoaTweet::Authentication::Key _key) {
|
API::API(CocoaTweet::Authentication::Key _key) {
|
||||||
swapKey(_key);
|
swapKey(_key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void API::swapKey(const CocoaTweet::Authentication::Key _key){
|
void API::swapKey(const CocoaTweet::Authentication::Key _key) {
|
||||||
if(_key.authType() == CocoaTweet::Authentication::Key::OAUTH10A){
|
if (_key.authType() == CocoaTweet::Authentication::Key::OAUTH10A) {
|
||||||
oauth_ = std::make_shared<CocoaTweet::Authentication::OAuth1>(_key);
|
oauth_ = std::make_shared<CocoaTweet::Authentication::OAuth1>(_key);
|
||||||
}else if(_key.authType() == CocoaTweet::Authentication::Key::OAUTH2){
|
} else if (_key.authType() == CocoaTweet::Authentication::Key::OAUTH2) {
|
||||||
oauth_ = std::make_shared<CocoaTweet::Authentication::Bearer>(_key);
|
oauth_ = std::make_shared<CocoaTweet::Authentication::Bearer>(_key);
|
||||||
}
|
}
|
||||||
user_ = Users::User(oauth_);
|
user_ = Users::User(oauth_);
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
#include <cocoatweet/api/directMessage/new.h>
|
#include <cocoatweet/api/directMessage/new.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::DirectMessages {
|
namespace CocoaTweet::API::DirectMessages {
|
||||||
DirectMessage::DirectMessage(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
DirectMessage::DirectMessage(
|
||||||
|
std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||||
oauth_ = _oauth;
|
oauth_ = _oauth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ public:
|
|||||||
DirectMessage() = default;
|
DirectMessage() = default;
|
||||||
|
|
||||||
/// @brief constructor which finally should to be called.
|
/// @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);
|
DirectMessage(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||||
|
|
||||||
void messageCreate(const std::string& _recipient, const std::string& _message);
|
void messageCreate(const std::string& _recipient, const std::string& _message);
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ public:
|
|||||||
void message(const std::string& _message);
|
void message(const std::string& _message);
|
||||||
|
|
||||||
/// @brief process request for endpoint
|
/// @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
|
/// @param[out] CocoaTweet::API::Model::Tweet : request result
|
||||||
void process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
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);
|
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;
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
HttpPost::process(_oauth, [&tweet](const std::string& _rcv) {
|
HttpPost::process(_oauth, [&tweet](const std::string& _rcv) {
|
||||||
tweet = CocoaTweet::API::Model::Tweet(_rcv);
|
tweet = CocoaTweet::API::Model::Tweet(_rcv);
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ class Create : public CocoaTweet::API::Interface::HttpPost {
|
|||||||
public:
|
public:
|
||||||
Create();
|
Create();
|
||||||
void id(const std::string& _id);
|
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:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ class Destroy : public CocoaTweet::API::Interface::HttpPost {
|
|||||||
public:
|
public:
|
||||||
Destroy();
|
Destroy();
|
||||||
void id(const std::string& _id);
|
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:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -130,10 +130,12 @@ void HttpGet::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBas
|
|||||||
throw CocoaTweet::Exception::RateLimitException(message.get<std::string>().c_str());
|
throw CocoaTweet::Exception::RateLimitException(message.get<std::string>().c_str());
|
||||||
} else if (error.get<int>() == 186) {
|
} else if (error.get<int>() == 186) {
|
||||||
throw CocoaTweet::Exception::TweetTooLongException(message.get<std::string>().c_str());
|
throw CocoaTweet::Exception::TweetTooLongException(message.get<std::string>().c_str());
|
||||||
}else if(error.get<int>() == 170){
|
} else if (error.get<int>() == 170) {
|
||||||
throw CocoaTweet::Exception::MissingRequiredParamException(message.get<std::string>().c_str());
|
throw CocoaTweet::Exception::MissingRequiredParamException(
|
||||||
}else if(error.get<int>() == 220){
|
message.get<std::string>().c_str());
|
||||||
throw CocoaTweet::Exception::CredentialNotAllowedException(message.get<std::string>().c_str());
|
} else if (error.get<int>() == 220) {
|
||||||
|
throw CocoaTweet::Exception::CredentialNotAllowedException(
|
||||||
|
message.get<std::string>().c_str());
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ class HttpGet : public virtual HttpBase {
|
|||||||
public:
|
public:
|
||||||
protected:
|
protected:
|
||||||
/// @brief Send HTTP/POST using OAuth object
|
/// @brief Send HTTP/POST using OAuth object
|
||||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer to OAuth object to
|
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer
|
||||||
/// authenticate
|
/// to OAuth object to authenticate
|
||||||
/// @param[in] std::function<void(const unsigned int, const std::string&)> _callback :
|
/// @param[in] std::function<void(const unsigned int, const std::string&)> _callback :
|
||||||
/// callback method for processing to response
|
/// callback method for processing to response
|
||||||
void process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth,
|
void process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth,
|
||||||
|
|||||||
@@ -71,7 +71,6 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBa
|
|||||||
// oauthHeader += CocoaTweet::Util::join(tmp, ",");
|
// oauthHeader += CocoaTweet::Util::join(tmp, ",");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
auto oauthHeader = std::string();
|
auto oauthHeader = std::string();
|
||||||
if (contentType_ == "application/x-www-form-urlencoded") {
|
if (contentType_ == "application/x-www-form-urlencoded") {
|
||||||
oauthHeader = oauth->calculateAuthHeader(bodyParam_, "POST", url_);
|
oauthHeader = oauth->calculateAuthHeader(bodyParam_, "POST", url_);
|
||||||
@@ -148,10 +147,12 @@ void HttpPost::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBa
|
|||||||
throw CocoaTweet::Exception::RateLimitException(message.get<std::string>().c_str());
|
throw CocoaTweet::Exception::RateLimitException(message.get<std::string>().c_str());
|
||||||
} else if (error.get<int>() == 186) {
|
} else if (error.get<int>() == 186) {
|
||||||
throw CocoaTweet::Exception::TweetTooLongException(message.get<std::string>().c_str());
|
throw CocoaTweet::Exception::TweetTooLongException(message.get<std::string>().c_str());
|
||||||
}else if(error.get<int>() == 170){
|
} else if (error.get<int>() == 170) {
|
||||||
throw CocoaTweet::Exception::MissingRequiredParamException(message.get<std::string>().c_str());
|
throw CocoaTweet::Exception::MissingRequiredParamException(
|
||||||
}else if(error.get<int>() == 220){
|
message.get<std::string>().c_str());
|
||||||
throw CocoaTweet::Exception::CredentialNotAllowedException(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:
|
public:
|
||||||
protected:
|
protected:
|
||||||
/// @brief Send HTTP/POST using OAuth object
|
/// @brief Send HTTP/POST using OAuth object
|
||||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer to OAuth object to
|
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer
|
||||||
/// authenticate
|
/// to OAuth object to authenticate
|
||||||
/// @param[in] std::function<void(const unsigned int, const std::string&)> _callback :
|
/// @param[in] std::function<void(const unsigned int, const std::string&)> _callback :
|
||||||
/// callback method for processing to response
|
/// callback method for processing to response
|
||||||
void process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth,
|
void process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth,
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ public:
|
|||||||
Media() = default;
|
Media() = default;
|
||||||
|
|
||||||
/// @brief constructor which finally should to be called.
|
/// @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);
|
Media(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||||
|
|
||||||
CocoaTweet::API::Model::MediaStore upload(const std::string& _file) const;
|
CocoaTweet::API::Model::MediaStore upload(const std::string& _file) const;
|
||||||
|
|||||||
@@ -26,11 +26,12 @@ public:
|
|||||||
void mediaId(const std::string& _mediaId);
|
void mediaId(const std::string& _mediaId);
|
||||||
|
|
||||||
/// @brief upload media
|
/// @brief upload media
|
||||||
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer to OAuth object for
|
/// @param[in] std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth : pointer
|
||||||
/// authenticate
|
/// to OAuth object for authenticate
|
||||||
/// @param[out] CocoaTweet::API::Model::MediaStore : media upload result. use id() for post
|
/// @param[out] CocoaTweet::API::Model::MediaStore : media upload result. use id() for post
|
||||||
/// tweet.
|
/// 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
|
} // namespace CocoaTweet::API::Medias
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
#include "oauthToken.h"
|
#include "oauthToken.h"
|
||||||
|
|
||||||
namespace CocoaTweet::API::Model{
|
namespace CocoaTweet::API::Model {
|
||||||
|
|
||||||
OAuthToken::OAuthToken(): oauthToken_(""), oauthTokenSecret_(""){}
|
OAuthToken::OAuthToken() : oauthToken_(""), oauthTokenSecret_("") {}
|
||||||
OAuthToken::OAuthToken(const std::string _oauthToken, const std::string& _oauthTokenSecret): oauthToken_(_oauthToken), oauthTokenSecret_(_oauthTokenSecret) {}
|
OAuthToken::OAuthToken(const std::string _oauthToken, const std::string& _oauthTokenSecret)
|
||||||
const std::string& OAuthToken::oauthToken() const {
|
: oauthToken_(_oauthToken), oauthTokenSecret_(_oauthTokenSecret) {}
|
||||||
|
const std::string& OAuthToken::oauthToken() const {
|
||||||
return oauthToken_;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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_
|
#ifndef COCOATWEET_API_MODEL_OAUTHTOKEN_H_
|
||||||
#define COCOATWEET_API_MODEL_OAUTHTOKEN_H_
|
#define COCOATWEET_API_MODEL_OAUTHTOKEN_H_
|
||||||
#include<string>
|
#include <string>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Model{
|
namespace CocoaTweet::API::Model {
|
||||||
class OAuthToken{
|
class OAuthToken {
|
||||||
std::string oauthToken_;
|
std::string oauthToken_;
|
||||||
std::string oauthTokenSecret_;
|
std::string oauthTokenSecret_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OAuthToken();
|
OAuthToken();
|
||||||
OAuthToken(const std::string _oauthToken, const std::string& _oauthTokenSecret);
|
OAuthToken(const std::string _oauthToken, const std::string& _oauthTokenSecret);
|
||||||
const std::string& oauthToken() const;
|
const std::string& oauthToken() const;
|
||||||
const std::string& oauthTokenSecret() const;
|
const std::string& oauthTokenSecret() const;
|
||||||
void oauthToken(const std::string& _oauthToken);
|
void oauthToken(const std::string& _oauthToken);
|
||||||
void oauthTokenSecret(const std::string& _oauthTokenSecret);
|
void oauthTokenSecret(const std::string& _oauthTokenSecret);
|
||||||
};
|
};
|
||||||
}
|
} // namespace CocoaTweet::API::Model
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -2,32 +2,33 @@
|
|||||||
#include <cocoatweet/util/util.h>
|
#include <cocoatweet/util/util.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace CocoaTweet::API::OAuth1{
|
namespace CocoaTweet::API::OAuth1 {
|
||||||
AccessToken::AccessToken(){
|
AccessToken::AccessToken() {
|
||||||
contentType_ = "application/x-www-form-urlencoded";
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
url_ = "https://api.twitter.com/oauth/access_token";
|
url_ = "https://api.twitter.com/oauth/access_token";
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccessToken::oauthVerifier(const std::string& _verifier){
|
void AccessToken::oauthVerifier(const std::string& _verifier) {
|
||||||
bodyParam_.insert_or_assign("oauth_verifier", _verifier);
|
bodyParam_.insert_or_assign("oauth_verifier", _verifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccessToken::oauthToken(const CocoaTweet::API::Model::OAuthToken _token){
|
void AccessToken::oauthToken(const CocoaTweet::API::Model::OAuthToken _token) {
|
||||||
oauthToken_ = _token;
|
oauthToken_ = _token;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CocoaTweet::API::Model::OAuthToken AccessToken::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth){
|
const CocoaTweet::API::Model::OAuthToken AccessToken::process(
|
||||||
|
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||||
CocoaTweet::API::Model::OAuthToken oauthToken;
|
CocoaTweet::API::Model::OAuthToken oauthToken;
|
||||||
HttpPost::process(_oauth, [&oauthToken](const std::string& _rcv){
|
HttpPost::process(_oauth, [&oauthToken](const std::string& _rcv) {
|
||||||
auto mp = CocoaTweet::Util::parse(_rcv, '&', '=');
|
auto mp = CocoaTweet::Util::parse(_rcv, '&', '=');
|
||||||
if(mp.count("oauth_token")){
|
if (mp.count("oauth_token")) {
|
||||||
oauthToken.oauthToken(mp.at("oauth_token"));
|
oauthToken.oauthToken(mp.at("oauth_token"));
|
||||||
}
|
}
|
||||||
if(mp.count("oauth_token_secret")){
|
if (mp.count("oauth_token_secret")) {
|
||||||
oauthToken.oauthTokenSecret(mp.at("oauth_token_secret"));
|
oauthToken.oauthTokenSecret(mp.at("oauth_token_secret"));
|
||||||
}
|
}
|
||||||
std::cout << _rcv << std::endl;
|
std::cout << _rcv << std::endl;
|
||||||
});
|
});
|
||||||
return oauthToken;
|
return oauthToken;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace CocoaTweet::API::OAuth1
|
||||||
@@ -3,18 +3,20 @@
|
|||||||
|
|
||||||
#include <cocoatweet/api/interface/httpPost.h>
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
#include <cocoatweet/api/model/oauthToken.h>
|
#include <cocoatweet/api/model/oauthToken.h>
|
||||||
namespace CocoaTweet::API::OAuth1{
|
namespace CocoaTweet::API::OAuth1 {
|
||||||
class AccessToken: public CocoaTweet::API::Interface::HttpPost {
|
class AccessToken : public CocoaTweet::API::Interface::HttpPost {
|
||||||
private:
|
private:
|
||||||
CocoaTweet::API::Model::OAuthToken oauthToken_;
|
CocoaTweet::API::Model::OAuthToken oauthToken_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AccessToken();
|
AccessToken();
|
||||||
|
|
||||||
void oauthVerifier(const std::string& _verifier);
|
void oauthVerifier(const std::string& _verifier);
|
||||||
void oauthToken(const CocoaTweet::API::Model::OAuthToken _token);
|
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
|
#endif
|
||||||
@@ -3,31 +3,33 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cocoatweet/util/util.h>
|
#include <cocoatweet/util/util.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::OAuth1{
|
namespace CocoaTweet::API::OAuth1 {
|
||||||
Authorize::Authorize(){
|
Authorize::Authorize() {
|
||||||
contentType_ = "application/x-www-form-urlencoded";
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
url_ = "https://api.twitter.com/oauth/authorize";
|
url_ = "https://api.twitter.com/oauth/authorize";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Authorize::oauthToken(const std::string& _oauthToken){
|
void Authorize::oauthToken(const std::string& _oauthToken) {
|
||||||
bodyParam_.insert_or_assign("oauth_token", _oauthToken);
|
bodyParam_.insert_or_assign("oauth_token", _oauthToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Authorize::forceLogin(const bool _forceLogin){
|
void Authorize::forceLogin(const bool _forceLogin) {
|
||||||
bodyParam_.insert_or_assign("force_login", std::to_string(static_cast<int>(_forceLogin)));
|
bodyParam_.insert_or_assign("force_login", std::to_string(static_cast<int>(_forceLogin)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Authorize::screenName(const std::string& _screenName){
|
void Authorize::screenName(const std::string& _screenName) {
|
||||||
bodyParam_.insert_or_assign("screen_name", _screenName);
|
bodyParam_.insert_or_assign("screen_name", _screenName);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Authorize::process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> __unused__) {
|
const std::string Authorize::process(
|
||||||
|
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> __unused__) {
|
||||||
std::vector<std::string> tmp;
|
std::vector<std::string> tmp;
|
||||||
std::string query = "";
|
std::string query = "";
|
||||||
for (const auto& [key, value] : bodyParam_) {
|
for (const auto& [key, value] : bodyParam_) {
|
||||||
tmp.push_back(key + "=" + value);
|
tmp.push_back(key + "=" + value);
|
||||||
query = CocoaTweet::Util::join(tmp, "&");
|
query = CocoaTweet::Util::join(tmp, "&");
|
||||||
}
|
}
|
||||||
return url_ + "?" + query;;
|
return url_ + "?" + query;
|
||||||
}
|
;
|
||||||
}
|
}
|
||||||
|
} // namespace CocoaTweet::API::OAuth1
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
#define COCOATWEET_API_OAUTH1_AUTHORIZE_H
|
#define COCOATWEET_API_OAUTH1_AUTHORIZE_H
|
||||||
|
|
||||||
#include <cocoatweet/api/interface/httpPost.h>
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
namespace CocoaTweet::API::OAuth1{
|
namespace CocoaTweet::API::OAuth1 {
|
||||||
class Authorize: public CocoaTweet::API::Interface::HttpPost {
|
class Authorize : public CocoaTweet::API::Interface::HttpPost {
|
||||||
public:
|
public:
|
||||||
Authorize();
|
Authorize();
|
||||||
|
|
||||||
@@ -13,8 +13,9 @@ public:
|
|||||||
|
|
||||||
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
|
#endif
|
||||||
@@ -2,11 +2,12 @@
|
|||||||
#include <cocoatweet/authentication/authenticate.h>
|
#include <cocoatweet/authentication/authenticate.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::OAuth1 {
|
namespace CocoaTweet::API::OAuth1 {
|
||||||
OAuth::OAuth(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth){
|
OAuth::OAuth(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||||
oauth_ = _oauth;
|
oauth_ = _oauth;
|
||||||
}
|
}
|
||||||
|
|
||||||
CocoaTweet::API::Model::OAuthToken OAuth::requestToken(const std::string& _oauthCallback) const{
|
CocoaTweet::API::Model::OAuthToken OAuth::requestToken(
|
||||||
|
const std::string& _oauthCallback) const {
|
||||||
auto key = oauth_.lock()->key();
|
auto key = oauth_.lock()->key();
|
||||||
key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A);
|
key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A);
|
||||||
auto oauth = std::make_shared<CocoaTweet::Authentication::OAuth1>(key);
|
auto oauth = std::make_shared<CocoaTweet::Authentication::OAuth1>(key);
|
||||||
@@ -14,15 +15,16 @@ namespace CocoaTweet::API::OAuth1 {
|
|||||||
CocoaTweet::API::OAuth1::RequestToken requestToken;
|
CocoaTweet::API::OAuth1::RequestToken requestToken;
|
||||||
requestToken.oauthCallback(_oauthCallback);
|
requestToken.oauthCallback(_oauthCallback);
|
||||||
return requestToken.process(oauth);
|
return requestToken.process(oauth);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string OAuth::authorize(const CocoaTweet::API::Model::OAuthToken _oauthToken) const{
|
const std::string OAuth::authorize(const CocoaTweet::API::Model::OAuthToken _oauthToken) const {
|
||||||
CocoaTweet::API::OAuth1::Authorize authorize;
|
CocoaTweet::API::OAuth1::Authorize authorize;
|
||||||
authorize.oauthToken(_oauthToken.oauthToken());
|
authorize.oauthToken(_oauthToken.oauthToken());
|
||||||
return authorize.process(oauth_);
|
return authorize.process(oauth_);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CocoaTweet::API::Model::OAuthToken OAuth::accessToken(const CocoaTweet::API::Model::OAuthToken _oauthToken, const std::string _verifier) const{
|
const CocoaTweet::API::Model::OAuthToken OAuth::accessToken(
|
||||||
|
const CocoaTweet::API::Model::OAuthToken _oauthToken, const std::string _verifier) const {
|
||||||
auto key = oauth_.lock()->key();
|
auto key = oauth_.lock()->key();
|
||||||
key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A);
|
key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH10A);
|
||||||
key.accessToken(_oauthToken.oauthToken());
|
key.accessToken(_oauthToken.oauthToken());
|
||||||
@@ -31,5 +33,5 @@ namespace CocoaTweet::API::OAuth1 {
|
|||||||
CocoaTweet::API::OAuth1::AccessToken accessToken;
|
CocoaTweet::API::OAuth1::AccessToken accessToken;
|
||||||
accessToken.oauthVerifier(_verifier);
|
accessToken.oauthVerifier(_verifier);
|
||||||
return accessToken.process(oauth);
|
return accessToken.process(oauth);
|
||||||
}
|
}
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::OAuth1
|
||||||
|
|||||||
@@ -17,14 +17,15 @@ public:
|
|||||||
OAuth() = default;
|
OAuth() = default;
|
||||||
|
|
||||||
/// @brief constructor which finally should to be called.
|
/// @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);
|
OAuth(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||||
|
|
||||||
CocoaTweet::API::Model::OAuthToken requestToken(const std::string& _oauthCallback) const;
|
CocoaTweet::API::Model::OAuthToken requestToken(const std::string& _oauthCallback) const;
|
||||||
const std::string authorize(const CocoaTweet::API::Model::OAuthToken _oauthToken) 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
|
#endif
|
||||||
|
|||||||
@@ -2,28 +2,29 @@
|
|||||||
#include <cocoatweet/util/util.h>
|
#include <cocoatweet/util/util.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace CocoaTweet::API::OAuth1{
|
namespace CocoaTweet::API::OAuth1 {
|
||||||
RequestToken::RequestToken(){
|
RequestToken::RequestToken() {
|
||||||
contentType_ = "application/x-www-form-urlencoded";
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
url_ = "https://api.twitter.com/oauth/request_token";
|
url_ = "https://api.twitter.com/oauth/request_token";
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestToken::oauthCallback(const std::string& _oauthCallback){
|
void RequestToken::oauthCallback(const std::string& _oauthCallback) {
|
||||||
bodyParam_.insert_or_assign("oauth_callback", _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 RequestToken::process(
|
||||||
|
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||||
CocoaTweet::API::Model::OAuthToken oauthToken;
|
CocoaTweet::API::Model::OAuthToken oauthToken;
|
||||||
HttpPost::process(_oauth, [&oauthToken](const std::string& _rcv){
|
HttpPost::process(_oauth, [&oauthToken](const std::string& _rcv) {
|
||||||
auto mp = CocoaTweet::Util::parse(_rcv, '&', '=');
|
auto mp = CocoaTweet::Util::parse(_rcv, '&', '=');
|
||||||
if(mp.count("oauth_token")){
|
if (mp.count("oauth_token")) {
|
||||||
oauthToken.oauthToken(mp.at("oauth_token"));
|
oauthToken.oauthToken(mp.at("oauth_token"));
|
||||||
}
|
}
|
||||||
if(mp.count("oauth_token_secret")){
|
if (mp.count("oauth_token_secret")) {
|
||||||
oauthToken.oauthTokenSecret(mp.at("oauth_token_secret"));
|
oauthToken.oauthTokenSecret(mp.at("oauth_token_secret"));
|
||||||
}
|
}
|
||||||
std::cout << _rcv << std::endl;
|
std::cout << _rcv << std::endl;
|
||||||
});
|
});
|
||||||
return oauthToken;
|
return oauthToken;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace CocoaTweet::API::OAuth1
|
||||||
@@ -4,14 +4,15 @@
|
|||||||
#include <cocoatweet/api/interface/httpPost.h>
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
#include <cocoatweet/api/model/oauthToken.h>
|
#include <cocoatweet/api/model/oauthToken.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::OAuth1{
|
namespace CocoaTweet::API::OAuth1 {
|
||||||
class RequestToken: public CocoaTweet::API::Interface::HttpPost {
|
class RequestToken : public CocoaTweet::API::Interface::HttpPost {
|
||||||
public:
|
public:
|
||||||
RequestToken();
|
RequestToken();
|
||||||
void oauthCallback(const std::string& _oauthCallback);
|
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
|
#endif
|
||||||
@@ -2,15 +2,15 @@
|
|||||||
#include <cocoatweet/authentication/basic.h>
|
#include <cocoatweet/authentication/basic.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::OAuth2 {
|
namespace CocoaTweet::API::OAuth2 {
|
||||||
OAuth2::OAuth2(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth){
|
OAuth2::OAuth2(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||||
oauth_ = _oauth;
|
oauth_ = _oauth;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string OAuth2::token() const{
|
const std::string OAuth2::token() const {
|
||||||
auto key = oauth_.lock()->key();
|
auto key = oauth_.lock()->key();
|
||||||
auto oauth = std::make_shared<CocoaTweet::Authentication::Basic>(key);
|
auto oauth = std::make_shared<CocoaTweet::Authentication::Basic>(key);
|
||||||
|
|
||||||
CocoaTweet::API::OAuth2::Token token;
|
CocoaTweet::API::OAuth2::Token token;
|
||||||
return token.process(oauth);
|
return token.process(oauth);
|
||||||
}
|
}
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::OAuth2
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ public:
|
|||||||
OAuth2() = default;
|
OAuth2() = default;
|
||||||
|
|
||||||
/// @brief constructor which finally should to be called.
|
/// @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);
|
OAuth2(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||||
|
|
||||||
const std::string token() const;
|
const std::string token() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::OAuth2
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
#include <cocoatweet/api/oauth2/token.h>
|
#include <cocoatweet/api/oauth2/token.h>
|
||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
|
|
||||||
|
namespace CocoaTweet::API::OAuth2 {
|
||||||
namespace CocoaTweet::API::OAuth2{
|
Token::Token() {
|
||||||
Token::Token(){
|
|
||||||
contentType_ = "application/x-www-form-urlencoded";
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
url_ = "https://api.twitter.com/oauth2/token";
|
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());
|
auto basic = std::make_shared<CocoaTweet::Authentication::Basic>(_oauth.lock()->key());
|
||||||
std::string bearer = "";
|
std::string bearer = "";
|
||||||
HttpPost::process(basic, [&bearer](const std::string& _rcv) {
|
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;
|
return bearer;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace CocoaTweet::API::OAuth2
|
||||||
@@ -4,12 +4,13 @@
|
|||||||
#include <cocoatweet/api/interface/httpPost.h>
|
#include <cocoatweet/api/interface/httpPost.h>
|
||||||
#include <cocoatweet/authentication/basic.h>
|
#include <cocoatweet/authentication/basic.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::OAuth2{
|
namespace CocoaTweet::API::OAuth2 {
|
||||||
class Token: public CocoaTweet::API::Interface::HttpPost{
|
class Token : public CocoaTweet::API::Interface::HttpPost {
|
||||||
public:
|
public:
|
||||||
Token();
|
Token();
|
||||||
const std::string process(std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
const std::string process(
|
||||||
};
|
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||||
}
|
};
|
||||||
|
} // namespace CocoaTweet::API::OAuth2
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -18,9 +18,11 @@ public:
|
|||||||
void id(const std::string _id);
|
void id(const std::string _id);
|
||||||
|
|
||||||
/// @brief process request for endpoint
|
/// @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
|
/// @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
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ public:
|
|||||||
|
|
||||||
void id(const std::string& _id);
|
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
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ public:
|
|||||||
Status() = default;
|
Status() = default;
|
||||||
|
|
||||||
/// @brief constructor which finally should to be called.
|
/// @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);
|
Status(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||||
|
|
||||||
/// @brief send request to statuses/update with specified status
|
/// @brief send request to statuses/update with specified status
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ public:
|
|||||||
|
|
||||||
void id(const std::string& _id);
|
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
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ void Update::failDMCommands(bool _fail) {
|
|||||||
bodyParam_.insert_or_assign("fail_dmcommands", std::to_string(_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;
|
CocoaTweet::API::Model::Tweet tweet;
|
||||||
HttpPost::process(_oauth, [&tweet](const std::string& _rcv) {
|
HttpPost::process(_oauth, [&tweet](const std::string& _rcv) {
|
||||||
tweet = CocoaTweet::API::Model::Tweet::parse(_rcv);
|
tweet = CocoaTweet::API::Model::Tweet::parse(_rcv);
|
||||||
|
|||||||
@@ -40,9 +40,11 @@ public:
|
|||||||
void failDMCommands(bool _fail);
|
void failDMCommands(bool _fail);
|
||||||
|
|
||||||
/// @brief process request for endpoint
|
/// @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
|
/// @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:
|
private:
|
||||||
std::string status_;
|
std::string status_;
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ public:
|
|||||||
void screenName(const std::string& _screenName);
|
void screenName(const std::string& _screenName);
|
||||||
|
|
||||||
/// @brief process request for endpoint
|
/// @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
|
/// @param[out] std::vector<CocoaTweet::API::Model::Tweet> : request result
|
||||||
std::vector<CocoaTweet::API::Model::Tweet> process(
|
std::vector<CocoaTweet::API::Model::Tweet> process(
|
||||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ Show::Show() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Show::screenName(const std::string& _screenName) {
|
void Show::screenName(const std::string& _screenName) {
|
||||||
if(bodyParam_.count("user_id") > 0){
|
if (bodyParam_.count("user_id") > 0) {
|
||||||
bodyParam_.erase("user_id");
|
bodyParam_.erase("user_id");
|
||||||
}
|
}
|
||||||
bodyParam_.insert_or_assign("screen_name", _screenName);
|
bodyParam_.insert_or_assign("screen_name", _screenName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Show::id(const std::string& _id) {
|
void Show::id(const std::string& _id) {
|
||||||
if(bodyParam_.count("screen_name") > 0){
|
if (bodyParam_.count("screen_name") > 0) {
|
||||||
bodyParam_.erase("screen_name");
|
bodyParam_.erase("screen_name");
|
||||||
}
|
}
|
||||||
bodyParam_.insert_or_assign("id", _id);
|
bodyParam_.insert_or_assign("id", _id);
|
||||||
@@ -31,4 +31,4 @@ CocoaTweet::API::Model::User Show::process(
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Users
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ public:
|
|||||||
void screenName(const std::string& _screenName);
|
void screenName(const std::string& _screenName);
|
||||||
|
|
||||||
/// @brief process request for endpoint
|
/// @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
|
/// @param[out] CocoaTweet::API::Model::User : request result
|
||||||
CocoaTweet::API::Model::User process(
|
CocoaTweet::API::Model::User process(
|
||||||
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
std::weak_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||||
@@ -31,6 +32,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::string status_;
|
std::string status_;
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Users
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
#include <cocoatweet/api/user/user.h>
|
#include <cocoatweet/api/user/user.h>
|
||||||
#include <cocoatweet/api/user/show.h>
|
#include <cocoatweet/api/user/show.h>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Users{
|
namespace CocoaTweet::API::Users {
|
||||||
User::User(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
User::User(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth) {
|
||||||
oauth_ = _oauth;
|
oauth_ = _oauth;
|
||||||
}
|
}
|
||||||
|
|
||||||
CocoaTweet::API::Model::User User::show(const std::string& _screenName)const{
|
CocoaTweet::API::Model::User User::show(const std::string& _screenName) const {
|
||||||
CocoaTweet::API::Users::Show show;
|
CocoaTweet::API::Users::Show show;
|
||||||
show.screenName(_screenName);
|
show.screenName(_screenName);
|
||||||
return show.process(oauth_);
|
return show.process(oauth_);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace CocoaTweet::API::Users
|
||||||
@@ -15,12 +15,12 @@ public:
|
|||||||
User() = default;
|
User() = default;
|
||||||
|
|
||||||
/// @brief constructor which finally should to be called.
|
/// @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);
|
User(std::shared_ptr<CocoaTweet::Authentication::AuthenticatorBase> _oauth);
|
||||||
|
|
||||||
CocoaTweet::API::Model::User show(const std::string& _screenName) const;
|
CocoaTweet::API::Model::User show(const std::string& _screenName) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Users
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ OAuth1::OAuth1() {
|
|||||||
method_ = AuthenticationMethod::OAUTH10A;
|
method_ = AuthenticationMethod::OAUTH10A;
|
||||||
}
|
}
|
||||||
|
|
||||||
OAuth1::OAuth1(const Key _key){
|
OAuth1::OAuth1(const Key _key) {
|
||||||
key_ = _key;
|
key_ = _key;
|
||||||
method_ = AuthenticationMethod::OAUTH10A;
|
method_ = AuthenticationMethod::OAUTH10A;
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,6 @@ const std::string OAuth1::version() const {
|
|||||||
return "1.0";
|
return "1.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::map<std::string, std::string> OAuth1::oauthParam() const {
|
std::map<std::string, std::string> OAuth1::oauthParam() const {
|
||||||
auto tmp = std::map<std::string, std::string>{{"oauth_nonce", nonce()},
|
auto tmp = std::map<std::string, std::string>{{"oauth_nonce", nonce()},
|
||||||
{"oauth_signature_method", method()},
|
{"oauth_signature_method", method()},
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <cocoatweet/authentication/authenticator.h>
|
#include <cocoatweet/authentication/authenticator.h>
|
||||||
|
|
||||||
namespace CocoaTweet::Authentication {
|
namespace CocoaTweet::Authentication {
|
||||||
class OAuth1: public AuthenticatorBase {
|
class OAuth1 : public AuthenticatorBase {
|
||||||
public:
|
public:
|
||||||
OAuth1();
|
OAuth1();
|
||||||
OAuth1(const Key _key);
|
OAuth1(const Key _key);
|
||||||
@@ -28,7 +28,6 @@ public:
|
|||||||
std::map<std::string, std::string> oauthParam() const;
|
std::map<std::string, std::string> oauthParam() const;
|
||||||
std::string hmacSha1(std::string _key, std::string _data);
|
std::string hmacSha1(std::string _key, std::string _data);
|
||||||
const std::string base64(const std::string& _raw);
|
const std::string base64(const std::string& _raw);
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::Authentication
|
} // namespace CocoaTweet::Authentication
|
||||||
|
|
||||||
|
|||||||
@@ -2,21 +2,16 @@
|
|||||||
#define COCOATWEET_AUTHENTICATION_AUTHENTICATORBASE_H
|
#define COCOATWEET_AUTHENTICATION_AUTHENTICATORBASE_H
|
||||||
|
|
||||||
#include <cocoatweet/authentication/key.h>
|
#include <cocoatweet/authentication/key.h>
|
||||||
namespace CocoaTweet::Authentication{
|
namespace CocoaTweet::Authentication {
|
||||||
class AuthenticatorBase{
|
class AuthenticatorBase {
|
||||||
public:
|
public:
|
||||||
enum class AuthenticationMethod{
|
enum class AuthenticationMethod { OAUTH10A, OAUTH2, BASIC, PLAIN, NONE };
|
||||||
OAUTH10A,
|
|
||||||
OAUTH2,
|
|
||||||
BASIC,
|
|
||||||
PLAIN,
|
|
||||||
NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual const std::string calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
virtual const std::string calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
||||||
const std::string& _method, const std::string& _url) = 0;
|
const std::string& _method,
|
||||||
|
const std::string& _url) = 0;
|
||||||
|
|
||||||
const Key key() const{
|
const Key key() const {
|
||||||
return key_;
|
return key_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +24,6 @@ protected:
|
|||||||
return realsize;
|
return realsize;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace CocoaTweet::Authentication
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -27,20 +27,18 @@ Basic::Basic() {
|
|||||||
method_ = AuthenticationMethod::BASIC;
|
method_ = AuthenticationMethod::BASIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
Basic::Basic(const Key _key){
|
Basic::Basic(const Key _key) {
|
||||||
key_ = _key;
|
key_ = _key;
|
||||||
method_ = AuthenticationMethod::BASIC;
|
method_ = AuthenticationMethod::BASIC;
|
||||||
}
|
}
|
||||||
const std::string Basic::calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
const std::string Basic::calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
||||||
const std::string& _method,
|
const std::string& _method,
|
||||||
const std::string& _url) {
|
const std::string& _url) {
|
||||||
|
|
||||||
auto signature = key_.consumerKey() + ":" + key_.consumerSecret();
|
auto signature = key_.consumerKey() + ":" + key_.consumerSecret();
|
||||||
auto k64Signature = base64(signature);
|
auto k64Signature = base64(signature);
|
||||||
auto authHeader = std::string("Authorization: Basic ") + k64Signature;
|
auto authHeader = std::string("Authorization: Basic ") + k64Signature;
|
||||||
|
|
||||||
return authHeader;
|
return authHeader;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Basic::base64(const std::string& _raw) {
|
const std::string Basic::base64(const std::string& _raw) {
|
||||||
@@ -73,5 +71,4 @@ const std::string Basic::base64(const std::string& _raw) {
|
|||||||
return base64;
|
return base64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace CocoaTweet::Authentication
|
} // namespace CocoaTweet::Authentication
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <cocoatweet/authentication/authenticator.h>
|
#include <cocoatweet/authentication/authenticator.h>
|
||||||
|
|
||||||
namespace CocoaTweet::Authentication {
|
namespace CocoaTweet::Authentication {
|
||||||
class Basic: public AuthenticatorBase {
|
class Basic : public AuthenticatorBase {
|
||||||
public:
|
public:
|
||||||
Basic();
|
Basic();
|
||||||
Basic(const Key _key);
|
Basic(const Key _key);
|
||||||
@@ -18,7 +18,6 @@ public:
|
|||||||
const std::string calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
const std::string calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
||||||
const std::string& _method, const std::string& _url);
|
const std::string& _method, const std::string& _url);
|
||||||
const std::string base64(const std::string& _raw);
|
const std::string base64(const std::string& _raw);
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::Authentication
|
} // namespace CocoaTweet::Authentication
|
||||||
|
|
||||||
|
|||||||
@@ -27,18 +27,16 @@ Bearer::Bearer() {
|
|||||||
method_ = AuthenticationMethod::OAUTH2;
|
method_ = AuthenticationMethod::OAUTH2;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bearer::Bearer(const Key _key){
|
Bearer::Bearer(const Key _key) {
|
||||||
key_ = _key;
|
key_ = _key;
|
||||||
method_ = AuthenticationMethod::OAUTH2;
|
method_ = AuthenticationMethod::OAUTH2;
|
||||||
}
|
}
|
||||||
const std::string Bearer::calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
const std::string Bearer::calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
||||||
const std::string& _method,
|
const std::string& _method,
|
||||||
const std::string& _url) {
|
const std::string& _url) {
|
||||||
|
|
||||||
auto authHeader = std::string("Authorization: Bearer ") + key_.bearerToken();
|
auto authHeader = std::string("Authorization: Bearer ") + key_.bearerToken();
|
||||||
|
|
||||||
return authHeader;
|
return authHeader;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CocoaTweet::Authentication
|
} // namespace CocoaTweet::Authentication
|
||||||
|
|||||||
@@ -8,12 +8,11 @@
|
|||||||
#include <cocoatweet/authentication/authenticator.h>
|
#include <cocoatweet/authentication/authenticator.h>
|
||||||
|
|
||||||
namespace CocoaTweet::Authentication {
|
namespace CocoaTweet::Authentication {
|
||||||
class Bearer: public AuthenticatorBase {
|
class Bearer : public AuthenticatorBase {
|
||||||
public:
|
public:
|
||||||
Bearer();
|
Bearer();
|
||||||
Bearer(const Key _key);
|
Bearer(const Key _key);
|
||||||
|
|
||||||
|
|
||||||
const std::string calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
const std::string calculateAuthHeader(std::map<std::string, std::string> _bodyParam,
|
||||||
const std::string& _method, const std::string& _url);
|
const std::string& _method, const std::string& _url);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,10 +7,7 @@
|
|||||||
namespace CocoaTweet::Authentication {
|
namespace CocoaTweet::Authentication {
|
||||||
class Key {
|
class Key {
|
||||||
public:
|
public:
|
||||||
enum AUTH_TYPE{
|
enum AUTH_TYPE { OAUTH10A, OAUTH2 };
|
||||||
OAUTH10A,
|
|
||||||
OAUTH2
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string consumerKey_;
|
std::string consumerKey_;
|
||||||
@@ -19,16 +16,20 @@ private:
|
|||||||
std::string accessTokenSecret_;
|
std::string accessTokenSecret_;
|
||||||
std::string bearerToken_;
|
std::string bearerToken_;
|
||||||
AUTH_TYPE authType_;
|
AUTH_TYPE authType_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Key() : consumerKey_(""), consumerSecret_(""), accessToken_(""), accessTokenSecret_("") {}
|
Key() : consumerKey_(""), consumerSecret_(""), accessToken_(""), accessTokenSecret_("") {}
|
||||||
Key(const std::string& _consumerKey, const std::string& _consumerSecret,
|
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),
|
: consumerKey_(_consumerKey),
|
||||||
consumerSecret_(_consumerSecret),
|
consumerSecret_(_consumerSecret),
|
||||||
accessToken_(_accessToken),
|
accessToken_(_accessToken),
|
||||||
accessTokenSecret_(_accessTokenSecret), authType_(_authType) {}
|
accessTokenSecret_(_accessTokenSecret),
|
||||||
Key(const std::string& _consumerKey, const std::string& _consumerSecret, const AUTH_TYPE _authType = AUTH_TYPE::OAUTH2)
|
authType_(_authType) {}
|
||||||
: consumerKey_(_consumerKey), consumerSecret_(_consumerSecret), 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) {
|
void consumerKey(const std::string& _consumerKey) {
|
||||||
consumerKey_ = _consumerKey;
|
consumerKey_ = _consumerKey;
|
||||||
|
|||||||
@@ -3,9 +3,8 @@
|
|||||||
|
|
||||||
#include <cocoatweet/authentication/authenticator.h>
|
#include <cocoatweet/authentication/authenticator.h>
|
||||||
|
|
||||||
namespace CocoaTweet::Authentication{
|
namespace CocoaTweet::Authentication {
|
||||||
class Plain: public AuthenticatorBase {
|
class Plain : public AuthenticatorBase {};
|
||||||
};
|
} // namespace CocoaTweet::Authentication
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,18 +5,18 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace CocoaTweet::Authentication{
|
namespace CocoaTweet::Authentication {
|
||||||
class Auth: public groupInterface {
|
class Auth : public groupInterface {
|
||||||
public:
|
public:
|
||||||
enum AuthType { OAuth, Bearer };
|
enum AuthType { OAuth, Bearer };
|
||||||
|
|
||||||
Auth();
|
Auth();
|
||||||
Auth(Key _key);
|
Auth(Key _key);
|
||||||
authorize(const bool app_only);
|
authorize(const bool app_only);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Key key_;
|
Key key_;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // namespace CocoaTweet::Authentication
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -36,8 +36,8 @@ std::string join(const std::vector<std::string> _vec, const std::string& _delim)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unordered_map<std::string, std::string> parse(const std::string str, const char _delim,
|
||||||
std::unordered_map<std::string, std::string> parse(const std::string str, const char _delim, const char _conn){
|
const char _conn) {
|
||||||
int first = 0;
|
int first = 0;
|
||||||
int last = str.find_first_of(_delim);
|
int last = str.find_first_of(_delim);
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
@@ -50,13 +50,13 @@ std::unordered_map<std::string, std::string> parse(const std::string str, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto mp = std::unordered_map<std::string, std::string>();
|
auto mp = std::unordered_map<std::string, std::string>();
|
||||||
for(auto elm: result){
|
for (auto elm : result) {
|
||||||
int pos = elm.find_first_of(_conn);
|
int pos = elm.find_first_of(_conn);
|
||||||
|
|
||||||
std::cout << pos << std::endl;
|
std::cout << pos << std::endl;
|
||||||
if(pos == std::string::npos){
|
if (pos == std::string::npos) {
|
||||||
mp.insert_or_assign(elm, "");
|
mp.insert_or_assign(elm, "");
|
||||||
}else{
|
} else {
|
||||||
auto key = elm.substr(0, pos);
|
auto key = elm.substr(0, pos);
|
||||||
auto val = elm.substr(pos + 1);
|
auto val = elm.substr(pos + 1);
|
||||||
mp.insert_or_assign(key, val);
|
mp.insert_or_assign(key, val);
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
namespace CocoaTweet::Util {
|
namespace CocoaTweet::Util {
|
||||||
std::string urlEncode(const std::string& _str);
|
std::string urlEncode(const std::string& _str);
|
||||||
std::string join(const std::vector<std::string> _vec, const std::string& _delim);
|
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
|
} // namespace CocoaTweet::Util
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+30
-7
@@ -2,35 +2,58 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cocoatweet/exception/exception.h>
|
#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 {
|
auto main() -> int {
|
||||||
// Generate Key object
|
// Generate Key object
|
||||||
// auto consumerKey = "your consumer key";
|
// auto consumerKey = "your consumer key";
|
||||||
// auto consumerSecret = "your consumer secret";
|
// auto consumerSecret = "your consumer secret";
|
||||||
// auto accessToken = "your access token";
|
// auto accessToken = "your access token";
|
||||||
// auto accessTokenSecret = "your access token secret";
|
// auto accessTokenSecret = "your access token secret";
|
||||||
// CocoaTweet::OAuth::Key key = CocoaTweet::OAuth::Key(consumerKey,
|
// CocoaTweet::Authentication::Key key = CocoaTweet::Authentication::Key(consumerKey,
|
||||||
// consumerSecret,
|
// consumerSecret,
|
||||||
// accessToken,
|
// accessToken,
|
||||||
// accessTokenSecret);
|
// accessTokenSecret);
|
||||||
|
|
||||||
|
try {
|
||||||
// also can generate Key object from JSON file
|
// also can generate Key object from JSON file
|
||||||
// CocoaTweet::OAuth::Key key = CocoaTweet::OAuth::Key::fromJsonFile("api_key.json");
|
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
|
// Generate API Entry object using Key object
|
||||||
// CocoaTweet::API::API api(key);
|
CocoaTweet::API::API api(key);
|
||||||
|
auto bearerToken = api.oauth2().token();
|
||||||
|
key.bearerToken(bearerToken);
|
||||||
|
key.authType(CocoaTweet::Authentication::Key::AUTH_TYPE::OAUTH2);
|
||||||
|
api.swapKey(key);
|
||||||
|
|
||||||
|
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;
|
// 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
|
// NOTE: call this, always authenticate with Bearer Token, which is Read Only Token
|
||||||
// try {
|
// try {
|
||||||
// api.generateBearerToken();
|
// api.generateBearerToken();
|
||||||
|
|
||||||
// Now, you can use a twitter api
|
// 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().create(status.id());
|
||||||
// api.favorite().destroy(status.id());
|
// api.favorite().destroy(status.id());
|
||||||
// api.status().destroy(status.id());
|
// api.status().destroy(status.id());
|
||||||
// auto timeline = api.status().userTimeline("milkcocoa0902");
|
// auto timeline = api.status().userTimeline("milkcocoa0902");
|
||||||
// } catch (CocoaTweet::Exception::Exception e) {
|
} catch (CocoaTweet::Exception::Exception e) {
|
||||||
// std::cout << e.what() << std::endl;
|
std::cout << e.what() << std::endl;
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user