diff options
author | Rob Bradford <rob@o-hand.com> | 2008-08-20 17:02:21 +0100 |
---|---|---|
committer | Rob Bradford <rob@o-hand.com> | 2008-08-20 17:02:21 +0100 |
commit | 27ce1bbe72190a81fb8765b9954f7329aa1913f1 (patch) | |
tree | 952594eb983e29ad51929c58c88715753db61cc0 | |
parent | add0d338451e0e4dc197edde5fb0baa723865ea3 (diff) |
Add a test for JSON api.
-rw-r--r-- | examples/Makefile.am | 9 | ||||
-rw-r--r-- | examples/test-json.c | 45 |
2 files changed, 51 insertions, 3 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am index 3ac2af5..7c4486f 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,5 +1,8 @@ -noinst_PROGRAMS = test-raw +noinst_PROGRAMS = test-raw test-json + +AM_CFLAGS = $(GLIB_CFLAGS) $(SOUP_CFLAGS) $(JSON_CFLAGS) -I.. +AM_LDFLAGS = $(GLIB_LIBS) $(SOUP_LIBS) $(JSON_LIBS) ../rest/librest.la test_raw_SOURCES = test-raw.c -test_raw_LDADD = $(GLIB_LIBS) $(SOUP_LIBS) ../rest/librest.la -test_raw_CFLAGS = $(GLIB_CFLAGS) $(SOUP_CFLAGS) -I.. +test_json_SOURCES = test-json.c + diff --git a/examples/test-json.c b/examples/test-json.c new file mode 100644 index 0000000..efd9cd7 --- /dev/null +++ b/examples/test-json.c @@ -0,0 +1,45 @@ +#include <rest/rest-proxy.h> + +static void +proxy_call_json_async_cb (RestProxy *proxy, + guint status_code, + const gchar *response_message, + GHashTable *headers, + JsonNode *root, + GObject *weak_object, + gpointer userdata) +{ + g_main_loop_quit ((GMainLoop *)userdata); +} + +gint +main (gint argc, gchar **argv) +{ + RestProxy *proxy; + GMainLoop *loop; + gchar *payload; + gssize len; + + g_type_init (); + g_thread_init (NULL); + + loop = g_main_loop_new (NULL, FALSE); + + proxy = rest_proxy_new ("http://www.flickr.com/services/rest/", FALSE); + rest_proxy_call_json_async (proxy, + NULL, + "GET", + proxy_call_json_async_cb, + NULL, + loop, + NULL, + "method", + "flickr.test.echo", + "api_key", + "314691be2e63a4d58994b2be01faacfb", + "format", + "json", + NULL); + + g_main_loop_run (loop); +} |