[gnome-online-accounts] examples: Add some basic examples
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts] examples: Add some basic examples
- Date: Sun, 25 Mar 2012 11:26:32 +0000 (UTC)
commit 14f6109c195799089492ce3ed06ad18c0ac4a84a
Author: Ross Burton <ross linux intel com>
Date: Thu Jan 19 15:41:06 2012 +0000
examples: Add some basic examples
Fixes: https://bugzilla.gnome.org/669042
src/examples/Makefile.am | 15 ++++++-
src/examples/list-accounts.c | 54 +++++++++++++++++++++
src/examples/list-providers.c | 48 +++++++++++++++++++
src/examples/tweet.c | 103 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 219 insertions(+), 1 deletions(-)
---
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am
index 29a7bee..09bf084 100644
--- a/src/examples/Makefile.am
+++ b/src/examples/Makefile.am
@@ -11,10 +11,23 @@ INCLUDES = \
-DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
-DPACKAGE_LIB_DIR=\""$(libdir)"\" \
-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT \
- -DGOA_API_IS_SUBJECT_TO_CHANGE \
$(WARN_CFLAGS) \
$(NULL)
+noinst_PROGRAMS = list-providers list-accounts tweet
+
+list_providers_SOURCES = list-providers.c
+list_providers_CFLAGS = $(GLIB_CFLAGS) $(GTK_CFLAGS)
+list_providers_LDADD = $(GLIB_LIBS) $(GTK_CFLAGS) ../goabackend/libgoa-backend-1.0.la ../goa/libgoa-1.0.la
+
+list_accounts_SOURCES = list-accounts.c
+list_accounts_CFLAGS = $(GLIB_CFLAGS)
+list_accounts_LDADD = $(GLIB_LIBS) ../goa/libgoa-1.0.la
+
+tweet_SOURCES = tweet.c
+tweet_CFLAGS = $(GLIB_CFLAGS) $(REST_CFLAGS)
+tweet_LDADD = $(GLIB_LIBS) $(REST_LIBS) ../goa/libgoa-1.0.la
+
clean-local :
rm -f *~
diff --git a/src/examples/list-accounts.c b/src/examples/list-accounts.c
new file mode 100644
index 0000000..59daf80
--- /dev/null
+++ b/src/examples/list-accounts.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2012 Intel Corp
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ross Burton <ross burton intel com>
+ */
+
+#include <config.h>
+
+#define GOA_API_IS_SUBJECT_TO_CHANGE
+#include <goa/goa.h>
+
+int
+main (int argc, char **argv)
+{
+ GError *error = NULL;
+ GoaClient *client;
+ GList *accounts, *l;
+ GoaAccount *account;
+
+ g_type_init ();
+
+ client = goa_client_new_sync (NULL, &error);
+ if (!client) {
+ g_error ("Could not create GoaClient: %s", error->message);
+ return 1;
+ }
+
+ accounts = goa_client_get_accounts (client);
+ for (l = accounts; l != NULL; l = l->next) {
+ account = goa_object_get_account (GOA_OBJECT (l->data));
+ g_print ("%s at %s\n",
+ goa_account_get_presentation_identity (account),
+ goa_account_get_provider_name (account));
+ }
+
+ g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
+
+ return 0;
+}
diff --git a/src/examples/list-providers.c b/src/examples/list-providers.c
new file mode 100644
index 0000000..80f90ce
--- /dev/null
+++ b/src/examples/list-providers.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2012 Intel Corp
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ross Burton <ross burton intel com>
+ */
+
+#include <config.h>
+
+#define GOA_API_IS_SUBJECT_TO_CHANGE
+#define GOA_BACKEND_API_IS_SUBJECT_TO_CHANGE
+#include <goabackend/goabackend.h>
+
+int
+main (int argc, char **argv)
+{
+ GoaProvider *provider;
+ GList *providers, *l;
+
+ g_type_init ();
+
+ providers = goa_provider_get_all ();
+ for (l = providers; l != NULL; l = l->next) {
+ char *provider_name;
+
+ provider = GOA_PROVIDER (l->data);
+ provider_name = goa_provider_get_provider_name (provider, NULL);
+ g_print ("Got provider %s\n", provider_name);
+ g_free (provider_name);
+ provider = NULL;
+ }
+
+ return 0;
+}
diff --git a/src/examples/tweet.c b/src/examples/tweet.c
new file mode 100644
index 0000000..8e44185
--- /dev/null
+++ b/src/examples/tweet.c
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2012 Intel Corp
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ross Burton <ross burton intel com>
+ */
+
+#include <config.h>
+
+#define GOA_API_IS_SUBJECT_TO_CHANGE
+#include <goa/goa.h>
+
+#include <rest/oauth-proxy.h>
+
+int
+main (int argc, char **argv)
+{
+ GError *error = NULL;
+ GoaClient *client;
+ GList *accounts, *l;
+ GoaAccount *account = NULL;
+ GoaOAuthBased *oauth = NULL;
+ char *access_token = NULL, *access_token_secret = NULL;
+ RestProxy *proxy;
+ RestProxyCall *call;
+
+ g_type_init ();
+
+ client = goa_client_new_sync (NULL, &error);
+ if (!client) {
+ g_error ("Could not create GoaClient: %s", error->message);
+ return 1;
+ }
+
+ accounts = goa_client_get_accounts (client);
+
+ /* Find a twitter account */
+ for (l = accounts; l != NULL; l = l->next) {
+ GoaObject *object = GOA_OBJECT (l->data);
+
+ account = goa_object_peek_account (object);
+ if (g_strcmp0 (goa_account_get_provider_type (account),
+ "twitter") == 0) {
+ g_object_ref (account);
+ oauth = goa_object_get_oauth_based (object);
+ break;
+ }
+ }
+
+ g_list_free_full (accounts, (GDestroyNotify) g_object_unref);
+
+ g_assert (account);
+ g_assert (oauth);
+
+ if (!goa_account_call_ensure_credentials_sync (account, NULL, NULL, &error)) {
+ g_error ("Could not ensure credentials are valid: %s", error->message);
+ return 1;
+ }
+
+ g_print ("Credentials valid\n");
+
+ if (!goa_oauth_based_call_get_access_token_sync (oauth, &access_token, &access_token_secret, NULL, NULL, &error)) {
+ g_error ("Could not get access token: %s", error->message);
+ return 1;
+ }
+
+ g_print ("Got access tokens\n");
+
+ proxy = oauth_proxy_new_with_token
+ (goa_oauth_based_get_consumer_key (oauth),
+ goa_oauth_based_get_consumer_secret (oauth),
+ access_token, access_token_secret,
+ "https://api.twitter.com/", FALSE);
+ call = rest_proxy_new_call (proxy);
+ rest_proxy_call_set_method (call, "POST");
+ rest_proxy_call_set_function (call, "1/statuses/update.xml");
+ rest_proxy_call_add_param (call, "status", "Hello from GOA+rest");
+
+ g_print ("Tweeting...\n");
+
+ if (!rest_proxy_call_sync (call, &error)) {
+ g_error ("Cannot tweet: %s", error->message);
+ return 1;
+ }
+
+ g_print ("Tweeted!\n");
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]