Fixed compatibility for HTTPClient Library. (HTTPClient by Donatien Garnier)
Dependents: FlashAir_Twitter CyaSSL-Twitter-OAuth4Tw TweetTest NetworkThermometer ... more
Fork of OAuth4Tw by
Diff: OAuth4Tw.cpp
- Revision:
- 5:5146becb651f
- Parent:
- 4:1ecf49a46040
diff -r 1ecf49a46040 -r 5146becb651f OAuth4Tw.cpp
--- a/OAuth4Tw.cpp Wed Jul 08 14:32:26 2015 +0000
+++ b/OAuth4Tw.cpp Tue Jul 14 09:31:13 2015 +0000
@@ -17,11 +17,11 @@
return oauth_url_escape(str);
}
-HTTPResult OAuth4Tw::get(const char *uri, IHTTPDataIn *response, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/)
+HTTPResult OAuth4Tw::get(const char *url, IHTTPDataIn *response, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/)
{
std::string req_url;
- req_url = oauth_sign_url2(uri, NULL, OA_HMAC, 0,
+ req_url = oauth_sign_url2(url, NULL, OA_HMAC, 0,
consumer_key, consumer_secret,
token_key, token_secret);
@@ -31,11 +31,12 @@
return r;
}
-HTTPResult OAuth4Tw::post(const char *uri, std::string postargs, IHTTPDataIn *response, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/)
+HTTPResult OAuth4Tw::post(const char *url, IHTTPDataIn *response, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/)
{
std::string req_url;
+ std::string postargs;
- req_url = oauth_sign_url2(uri, &postargs, OA_HMAC, 0,
+ req_url = oauth_sign_url2(url, &postargs, OA_HMAC, 0,
consumer_key, consumer_secret,
token_key, token_secret);
@@ -47,3 +48,37 @@
return r;
}
+
+HTTPResult OAuth4Tw::post(const char *url, std::vector<std::string> *postdata, IHTTPDataIn *response, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/)
+{
+ std::string req_url;
+ std::string postargs;
+
+ {
+ std::vector<std::string> argv;
+ argv.reserve(postdata->size()+8);
+
+ oauth_split_post_paramters(url, &argv, 0);
+ for (int i=0; i<postdata->size(); i++) {
+ argv.push_back(postdata->at(i));
+ }
+
+ req_url = oauth_sign_array2(&argv, &postargs, OA_HMAC, 0,
+ consumer_key, consumer_secret,
+ token_key, token_secret);
+
+#if 0
+ for (int i=0; i<argv.size(); i++) {
+ printf("param[%d]: %s\n", i, argv.at(i).c_str());
+ }
+#endif
+ }
+
+ const char *poststr = postargs.c_str();
+
+ HTTPClient http;
+ HTTPPostText request((char *)poststr, strlen(poststr) + 1);
+ HTTPResult r = http.post(req_url.c_str(), request, response);
+
+ return r;
+}
ban4jp -
