Fixed compatibility for HTTPClient Library. (HTTPClient by Donatien Garnier)

Dependents:   FlashAir_Twitter CyaSSL-Twitter-OAuth4Tw TweetTest NetworkThermometer ... more

Fork of OAuth4Tw by Masayoshi Takahashi

Files at this revision

API Documentation at this revision

Comitter:
ban4jp
Date:
Tue Jul 14 09:31:13 2015 +0000
Parent:
4:1ecf49a46040
Commit message:
Fixed argument of post method.

Changed in this revision

OAuth4Tw.cpp Show annotated file Show diff for this revision Revisions of this file
OAuth4Tw.h Show annotated file Show diff for this revision Revisions of this file
twicpps/oauth.h Show annotated file Show diff for this revision Revisions of this file
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;
+}
diff -r 1ecf49a46040 -r 5146becb651f OAuth4Tw.h
--- a/OAuth4Tw.h	Wed Jul 08 14:32:26 2015 +0000
+++ b/OAuth4Tw.h	Tue Jul 14 09:31:13 2015 +0000
@@ -3,6 +3,7 @@
 
 #include "mbed.h"
 #include "HTTPClient.h"
+#include <vector>
 #include <string>
 
 class OAuth4Tw
@@ -13,9 +14,10 @@
 
     static std::string url_escape(const char *str);
 
-    HTTPResult get(const char *uri, IHTTPDataIn* response, int timeout = HTTP_CLIENT_DEFAULT_TIMEOUT);
+    HTTPResult get(const char *url, IHTTPDataIn* response, int timeout = HTTP_CLIENT_DEFAULT_TIMEOUT);
 
-    HTTPResult post(const char *uri, std::string postargs, IHTTPDataIn* response, int timeout = HTTP_CLIENT_DEFAULT_TIMEOUT);
+    HTTPResult post(const char *url, IHTTPDataIn* response, int timeout = HTTP_CLIENT_DEFAULT_TIMEOUT);
+    HTTPResult post(const char *url, std::vector<std::string> *postdata, IHTTPDataIn* response, int timeout = HTTP_CLIENT_DEFAULT_TIMEOUT);
 
 private:
     const char *consumer_key;
diff -r 1ecf49a46040 -r 5146becb651f twicpps/oauth.h
--- a/twicpps/oauth.h	Wed Jul 08 14:32:26 2015 +0000
+++ b/twicpps/oauth.h	Tue Jul 14 09:31:13 2015 +0000
@@ -196,7 +196,7 @@
  * 
  * @return number of parameter(s) in array.
  */
-void oauth_split_url_parameters(const char *url, char ***argv);
+void oauth_split_url_parameters(const char *url, std::vector<std::string> *argv);
 
 /**
  * splits the given url into a parameter array. 
@@ -212,7 +212,7 @@
  * 
  * @return number of parameter(s) in array.
  */
-void oauth_split_post_paramters(const char *url, char ***argv, short qesc);
+void oauth_split_post_paramters(const char *url, std::vector<std::string> *argv, short qesc);
 
 /**
  * build a url query string from an array.