statuses/destroyを叩くやつを反映した

また,CocoaTweet::Util::join()を使用するようにした
This commit is contained in:
keita
2021-02-18 18:38:01 +09:00
parent d6a277f8fe
commit 68d6d478c6
6 changed files with 47 additions and 18 deletions
+11 -8
View File
@@ -40,10 +40,14 @@ void postInterface::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
for (const auto& [key, value] : bodyParam_) { for (const auto& [key, value] : bodyParam_) {
tmp.push_back(key + "=" + value); tmp.push_back(key + "=" + value);
} }
std::stringstream os;
std::copy(tmp.begin(), tmp.end(), std::ostream_iterator<std::string>(os, "&")); /*for(auto v : tmp){
requestBody = os.str(); requestBody += (v + "&");
requestBody.erase(requestBody.size() - std::char_traits<char>::length("&")); }
if(!requestBody.empty()){
requestBody.pop_back();
}*/
requestBody = CocoaTweet::Util::join(tmp, "&");
} }
std::cout << "request Body -> " << requestBody << std::endl; std::cout << "request Body -> " << requestBody << std::endl;
@@ -54,10 +58,7 @@ void postInterface::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
for (const auto& [key, value] : oauthParam) { for (const auto& [key, value] : oauthParam) {
tmp.push_back(key + "=" + CocoaTweet::Util::urlEncode(value)); tmp.push_back(key + "=" + CocoaTweet::Util::urlEncode(value));
} }
std::stringstream os; oauthHeader += CocoaTweet::Util::join(tmp, ",");
std::copy(tmp.begin(), tmp.end(), std::ostream_iterator<std::string>(os, ","));
oauthHeader += os.str();
oauthHeader.erase(oauthHeader.size() - std::char_traits<char>::length(","));
} }
std::cout << "OAuth Header -> " << oauthHeader << std::endl; std::cout << "OAuth Header -> " << oauthHeader << std::endl;
@@ -71,8 +72,10 @@ void postInterface::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
if (curl) { if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url_.c_str()); curl_easy_setopt(curl, CURLOPT_URL, url_.c_str());
curl_easy_setopt(curl, CURLOPT_POST, 1); curl_easy_setopt(curl, CURLOPT_POST, 1);
// if(!requestBody.empty()){
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, requestBody.c_str()); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, requestBody.c_str());
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, requestBody.length()); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, requestBody.length());
// }
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlCallback_); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlCallback_);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (std::string*)&rcv); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (std::string*)&rcv);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+7
View File
@@ -2,6 +2,7 @@
#include "cocoatweet/api/status/status.h" #include "cocoatweet/api/status/status.h"
#include "cocoatweet/api/status/update.h" #include "cocoatweet/api/status/update.h"
#include "cocoatweet/api/status/destroy.h"
namespace CocoaTweet::API::Statuses { namespace CocoaTweet::API::Statuses {
Status::Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) { Status::Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth) {
@@ -13,4 +14,10 @@ void Status::Update(const std::string& _status) const {
update.status(_status); update.status(_status);
update.process(oauth_, [](std::string _rcv) { std::cout << _rcv << std::endl; }); update.process(oauth_, [](std::string _rcv) { std::cout << _rcv << std::endl; });
} }
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; });
}
} // namespace CocoaTweet::API::Statuses } // namespace CocoaTweet::API::Statuses
+1
View File
@@ -10,6 +10,7 @@ public:
Status() = default; Status() = default;
Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth); Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
void Update(const std::string& _status) const; void Update(const std::string& _status) const;
void Destroy(const std::string& _id) const;
private: private:
}; };
+11 -4
View File
@@ -28,10 +28,17 @@ std::map<std::string, std::string> OAuth1::signature(
tmp.push_back(key + "=" + value); tmp.push_back(key + "=" + value);
std::cout << (key + "=" + value) << std::endl; std::cout << (key + "=" + value) << std::endl;
} }
std::ostringstream os; //std::ostringstream os;
std::copy(tmp.begin(), tmp.end(), std::ostream_iterator<std::string>(os, "&")); //std::copy(tmp.begin(), tmp.end(), std::ostream_iterator<std::string>(os, "&"));
std::string query = os.str(); //std::string query = os.str();
query.erase(query.size() - std::char_traits<char>::length("&")); /*std::string query = "";
for(auto v : tmp){
query += (v + "&");
}
if(!query.empty()){
query.pop_back();
}*/
std::string query = CocoaTweet::Util::join(tmp, "&");
auto significateKey = key().consumerSecret() + "&" + key().accessTokenSecret(); auto significateKey = key().consumerSecret() + "&" + key().accessTokenSecret();
auto significateBase = _method + "&" + CocoaTweet::Util::urlEncode(_url) + "&" + auto significateBase = _method + "&" + CocoaTweet::Util::urlEncode(_url) + "&" +
+14 -2
View File
@@ -19,6 +19,18 @@ std::string urlEncode(const std::string& _str) {
return out.str(); return out.str();
} }
template <typename T> std::string join(const std::vector<std::string> _vec, const std::string& _delim) {
std::string join(const std::vector<T> _vec) {} std::string str("");
for(auto v : _vec){
str += (v + _delim);
}
if(!str.empty()){
str.pop_back();
}
return str;
}
} // namespace CocoaTweet::Util } // namespace CocoaTweet::Util
+1 -2
View File
@@ -7,8 +7,7 @@
namespace CocoaTweet::Util { namespace CocoaTweet::Util {
std::string urlEncode(const std::string& _str); std::string urlEncode(const std::string& _str);
template <typename T> std::string join(const std::vector<std::string> _vec, const std::string& _delim);
std::string join(const std::vector<T> _vec);
} // namespace CocoaTweet::Util } // namespace CocoaTweet::Util
#endif #endif