summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRoss Burton <ross@linux.intel.com>2009-08-03 13:57:17 +0100
committerRoss Burton <ross@linux.intel.com>2009-08-03 13:57:17 +0100
commit7180dd6551c5ae98f5fa1a0dc78a5a763c5fee7a (patch)
tree1295019c73f9a170c8ff2463257b92c0d3a0a2eb /examples
parentee917d375957f01059d003c84c4421b28d52896a (diff)
downloadlibrest-7180dd6551c5ae98f5fa1a0dc78a5a763c5fee7a.tar.gz
Use the new APIs and clean up get-fireeagle-location
Diffstat (limited to 'examples')
-rw-r--r--examples/get-fireeagle-location.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/examples/get-fireeagle-location.c b/examples/get-fireeagle-location.c
index 1477f41..52a2048 100644
--- a/examples/get-fireeagle-location.c
+++ b/examples/get-fireeagle-location.c
@@ -4,7 +4,7 @@
*
* Authors: Rob Bradford <rob@linux.intel.com>
* Ross Burton <ross@linux.intel.com>
- *
+ *
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU Lesser General Public License,
* version 2.1, as published by the Free Software Foundation.
@@ -21,6 +21,7 @@
*/
#include <rest/oauth-proxy.h>
+#include <rest/rest-xml-parser.h>
#include <stdio.h>
int
@@ -29,6 +30,9 @@ main (int argc, char **argv)
RestProxy *proxy;
RestProxyCall *call;
GError *error = NULL;
+ char pin[256];
+ RestXmlParser *parser;
+ RestXmlNode *root, *node;
g_thread_init (NULL);
g_type_init ();
@@ -42,21 +46,27 @@ main (int argc, char **argv)
/* FireEagle endpoint */
"https://fireeagle.yahooapis.com/", FALSE);
- /* First stage authentication, this gets a request token */
- if (!oauth_proxy_auth_step (OAUTH_PROXY (proxy), "oauth/request_token", &error))
+ /* First stage authentication, this gets a request token. */
+ if (!oauth_proxy_request_token (OAUTH_PROXY (proxy),
+ "oauth/request_token",
+ "oob",
+ &error))
g_error ("Cannot request token: %s", error->message);
/* From the token construct a URL for the user to visit */
- g_print ("Go to https://fireeagle.yahoo.net/oauth/authorize?oauth_token=%s then hit any key\n",
+ g_print ("Go to https://fireeagle.yahoo.net/oauth/authorize?oauth_token=%s then enter the verification code\n",
oauth_proxy_get_token (OAUTH_PROXY (proxy)));
- getchar ();
- /* Second stage authentication, this gets an access token */
- if (!oauth_proxy_auth_step (OAUTH_PROXY (proxy), "oauth/access_token", &error))
- g_error ("Cannot request token: %s", error->message);
+ /* Read the PIN */
+ fgets (pin, sizeof (pin), stdin);
+ g_strchomp (pin);
- /* We're now authenticated */
- g_print ("Got access token\n");
+ /* Second stage authentication, this gets an access token. */
+ if (!oauth_proxy_access_token (OAUTH_PROXY (proxy),
+ "oauth/access_token",
+ pin,
+ &error))
+ g_error ("Cannot request token: %s", error->message);
/* Get the user's current location */
call = rest_proxy_new_call (proxy);
@@ -65,11 +75,17 @@ main (int argc, char **argv)
if (!rest_proxy_call_run (call, NULL, &error))
g_error ("Cannot make call: %s", error->message);
- g_print ("%s\n", rest_proxy_call_get_payload (call));
-
+ parser = rest_xml_parser_new ();
+ root = rest_xml_parser_parse_from_data (parser,
+ rest_proxy_call_get_payload (call),
+ rest_proxy_call_get_payload_length (call));
+ g_object_unref (parser);
g_object_unref (call);
-
g_object_unref (proxy);
+ node = rest_xml_node_find (root, "location");
+ node = rest_xml_node_find (node, "name");
+ g_print ("%s\n", node->content);
+
return 0;
}