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:
Wed Jul 08 14:32:26 2015 +0000
Parent:
3:c28b796ef7ed
Child:
5:5146becb651f
Commit message:
Add GET method, and changed the API.

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/sha1.c Show annotated file Show diff for this revision Revisions of this file
--- a/OAuth4Tw.cpp	Wed Jul 08 03:52:54 2015 +0000
+++ b/OAuth4Tw.cpp	Wed Jul 08 14:32:26 2015 +0000
@@ -5,34 +5,45 @@
 #include <HTTPClient.h>
 #include "HTTPPostText.h"
 
-static char res_buffer[1024] = "";
-
 OAuth4Tw::OAuth4Tw(const char *c_key, const char *c_secret,
-        const char *t_key, const char *t_secret)
-        :consumer_key(c_key),
+                   const char *t_key, const char *t_secret)
+    :consumer_key(c_key),
      consumer_secret(c_secret),
      token_key(t_key),
      token_secret(t_secret) { }
 
-std::string OAuth4Tw::url_escape(const char *str) {
+std::string OAuth4Tw::url_escape(const char *str)
+{
     return oauth_url_escape(str);
 }
 
-std::string OAuth4Tw::post(const char *uri, std::string postarg) {
-
+HTTPResult OAuth4Tw::get(const char *uri, IHTTPDataIn *response, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/)
+{
     std::string req_url;
-    
-    req_url = oauth_sign_url2(uri, &postarg, OA_HMAC, 0,
-            consumer_key, consumer_secret, token_key, token_secret);
 
-    const char *u = req_url.c_str();
-    const char *p = postarg.c_str();
-    
+    req_url = oauth_sign_url2(uri, NULL, OA_HMAC, 0,
+                              consumer_key, consumer_secret,
+                              token_key, token_secret);
+
     HTTPClient http;
-    HTTPPostText req((char *)p, strlen(p) + 1);
-    HTTPText res(res_buffer, sizeof(res_buffer));
-    http.post(u, req, &res);
+    HTTPResult r = http.get(req_url.c_str(), response);
 
-    return res_buffer;
+    return r;
 }
 
+HTTPResult OAuth4Tw::post(const char *uri, std::string postargs, IHTTPDataIn *response, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/)
+{
+    std::string req_url;
+
+    req_url = oauth_sign_url2(uri, &postargs, OA_HMAC, 0,
+                              consumer_key, consumer_secret,
+                              token_key, token_secret);
+
+    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;
+}
--- a/OAuth4Tw.h	Wed Jul 08 03:52:54 2015 +0000
+++ b/OAuth4Tw.h	Wed Jul 08 14:32:26 2015 +0000
@@ -2,17 +2,21 @@
 #define MBED_OAUTH4TW_H
 
 #include "mbed.h"
+#include "HTTPClient.h"
 #include <string>
 
-class OAuth4Tw {
+class OAuth4Tw
+{
 public:
     OAuth4Tw(const char *c_key, const char *c_secret,
-        const char *t_key, const char *t_secret);
-        
+             const char *t_key, const char *t_secret);
+
     static std::string url_escape(const char *str);
-    
-    std::string post(const char *uri, std::string postarg);
-    
+
+    HTTPResult get(const char *uri, IHTTPDataIn* response, int timeout = HTTP_CLIENT_DEFAULT_TIMEOUT);
+
+    HTTPResult post(const char *uri, std::string postargs, IHTTPDataIn* response, int timeout = HTTP_CLIENT_DEFAULT_TIMEOUT);
+
 private:
     const char *consumer_key;
     const char *consumer_secret;
--- a/twicpps/sha1.c	Wed Jul 08 03:52:54 2015 +0000
+++ b/twicpps/sha1.c	Wed Jul 08 14:32:26 2015 +0000
@@ -31,7 +31,7 @@
 
 #include "sha1.h"
 
-#pragma warning(disable:4244)
+//#pragma warning(disable:4244)
 
 /*
  *  Define the SHA1 circular left shift macro