[librest/goa: 2/4] goa: add very rough GOA integration point
- From: Ross Burton <rburton src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librest/goa: 2/4] goa: add very rough GOA integration point
- Date: Fri, 13 Jan 2012 12:40:08 +0000 (UTC)
commit 43aeca0d79a2beaf7d0391752ba14a446ca792d6
Author: Ross Burton <ross linux intel com>
Date: Fri Jan 13 12:38:41 2012 +0000
goa: add very rough GOA integration point
rest-extras/Makefile.am | 13 ++++++----
rest-extras/rest-goa.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
rest-extras/rest-goa.h | 53 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 121 insertions(+), 5 deletions(-)
---
diff --git a/rest-extras/Makefile.am b/rest-extras/Makefile.am
index c354867..6d4a39f 100644
--- a/rest-extras/Makefile.am
+++ b/rest-extras/Makefile.am
@@ -8,22 +8,25 @@ lib_sources = \
lastfm-proxy-call.c \
lastfm-proxy-private.h \
youtube-proxy.c \
- youtube-proxy-private.h
+ youtube-proxy-private.h \
+ rest-goa.c
+
lib_headers = \
flickr-proxy.h \
flickr-proxy-call.h \
lastfm-proxy.h \
lastfm-proxy-call.h \
- youtube-proxy.h
+ youtube-proxy.h \
+ rest-goa.h
lib_LTLIBRARIES = librest-extras- API_VERSION@.la
librest_extras_ API_VERSION@_la_CFLAGS = $(GLIB_CFLAGS) $(GTHREAD_CFLAGS) \
- $(SOUP_CFLAGS) $(SOUP_GNOME_CFLAGS) \
+ $(SOUP_CFLAGS) $(SOUP_GNOME_CFLAGS) $(GOA_CFLAGS) \
$(XML_CFLAGS) $(GCOV_CFLAGS) \
-I$(top_srcdir) -Wall -DG_LOG_DOMAIN=\"Rest\"
librest_extras_ API_VERSION@_la_LIBADD = $(GLIB_LIBS) $(GTHREAD_LIBS) \
- $(SOUP_LIBS) $(SOUP_GNOME_LIBS) $(XML_LIBS) \
+ $(SOUP_LIBS) $(SOUP_GNOME_LIBS) $(XML_LIBS) $(GOA_LIBS) \
$(GCOV_LDFLAGS) \
$(top_builddir)/rest/librest- API_VERSION@.la
librest_extras_ API_VERSION@_la_LDFLAGS = -no-undefined
@@ -60,7 +63,7 @@ RestExtras_ API_VERSION_AM@_gir_LIBS = librest-extras- API_VERSION@.la
RestExtras_ API_VERSION_AM@_gir_FILES = $(addprefix $(top_srcdir)/rest-extras/, $(lib_headers))
RestExtras_ API_VERSION_AM@_gir_CFLAGS = -I$(top_srcdir)
RestExtras_ API_VERSION_AM@_gir_INCLUDES = GObject-2.0 libxml2-2.0
-RestExtras_ API_VERSION_AM@_gir_PACKAGES = gobject-2.0 libsoup-2.4 libxml-2.0
+RestExtras_ API_VERSION_AM@_gir_PACKAGES = gobject-2.0 libsoup-2.4 libxml-2.0 goa-1.0
RestExtras_ API_VERSION_AM@_gir_SCANNERFLAGS = --include-uninstalled=$(top_builddir)/rest/Rest- API_VERSION@.gir
girdir = $(datadir)/gir-1.0
diff --git a/rest-extras/rest-goa.c b/rest-extras/rest-goa.c
new file mode 100644
index 0000000..c07b2f2
--- /dev/null
+++ b/rest-extras/rest-goa.c
@@ -0,0 +1,60 @@
+#include <rest/oauth-proxy.h>
+#include "rest-goa.h"
+
+RestProxy *
+rest_goa_proxy_from_account (GoaObject *object, const char *url_format, gboolean binding_required, gboolean *authenticated)
+{
+ GoaOAuthBased *oauth;
+ GoaAccount *account;
+ RestProxy *proxy;
+ GError *error = NULL;
+
+ g_return_val_if_fail (GOA_IS_OBJECT (object), NULL);
+ g_return_val_if_fail (url_format, NULL);
+
+ oauth = goa_object_get_oauth_based (object);
+ if (oauth == NULL) {
+ g_warning ("object is not OAuth-based");
+ return NULL;
+ }
+
+ account = goa_object_get_account (object);
+
+ /* Create an unauthorised proxy */
+ proxy = oauth_proxy_new
+ (goa_oauth_based_get_consumer_key (oauth),
+ goa_oauth_based_get_consumer_secret (oauth),
+ url_format, binding_required);
+
+ if (goa_account_call_ensure_credentials_sync (account, NULL, NULL, &error)) {
+ char *access_token = NULL, *access_token_secret = NULL;
+
+ if (goa_oauth_based_call_get_access_token_sync
+ (oauth, &access_token, &access_token_secret, NULL, NULL, &error)) {
+ g_object_set (proxy,
+ "token", access_token,
+ "token-secret", access_token_secret,
+ NULL);
+
+ g_free (access_token);
+ g_free (access_token_secret);
+
+ if (authenticated) *authenticated = TRUE;
+ } else {
+ g_message ("Could not get access token: %s", error->message);
+ g_clear_error (&error);
+
+ if (authenticated) *authenticated = FALSE;
+ }
+ } else {
+ g_message ("Could not ensure credentials: %s", error->message);
+ g_clear_error (&error);
+ /* TODO: ignore and return partial proxy? critical failure and return NULL? */
+ }
+
+ g_object_unref (account);
+ g_object_unref (oauth);
+
+ return proxy;
+}
+
diff --git a/rest-extras/rest-goa.h b/rest-extras/rest-goa.h
new file mode 100644
index 0000000..563ba0c
--- /dev/null
+++ b/rest-extras/rest-goa.h
@@ -0,0 +1,53 @@
+/*
+ * librest - RESTful web services access
+ * Copyright (c) 2008, 2009, Intel Corporation.
+ *
+ * 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.
+ *
+ * This program is distributed in the hope 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#ifndef _REST_GOA
+#define _REST_GOA
+
+#define GOA_API_IS_SUBJECT_TO_CHANGE
+
+#include <glib-object.h>
+#include <goa/goa.h>
+#include <rest/rest-proxy.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Very incomplete and experimental APIs to integrate librest with
+ * gnome-online-accounts. Much design work needed!
+ */
+
+/*
+ * Create a new RestProxy based on a specific GoaObject. *authenticated is set
+ * to TRUE if the account has valid credentials.
+ *
+ * Currently only accounts that are OAuth-based are handled.
+ */
+RestProxy *rest_goa_proxy_from_account (GoaObject *object,
+ const char *url_format,
+ gboolean binding_required,
+ gboolean *authenticated);
+
+G_END_DECLS
+
+#endif /* _REST_GOA */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]