statuses/destroyを叩くやつを反映した
また,CocoaTweet::Util::join()を使用するようにした
This commit is contained in:
@@ -40,10 +40,14 @@ void postInterface::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||
for (const auto& [key, value] : bodyParam_) {
|
||||
tmp.push_back(key + "=" + value);
|
||||
}
|
||||
std::stringstream os;
|
||||
std::copy(tmp.begin(), tmp.end(), std::ostream_iterator<std::string>(os, "&"));
|
||||
requestBody = os.str();
|
||||
requestBody.erase(requestBody.size() - std::char_traits<char>::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<CocoaTweet::OAuth::OAuth1> _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<std::string>(os, ","));
|
||||
oauthHeader += os.str();
|
||||
oauthHeader.erase(oauthHeader.size() - std::char_traits<char>::length(","));
|
||||
oauthHeader += CocoaTweet::Util::join(tmp, ",");
|
||||
}
|
||||
std::cout << "OAuth Header -> " << oauthHeader << std::endl;
|
||||
|
||||
@@ -71,8 +72,10 @@ void postInterface::process(std::weak_ptr<CocoaTweet::OAuth::OAuth1> _oauth,
|
||||
if (curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url_.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||
// 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);
|
||||
|
||||
@@ -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<CocoaTweet::OAuth::OAuth1> _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
|
||||
|
||||
@@ -10,6 +10,7 @@ public:
|
||||
Status() = default;
|
||||
Status(std::shared_ptr<CocoaTweet::OAuth::OAuth1> _oauth);
|
||||
void Update(const std::string& _status) const;
|
||||
void Destroy(const std::string& _id) const;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
@@ -28,10 +28,17 @@ std::map<std::string, std::string> 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<std::string>(os, "&"));
|
||||
std::string query = os.str();
|
||||
query.erase(query.size() - std::char_traits<char>::length("&"));
|
||||
//std::ostringstream os;
|
||||
//std::copy(tmp.begin(), tmp.end(), std::ostream_iterator<std::string>(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) + "&" +
|
||||
|
||||
@@ -19,6 +19,18 @@ std::string urlEncode(const std::string& _str) {
|
||||
return out.str();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string join(const std::vector<T> _vec) {}
|
||||
std::string join(const std::vector<std::string> _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
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
namespace CocoaTweet::Util {
|
||||
std::string urlEncode(const std::string& _str);
|
||||
template <typename T>
|
||||
std::string join(const std::vector<T> _vec);
|
||||
std::string join(const std::vector<std::string> _vec, const std::string& _delim);
|
||||
} // namespace CocoaTweet::Util
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user