1 /*
2 * librest - RESTful web services access
3 * Copyright (c) 2008, 2009, Intel Corporation.
4 *
5 * Authors: Rob Bradford <rob@linux.intel.com>
6 * Ross Burton <ross@linux.intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU Lesser General Public License,
10 * version 2.1, as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23 #include <rest/rest-proxy.h>
24 #include <unistd.h>
25
26 static void
proxy_call_async_cb(RestProxyCall * call,const GError * error,GObject * weak_object,gpointer userdata)27 proxy_call_async_cb (RestProxyCall *call,
28 const GError *error,
29 GObject *weak_object,
30 gpointer userdata)
31 {
32 const gchar *payload;
33 goffset len;
34
35 payload = rest_proxy_call_get_payload (call);
36 len = rest_proxy_call_get_payload_length (call);
37 write (1, payload, len);
38 g_main_loop_quit ((GMainLoop *)userdata);
39 }
40
41 gint
main(gint argc,gchar ** argv)42 main (gint argc, gchar **argv)
43 {
44 RestProxy *proxy;
45 RestProxyCall *call;
46 GMainLoop *loop;
47 const gchar *payload;
48 gssize len;
49
50 #if !GLIB_CHECK_VERSION (2, 36, 0)
51 g_type_init ();
52 #endif
53
54 loop = g_main_loop_new (NULL, FALSE);
55
56 proxy = rest_proxy_new ("https://www.flickr.com/services/rest/", FALSE);
57 call = rest_proxy_new_call (proxy);
58 rest_proxy_call_add_params (call,
59 "method", "flickr.test.echo",
60 "api_key", "314691be2e63a4d58994b2be01faacfb",
61 "format", "json",
62 NULL);
63 rest_proxy_call_async (call,
64 proxy_call_async_cb,
65 NULL,
66 loop,
67 NULL);
68
69 g_main_loop_run (loop);
70
71 rest_proxy_call_run (call, NULL, NULL);
72
73 payload = rest_proxy_call_get_payload (call);
74 len = rest_proxy_call_get_payload_length (call);
75 write (1, payload, len);
76
77 g_object_unref (call);
78 g_object_unref (proxy);
79 }
80