Fixed compatibility for HTTPClient Library. (HTTPClient by Donatien Garnier)
Dependents: FlashAir_Twitter CyaSSL-Twitter-OAuth4Tw TweetTest NetworkThermometer ... more
Fork of OAuth4Tw by
OAuth4Tw.cpp@5:5146becb651f, 2015-07-14 (annotated)
- Committer:
- ban4jp
- Date:
- Tue Jul 14 09:31:13 2015 +0000
- Revision:
- 5:5146becb651f
- Parent:
- 4:1ecf49a46040
Fixed argument of post method.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takahashim | 0:0048b264a3ad | 1 | #include "OAuth4Tw.h" |
takahashim | 0:0048b264a3ad | 2 | #include "mbed.h" |
ban4jp | 3:c28b796ef7ed | 3 | #include "twicpps/oauth.h" |
ban4jp | 3:c28b796ef7ed | 4 | |
ban4jp | 3:c28b796ef7ed | 5 | #include <HTTPClient.h> |
ban4jp | 3:c28b796ef7ed | 6 | #include "HTTPPostText.h" |
ban4jp | 3:c28b796ef7ed | 7 | |
takahashim | 0:0048b264a3ad | 8 | OAuth4Tw::OAuth4Tw(const char *c_key, const char *c_secret, |
ban4jp | 4:1ecf49a46040 | 9 | const char *t_key, const char *t_secret) |
ban4jp | 4:1ecf49a46040 | 10 | :consumer_key(c_key), |
takahashim | 0:0048b264a3ad | 11 | consumer_secret(c_secret), |
takahashim | 0:0048b264a3ad | 12 | token_key(t_key), |
takahashim | 0:0048b264a3ad | 13 | token_secret(t_secret) { } |
takahashim | 0:0048b264a3ad | 14 | |
ban4jp | 4:1ecf49a46040 | 15 | std::string OAuth4Tw::url_escape(const char *str) |
ban4jp | 4:1ecf49a46040 | 16 | { |
takahashim | 0:0048b264a3ad | 17 | return oauth_url_escape(str); |
takahashim | 0:0048b264a3ad | 18 | } |
takahashim | 0:0048b264a3ad | 19 | |
ban4jp | 5:5146becb651f | 20 | HTTPResult OAuth4Tw::get(const char *url, IHTTPDataIn *response, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/) |
ban4jp | 4:1ecf49a46040 | 21 | { |
takahashim | 0:0048b264a3ad | 22 | std::string req_url; |
takahashim | 0:0048b264a3ad | 23 | |
ban4jp | 5:5146becb651f | 24 | req_url = oauth_sign_url2(url, NULL, OA_HMAC, 0, |
ban4jp | 4:1ecf49a46040 | 25 | consumer_key, consumer_secret, |
ban4jp | 4:1ecf49a46040 | 26 | token_key, token_secret); |
ban4jp | 4:1ecf49a46040 | 27 | |
ban4jp | 3:c28b796ef7ed | 28 | HTTPClient http; |
ban4jp | 4:1ecf49a46040 | 29 | HTTPResult r = http.get(req_url.c_str(), response); |
ban4jp | 3:c28b796ef7ed | 30 | |
ban4jp | 4:1ecf49a46040 | 31 | return r; |
takahashim | 0:0048b264a3ad | 32 | } |
takahashim | 0:0048b264a3ad | 33 | |
ban4jp | 5:5146becb651f | 34 | HTTPResult OAuth4Tw::post(const char *url, IHTTPDataIn *response, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/) |
ban4jp | 4:1ecf49a46040 | 35 | { |
ban4jp | 4:1ecf49a46040 | 36 | std::string req_url; |
ban4jp | 5:5146becb651f | 37 | std::string postargs; |
ban4jp | 4:1ecf49a46040 | 38 | |
ban4jp | 5:5146becb651f | 39 | req_url = oauth_sign_url2(url, &postargs, OA_HMAC, 0, |
ban4jp | 4:1ecf49a46040 | 40 | consumer_key, consumer_secret, |
ban4jp | 4:1ecf49a46040 | 41 | token_key, token_secret); |
ban4jp | 4:1ecf49a46040 | 42 | |
ban4jp | 4:1ecf49a46040 | 43 | const char *poststr = postargs.c_str(); |
ban4jp | 4:1ecf49a46040 | 44 | |
ban4jp | 4:1ecf49a46040 | 45 | HTTPClient http; |
ban4jp | 4:1ecf49a46040 | 46 | HTTPPostText request((char *)poststr, strlen(poststr) + 1); |
ban4jp | 4:1ecf49a46040 | 47 | HTTPResult r = http.post(req_url.c_str(), request, response); |
ban4jp | 4:1ecf49a46040 | 48 | |
ban4jp | 4:1ecf49a46040 | 49 | return r; |
ban4jp | 4:1ecf49a46040 | 50 | } |
ban4jp | 5:5146becb651f | 51 | |
ban4jp | 5:5146becb651f | 52 | HTTPResult OAuth4Tw::post(const char *url, std::vector<std::string> *postdata, IHTTPDataIn *response, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/) |
ban4jp | 5:5146becb651f | 53 | { |
ban4jp | 5:5146becb651f | 54 | std::string req_url; |
ban4jp | 5:5146becb651f | 55 | std::string postargs; |
ban4jp | 5:5146becb651f | 56 | |
ban4jp | 5:5146becb651f | 57 | { |
ban4jp | 5:5146becb651f | 58 | std::vector<std::string> argv; |
ban4jp | 5:5146becb651f | 59 | argv.reserve(postdata->size()+8); |
ban4jp | 5:5146becb651f | 60 | |
ban4jp | 5:5146becb651f | 61 | oauth_split_post_paramters(url, &argv, 0); |
ban4jp | 5:5146becb651f | 62 | for (int i=0; i<postdata->size(); i++) { |
ban4jp | 5:5146becb651f | 63 | argv.push_back(postdata->at(i)); |
ban4jp | 5:5146becb651f | 64 | } |
ban4jp | 5:5146becb651f | 65 | |
ban4jp | 5:5146becb651f | 66 | req_url = oauth_sign_array2(&argv, &postargs, OA_HMAC, 0, |
ban4jp | 5:5146becb651f | 67 | consumer_key, consumer_secret, |
ban4jp | 5:5146becb651f | 68 | token_key, token_secret); |
ban4jp | 5:5146becb651f | 69 | |
ban4jp | 5:5146becb651f | 70 | #if 0 |
ban4jp | 5:5146becb651f | 71 | for (int i=0; i<argv.size(); i++) { |
ban4jp | 5:5146becb651f | 72 | printf("param[%d]: %s\n", i, argv.at(i).c_str()); |
ban4jp | 5:5146becb651f | 73 | } |
ban4jp | 5:5146becb651f | 74 | #endif |
ban4jp | 5:5146becb651f | 75 | } |
ban4jp | 5:5146becb651f | 76 | |
ban4jp | 5:5146becb651f | 77 | const char *poststr = postargs.c_str(); |
ban4jp | 5:5146becb651f | 78 | |
ban4jp | 5:5146becb651f | 79 | HTTPClient http; |
ban4jp | 5:5146becb651f | 80 | HTTPPostText request((char *)poststr, strlen(poststr) + 1); |
ban4jp | 5:5146becb651f | 81 | HTTPResult r = http.post(req_url.c_str(), request, response); |
ban4jp | 5:5146becb651f | 82 | |
ban4jp | 5:5146becb651f | 83 | return r; |
ban4jp | 5:5146becb651f | 84 | } |