OAuth library for twitter. Original: http://mbed.org/users/soramimi/programs/Twitter/

Dependents:   OAuth4Tw

Committer:
takahashim
Date:
Mon Dec 12 18:47:10 2011 +0000
Revision:
0:0048b264a3ad
publish library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takahashim 0:0048b264a3ad 1 /*
takahashim 0:0048b264a3ad 2 * OAuth http functions in POSIX-C.
takahashim 0:0048b264a3ad 3 *
takahashim 0:0048b264a3ad 4 * Copyright 2007, 2008, 2009, 2010 Robin Gareus <robin@gareus.org>
takahashim 0:0048b264a3ad 5 *
takahashim 0:0048b264a3ad 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
takahashim 0:0048b264a3ad 7 * of this software and associated documentation files (the "Software"), to deal
takahashim 0:0048b264a3ad 8 * in the Software without restriction, including without limitation the rights
takahashim 0:0048b264a3ad 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
takahashim 0:0048b264a3ad 10 * copies of the Software, and to permit persons to whom the Software is
takahashim 0:0048b264a3ad 11 * furnished to do so, subject to the following conditions:
takahashim 0:0048b264a3ad 12 *
takahashim 0:0048b264a3ad 13 * The above copyright notice and this permission notice shall be included in
takahashim 0:0048b264a3ad 14 * all copies or substantial portions of the Software.
takahashim 0:0048b264a3ad 15 *
takahashim 0:0048b264a3ad 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
takahashim 0:0048b264a3ad 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
takahashim 0:0048b264a3ad 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
takahashim 0:0048b264a3ad 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
takahashim 0:0048b264a3ad 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
takahashim 0:0048b264a3ad 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
takahashim 0:0048b264a3ad 22 * THE SOFTWARE.
takahashim 0:0048b264a3ad 23 *
takahashim 0:0048b264a3ad 24 */
takahashim 0:0048b264a3ad 25 #if HAVE_CONFIG_H
takahashim 0:0048b264a3ad 26 # include <config.h>
takahashim 0:0048b264a3ad 27 #endif
takahashim 0:0048b264a3ad 28
takahashim 0:0048b264a3ad 29 #include <stdio.h>
takahashim 0:0048b264a3ad 30 #include <stdarg.h>
takahashim 0:0048b264a3ad 31 #include <stdlib.h>
takahashim 0:0048b264a3ad 32 #include <string.h>
takahashim 0:0048b264a3ad 33
takahashim 0:0048b264a3ad 34 #include "oauth.h"
takahashim 0:0048b264a3ad 35
takahashim 0:0048b264a3ad 36 #include <HTTPClient.h>
takahashim 0:0048b264a3ad 37
takahashim 0:0048b264a3ad 38 /* wrapper functions */
takahashim 0:0048b264a3ad 39
takahashim 0:0048b264a3ad 40 /**
takahashim 0:0048b264a3ad 41 * do a HTTP POST request, wait for it to finish
takahashim 0:0048b264a3ad 42 * and return the content of the reply.
takahashim 0:0048b264a3ad 43 * (requires libcurl or a command-line HTTP client)
takahashim 0:0048b264a3ad 44 *
takahashim 0:0048b264a3ad 45 * more documentation in oauth.h
takahashim 0:0048b264a3ad 46 *
takahashim 0:0048b264a3ad 47 * @param u url to query
takahashim 0:0048b264a3ad 48 * @param p postargs to send along with the HTTP request.
takahashim 0:0048b264a3ad 49 * @return In case of an error NULL is returned; otherwise a pointer to the
takahashim 0:0048b264a3ad 50 * replied content from HTTP server. latter needs to be freed by caller.
takahashim 0:0048b264a3ad 51 */
takahashim 0:0048b264a3ad 52 std::string oauth_http_post(const char *u, const char *p)
takahashim 0:0048b264a3ad 53 {
takahashim 0:0048b264a3ad 54 HTTPClient http;
takahashim 0:0048b264a3ad 55 HTTPText req("application/x-www-form-urlencoded");
takahashim 0:0048b264a3ad 56 HTTPText res;
takahashim 0:0048b264a3ad 57 req.set(p);
takahashim 0:0048b264a3ad 58 http.post(u, req, &res);
takahashim 0:0048b264a3ad 59 return res.get();
takahashim 0:0048b264a3ad 60 }
takahashim 0:0048b264a3ad 61