From 68d6d478c60485d2dc34ef42a5ea0eb803343020 Mon Sep 17 00:00:00 2001 From: keita Date: Thu, 18 Feb 2021 18:38:01 +0900 Subject: [PATCH] =?UTF-8?q?statuses/destroy=E3=82=92=E5=8F=A9=E3=81=8F?= =?UTF-8?q?=E3=82=84=E3=81=A4=E3=82=92=E5=8F=8D=E6=98=A0=E3=81=97=E3=81=9F?= =?UTF-8?q?=20=E3=81=BE=E3=81=9F=EF=BC=8CCocoaTweet::Util::join()=E3=82=92?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cocoatweet/api/interface/postInterface.cc | 23 +++++++++++-------- src/cocoatweet/api/status/status.cc | 7 ++++++ src/cocoatweet/api/status/status.h | 1 + src/cocoatweet/oauth/oauth.cc | 15 ++++++++---- src/cocoatweet/util/util.cc | 16 +++++++++++-- src/cocoatweet/util/util.h | 3 +-- 6 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/cocoatweet/api/interface/postInterface.cc b/src/cocoatweet/api/interface/postInterface.cc index 35b921b..cd3a883 100644 --- a/src/cocoatweet/api/interface/postInterface.cc +++ b/src/cocoatweet/api/interface/postInterface.cc @@ -40,10 +40,14 @@ void postInterface::process(std::weak_ptr _oauth, for (const auto& [key, value] : bodyParam_) { tmp.push_back(key + "=" + value); } - std::stringstream os; - std::copy(tmp.begin(), tmp.end(), std::ostream_iterator(os, "&")); - requestBody = os.str(); - requestBody.erase(requestBody.size() - std::char_traits::length("&")); + + /*for(auto v : tmp){ + requestBody += (v + "&"); + } + if(!requestBody.empty()){ + requestBody.pop_back(); + }*/ + requestBody = CocoaTweet::Util::join(tmp, "&"); } std::cout << "request Body -> " << requestBody << std::endl; @@ -54,10 +58,7 @@ void postInterface::process(std::weak_ptr _oauth, for (const auto& [key, value] : oauthParam) { tmp.push_back(key + "=" + CocoaTweet::Util::urlEncode(value)); } - std::stringstream os; - std::copy(tmp.begin(), tmp.end(), std::ostream_iterator(os, ",")); - oauthHeader += os.str(); - oauthHeader.erase(oauthHeader.size() - std::char_traits::length(",")); + oauthHeader += CocoaTweet::Util::join(tmp, ","); } std::cout << "OAuth Header -> " << oauthHeader << std::endl; @@ -71,8 +72,10 @@ void postInterface::process(std::weak_ptr _oauth, if (curl) { curl_easy_setopt(curl, CURLOPT_URL, url_.c_str()); curl_easy_setopt(curl, CURLOPT_POST, 1); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, requestBody.c_str()); - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, requestBody.length()); + // if(!requestBody.empty()){ + curl_easy_setopt(curl, CURLOPT_POSTFIELDS, requestBody.c_str()); + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, requestBody.length()); +// } curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlCallback_); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (std::string*)&rcv); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); diff --git a/src/cocoatweet/api/status/status.cc b/src/cocoatweet/api/status/status.cc index 928a30c..6390ac2 100644 --- a/src/cocoatweet/api/status/status.cc +++ b/src/cocoatweet/api/status/status.cc @@ -2,6 +2,7 @@ #include "cocoatweet/api/status/status.h" #include "cocoatweet/api/status/update.h" +#include "cocoatweet/api/status/destroy.h" namespace CocoaTweet::API::Statuses { Status::Status(std::shared_ptr _oauth) { @@ -13,4 +14,10 @@ void Status::Update(const std::string& _status) const { update.status(_status); 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 diff --git a/src/cocoatweet/api/status/status.h b/src/cocoatweet/api/status/status.h index 9c16931..7dec316 100644 --- a/src/cocoatweet/api/status/status.h +++ b/src/cocoatweet/api/status/status.h @@ -10,6 +10,7 @@ public: Status() = default; Status(std::shared_ptr _oauth); void Update(const std::string& _status) const; + void Destroy(const std::string& _id) const; private: }; diff --git a/src/cocoatweet/oauth/oauth.cc b/src/cocoatweet/oauth/oauth.cc index 1fdd1fd..4c82f6d 100644 --- a/src/cocoatweet/oauth/oauth.cc +++ b/src/cocoatweet/oauth/oauth.cc @@ -28,10 +28,17 @@ std::map OAuth1::signature( tmp.push_back(key + "=" + value); std::cout << (key + "=" + value) << std::endl; } - std::ostringstream os; - std::copy(tmp.begin(), tmp.end(), std::ostream_iterator(os, "&")); - std::string query = os.str(); - query.erase(query.size() - std::char_traits::length("&")); + //std::ostringstream os; + //std::copy(tmp.begin(), tmp.end(), std::ostream_iterator(os, "&")); + //std::string query = os.str(); + /*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 significateBase = _method + "&" + CocoaTweet::Util::urlEncode(_url) + "&" + diff --git a/src/cocoatweet/util/util.cc b/src/cocoatweet/util/util.cc index 1ebfe89..d8b5df3 100644 --- a/src/cocoatweet/util/util.cc +++ b/src/cocoatweet/util/util.cc @@ -19,6 +19,18 @@ std::string urlEncode(const std::string& _str) { return out.str(); } -template -std::string join(const std::vector _vec) {} +std::string join(const std::vector _vec, const std::string& _delim) { + std::string str(""); + + for(auto v : _vec){ + str += (v + _delim); + } + + if(!str.empty()){ + str.pop_back(); + } + + return str; + +} } // namespace CocoaTweet::Util diff --git a/src/cocoatweet/util/util.h b/src/cocoatweet/util/util.h index f8202fc..a35e2f0 100644 --- a/src/cocoatweet/util/util.h +++ b/src/cocoatweet/util/util.h @@ -7,8 +7,7 @@ namespace CocoaTweet::Util { std::string urlEncode(const std::string& _str); -template -std::string join(const std::vector _vec); +std::string join(const std::vector _vec, const std::string& _delim); } // namespace CocoaTweet::Util #endif