interface周りの負債を改善
This commit is contained in:
@@ -2,10 +2,15 @@
|
|||||||
|
|
||||||
namespace CocoaTweet::API::Favorites {
|
namespace CocoaTweet::API::Favorites {
|
||||||
Create::Create() {
|
Create::Create() {
|
||||||
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
url_ = "https://api.twitter.com/1.1/favorites/create.json";
|
url_ = "https://api.twitter.com/1.1/favorites/create.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Create::id(const std::string& _id) {
|
void Create::id(const std::string& _id) {
|
||||||
bodyParam_.insert_or_assign("id", _id);
|
bodyParam_.insert_or_assign("id", _id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Create::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth){
|
||||||
|
postInterface::process(_oauth, [](const std::string& _srv){std::cout << _srv << std::endl;});
|
||||||
|
}
|
||||||
} // namespace CocoaTweet::API::Favorites
|
} // namespace CocoaTweet::API::Favorites
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class Create : public CocoaTweet::API::Interface::postInterface {
|
|||||||
public:
|
public:
|
||||||
Create();
|
Create();
|
||||||
void id(const std::string& _id);
|
void id(const std::string& _id);
|
||||||
|
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,10 +2,15 @@
|
|||||||
|
|
||||||
namespace CocoaTweet::API::Favorites {
|
namespace CocoaTweet::API::Favorites {
|
||||||
Destroy::Destroy() {
|
Destroy::Destroy() {
|
||||||
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
url_ = "https://api.twitter.com/1.1/favorites/destroy.json";
|
url_ = "https://api.twitter.com/1.1/favorites/destroy.json";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Destroy::id(const std::string& _id) {
|
void Destroy::id(const std::string& _id) {
|
||||||
bodyParam_.insert_or_assign("id", _id);
|
bodyParam_.insert_or_assign("id", _id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Destroy::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth){
|
||||||
|
postInterface::process(_oauth, [](const std::string& _srv){std::cout << _srv << std::endl;});
|
||||||
|
}
|
||||||
} // namespace CocoaTweet::API::Favorites
|
} // namespace CocoaTweet::API::Favorites
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class Destroy : public CocoaTweet::API::Interface::postInterface {
|
|||||||
public:
|
public:
|
||||||
Destroy();
|
Destroy();
|
||||||
void id(const std::string& _id);
|
void id(const std::string& _id);
|
||||||
|
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ Favorite::Favorite(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
|||||||
void Favorite::Create(const std::string& _id) const {
|
void Favorite::Create(const std::string& _id) const {
|
||||||
CocoaTweet::API::Favorites::Create create;
|
CocoaTweet::API::Favorites::Create create;
|
||||||
create.id(_id);
|
create.id(_id);
|
||||||
create.process(oauth_, [](std::string _rcv) { std::cout << _rcv << std::endl; });
|
create.process(oauth_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Favorite::Destroy(const std::string& _id) const {
|
void Favorite::Destroy(const std::string& _id) const {
|
||||||
CocoaTweet::API::Favorites::Destroy destroy;
|
CocoaTweet::API::Favorites::Destroy destroy;
|
||||||
destroy.id(_id);
|
destroy.id(_id);
|
||||||
destroy.process(oauth_, [](std::string _rcv) { std::cout << _rcv << std::endl; });
|
destroy.process(oauth_);
|
||||||
}
|
}
|
||||||
} // namespace CocoaTweet::API::Favorites
|
} // namespace CocoaTweet::API::Favorites
|
||||||
|
|||||||
@@ -23,8 +23,10 @@ void postInterface::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|||||||
auto oauth = _oauth.lock();
|
auto oauth = _oauth.lock();
|
||||||
auto oauthParam = oauth->oauthParam();
|
auto oauthParam = oauth->oauthParam();
|
||||||
auto sigingParam = oauthParam;
|
auto sigingParam = oauthParam;
|
||||||
for (const auto [k, v] : bodyParam_) {
|
if(contentType_ == "application/x-www-form-urlencoded"){
|
||||||
sigingParam.insert_or_assign(k, v);
|
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_);
|
||||||
|
|||||||
@@ -3,17 +3,19 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "cocoatweet/oauth/oauth.h"
|
#include "cocoatweet/oauth/oauth.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace CocoaTweet::API::Interface {
|
namespace CocoaTweet::API::Interface {
|
||||||
class postInterface {
|
class postInterface {
|
||||||
public:
|
public:
|
||||||
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
|
||||||
std::function<void(std::string)> _callback);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::weak_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
std::weak_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
|
||||||
std::map<std::string, std::string> bodyParam_;
|
std::map<std::string, std::string> bodyParam_;
|
||||||
std::string url_;
|
std::string url_;
|
||||||
|
std::string contentType_;
|
||||||
|
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||||
|
std::function<void(std::string)> _callback);
|
||||||
static size_t curlCallback_(char* _ptr, size_t _size, size_t _nmemb, std::string* _stream);
|
static size_t curlCallback_(char* _ptr, size_t _size, size_t _nmemb, std::string* _stream);
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Interface
|
} // namespace CocoaTweet::API::Interface
|
||||||
|
|||||||
@@ -3,7 +3,12 @@
|
|||||||
namespace CocoaTweet::API::Statuses {
|
namespace CocoaTweet::API::Statuses {
|
||||||
Destroy::Destroy() {}
|
Destroy::Destroy() {}
|
||||||
void Destroy::id(const std::string _id) {
|
void Destroy::id(const std::string _id) {
|
||||||
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
url_ = "https://api.twitter.com/1.1/statuses/destroy/" + _id + ".json";
|
url_ = "https://api.twitter.com/1.1/statuses/destroy/" + _id + ".json";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Destroy::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth){
|
||||||
|
postInterface::process(_oauth, [](const std::string& _srv){std::cout << _srv << std::endl;});
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class Destroy : public CocoaTweet::API::Interface::postInterface {
|
|||||||
public:
|
public:
|
||||||
Destroy();
|
Destroy();
|
||||||
void id(const std::string _id);
|
void id(const std::string _id);
|
||||||
|
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
};
|
};
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ Status::Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
|
|||||||
void Status::Update(const std::string& _status) const {
|
void Status::Update(const std::string& _status) const {
|
||||||
CocoaTweet::API::Statuses::Update update;
|
CocoaTweet::API::Statuses::Update update;
|
||||||
update.status(_status);
|
update.status(_status);
|
||||||
update.process(oauth_, [](std::string _rcv) { std::cout << _rcv << std::endl; });
|
update.process(oauth_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Status::Destroy(const std::string& _id) const {
|
void Status::Destroy(const std::string& _id) const {
|
||||||
CocoaTweet::API::Statuses::Destroy destroy;
|
CocoaTweet::API::Statuses::Destroy destroy;
|
||||||
destroy.id(_id);
|
destroy.id(_id);
|
||||||
destroy.process(oauth_, [](std::string _rcv) { std::cout << _rcv << std::endl; });
|
destroy.process(oauth_);
|
||||||
}
|
}
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace CocoaTweet::API::Statuses {
|
namespace CocoaTweet::API::Statuses {
|
||||||
Update::Update() {
|
Update::Update() {
|
||||||
|
contentType_ = "application/x-www-form-urlencoded";
|
||||||
url_ = "https://api.twitter.com/1.1/statuses/update.json";
|
url_ = "https://api.twitter.com/1.1/statuses/update.json";
|
||||||
}
|
}
|
||||||
void Update::status(const std::string _status) {
|
void Update::status(const std::string _status) {
|
||||||
@@ -9,4 +10,8 @@ void Update::status(const std::string _status) {
|
|||||||
bodyParam_.insert_or_assign("status", status_);
|
bodyParam_.insert_or_assign("status", status_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Update::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth){
|
||||||
|
postInterface::process(_oauth, [](const std::string& _srv){std::cout << _srv << std::endl;});
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace CocoaTweet::API::Statuses
|
} // namespace CocoaTweet::API::Statuses
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class Update : public CocoaTweet::API::Interface::postInterface {
|
|||||||
public:
|
public:
|
||||||
Update();
|
Update();
|
||||||
void status(const std::string _status);
|
void status(const std::string _status);
|
||||||
|
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string status_;
|
std::string status_;
|
||||||
|
|||||||
Reference in New Issue
Block a user