Fixed compatibility for HTTPClient Library. (HTTPClient by Donatien Garnier)
Dependents: FlashAir_Twitter CyaSSL-Twitter-OAuth4Tw TweetTest NetworkThermometer ... more
Fork of OAuth4Tw by
OAuth4Tw.cpp@4:1ecf49a46040, 2015-07-08 (annotated)
- Committer:
- ban4jp
- Date:
- Wed Jul 08 14:32:26 2015 +0000
- Revision:
- 4:1ecf49a46040
- Parent:
- 3:c28b796ef7ed
- Child:
- 5:5146becb651f
Add GET method, and changed the API.
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 | 4:1ecf49a46040 | 20 | HTTPResult OAuth4Tw::get(const char *uri, 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 | 4:1ecf49a46040 | 24 | req_url = oauth_sign_url2(uri, 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 | 4:1ecf49a46040 | 34 | HTTPResult OAuth4Tw::post(const char *uri, std::string postargs, IHTTPDataIn *response, int timeout /*= HTTP_CLIENT_DEFAULT_TIMEOUT*/) |
ban4jp | 4:1ecf49a46040 | 35 | { |
ban4jp | 4:1ecf49a46040 | 36 | std::string req_url; |
ban4jp | 4:1ecf49a46040 | 37 | |
ban4jp | 4:1ecf49a46040 | 38 | req_url = oauth_sign_url2(uri, &postargs, OA_HMAC, 0, |
ban4jp | 4:1ecf49a46040 | 39 | consumer_key, consumer_secret, |
ban4jp | 4:1ecf49a46040 | 40 | token_key, token_secret); |
ban4jp | 4:1ecf49a46040 | 41 | |
ban4jp | 4:1ecf49a46040 | 42 | const char *poststr = postargs.c_str(); |
ban4jp | 4:1ecf49a46040 | 43 | |
ban4jp | 4:1ecf49a46040 | 44 | HTTPClient http; |
ban4jp | 4:1ecf49a46040 | 45 | HTTPPostText request((char *)poststr, strlen(poststr) + 1); |
ban4jp | 4:1ecf49a46040 | 46 | HTTPResult r = http.post(req_url.c_str(), request, response); |
ban4jp | 4:1ecf49a46040 | 47 | |
ban4jp | 4:1ecf49a46040 | 48 | return r; |
ban4jp | 4:1ecf49a46040 | 49 | } |