interface周りの負債を改善

This commit is contained in:
keita
2021-02-20 22:29:49 +09:00
parent a62d0fe7ff
commit 8600dff037
12 changed files with 36 additions and 8 deletions
+5
View File
@@ -2,10 +2,15 @@
namespace CocoaTweet::API::Favorites {
Create::Create() {
contentType_ = "application/x-www-form-urlencoded";
url_ = "https://api.twitter.com/1.1/favorites/create.json";
}
void Create::id(const std::string& _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
+1
View File
@@ -8,6 +8,7 @@ class Create : public CocoaTweet::API::Interface::postInterface {
public:
Create();
void id(const std::string& _id);
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
private:
};
+5
View File
@@ -2,10 +2,15 @@
namespace CocoaTweet::API::Favorites {
Destroy::Destroy() {
contentType_ = "application/x-www-form-urlencoded";
url_ = "https://api.twitter.com/1.1/favorites/destroy.json";
}
void Destroy::id(const std::string& _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
+1
View File
@@ -8,6 +8,7 @@ class Destroy : public CocoaTweet::API::Interface::postInterface {
public:
Destroy();
void id(const std::string& _id);
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
private:
};
+2 -2
View File
@@ -12,12 +12,12 @@ Favorite::Favorite(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
void Favorite::Create(const std::string& _id) const {
CocoaTweet::API::Favorites::Create create;
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 {
CocoaTweet::API::Favorites::Destroy destroy;
destroy.id(_id);
destroy.process(oauth_, [](std::string _rcv) { std::cout << _rcv << std::endl; });
destroy.process(oauth_);
}
} // namespace CocoaTweet::API::Favorites
@@ -23,9 +23,11 @@ void postInterface::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _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 signature = oauth->signature(sigingParam, "POST", url_);
+4 -2
View File
@@ -3,17 +3,19 @@
#include <functional>
#include "cocoatweet/oauth/oauth.h"
#include <iostream>
namespace CocoaTweet::API::Interface {
class postInterface {
public:
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
std::function<void(std::string)> _callback);
protected:
std::weak_ptr<CocoaTweet::OAuth::OAuth1> oauth_;
std::map<std::string, std::string> bodyParam_;
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);
};
} // namespace CocoaTweet::API::Interface
+5
View File
@@ -3,7 +3,12 @@
namespace CocoaTweet::API::Statuses {
Destroy::Destroy() {}
void Destroy::id(const std::string _id) {
contentType_ = "application/x-www-form-urlencoded";
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
+1
View File
@@ -11,6 +11,7 @@ class Destroy : public CocoaTweet::API::Interface::postInterface {
public:
Destroy();
void id(const std::string _id);
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
};
} // namespace CocoaTweet::API::Statuses
+2 -2
View File
@@ -12,12 +12,12 @@ Status::Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
void Status::Update(const std::string& _status) const {
CocoaTweet::API::Statuses::Update update;
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 {
CocoaTweet::API::Statuses::Destroy destroy;
destroy.id(_id);
destroy.process(oauth_, [](std::string _rcv) { std::cout << _rcv << std::endl; });
destroy.process(oauth_);
}
} // namespace CocoaTweet::API::Statuses
+5
View File
@@ -2,6 +2,7 @@
namespace CocoaTweet::API::Statuses {
Update::Update() {
contentType_ = "application/x-www-form-urlencoded";
url_ = "https://api.twitter.com/1.1/statuses/update.json";
}
void Update::status(const std::string _status) {
@@ -9,4 +10,8 @@ void Update::status(const std::string _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
+1
View File
@@ -11,6 +11,7 @@ class Update : public CocoaTweet::API::Interface::postInterface {
public:
Update();
void status(const std::string _status);
void process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
private:
std::string status_;