diff options
-rw-r--r-- | gfbgraph/Makefile.am | 13 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-album.c | 12 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-album.h | 1 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-common.c | 2 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-connectable.c | 8 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-goa-authorizer.c | 2 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-goa-authorizer.h | 1 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-node.c | 16 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-node.h | 1 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-photo.c | 16 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-photo.h | 1 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-simple-authorizer.c | 200 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-simple-authorizer.h (renamed from tests/gfbgraph-simple-authorizer.h) | 23 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-user.c | 12 | ||||
-rw-r--r-- | gfbgraph/gfbgraph-user.h | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/credentials.h | 2 | ||||
-rw-r--r-- | tests/gfbgraph-simple-authorizer.c | 102 | ||||
-rw-r--r-- | tests/gtestutils.c | 5 | ||||
-rw-r--r-- | tests/test-async.c | 5 | ||||
-rw-r--r-- | tests/test.c | 5 |
21 files changed, 279 insertions, 151 deletions
diff --git a/gfbgraph/Makefile.am b/gfbgraph/Makefile.am index 0c19e2e..d07b90d 100644 --- a/gfbgraph/Makefile.am +++ b/gfbgraph/Makefile.am @@ -6,7 +6,9 @@ lib_sources = \ gfbgraph-goa-authorizer.c \ gfbgraph-node.c \ gfbgraph-photo.c \ + gfbgraph-simple-authorizer.c \ gfbgraph-user.c + lib_headers = \ gfbgraph.h \ gfbgraph-album.h \ @@ -16,6 +18,7 @@ lib_headers = \ gfbgraph-goa-authorizer.h \ gfbgraph-node.h \ gfbgraph-photo.h \ + gfbgraph-simple-authorizer.h \ gfbgraph-user.h lib_LTLIBRARIES = libgfbgraph-@API_VERSION@.la @@ -44,7 +47,7 @@ libgfbgraph_@API_VERSION@_ladir = $(includedir)/gfbgraph-@API_VERSION@/gfbgraph # Introspection -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_GIRS = -INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) +INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) --warn-all INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir) if HAVE_INTROSPECTION @@ -54,10 +57,11 @@ GFBGraph-@API_VERSION@.gir: libgfbgraph-@API_VERSION@.la Makefile GFBGraph_@API_MAJOR@_@API_MINOR@_gir_INCLUDES = \ + GLib-2.0 \ + Gio-2.0 \ GObject-2.0 \ Rest-0.7 \ Json-1.0 \ - Gio-2.0 \ Soup-2.4 GFBGraph_@API_MAJOR@_@API_MINOR@_gir_CFLAGS = \ @@ -72,11 +76,10 @@ GFBGraph_@API_MAJOR@_@API_MINOR@_gir_LIBS = libgfbgraph-@API_VERSION@.la GFBGraph_@API_MAJOR@_@API_MINOR@_gir_FILES = $(lib_sources) $(lib_headers) GFBGraph_@API_MAJOR@_@API_MINOR@_gir_NAMESPACE = GFBGraph GFBGraph_@API_MAJOR@_@API_MINOR@_gir_EXPORT_PACKAGES = libgfbgraph.@API_VERSION@ -GFBGraph_@API_MAJOR@_@API_MINOR@_gir_SCANNER_FLAGS = \ - --warn-all \ +GFBGraph_@API_MAJOR@_@API_MINOR@_gir_SCANNERFLAGS = \ --nsversion=$(API_VERSION) \ --symbol-prefix=gfbgraph \ - --identifier-prefix = GFBGraph \ + --identifier-prefix=GFBGraph \ --c-include="gfbgraph/gfbgraph.h" INTROSPECTION_GIRS += GFBGraph-@API_VERSION@.gir diff --git a/gfbgraph/gfbgraph-album.c b/gfbgraph/gfbgraph-album.c index d7d73d4..b3b5d8c 100644 --- a/gfbgraph/gfbgraph-album.c +++ b/gfbgraph/gfbgraph-album.c @@ -86,7 +86,7 @@ gfbgraph_album_class_init (GFBGraphAlbumClass *klass) g_type_class_add_private (gobject_class, sizeof(GFBGraphAlbumPrivate)); /** - * GFBGraphAlbum:name + * GFBGraphAlbum:name: * * The album name. **/ @@ -98,7 +98,7 @@ gfbgraph_album_class_init (GFBGraphAlbumClass *klass) G_PARAM_READABLE | G_PARAM_WRITABLE)); /** - * GFBGraphAlbum:description. + * GFBGraphAlbum:description: * * The album description given by the owner. **/ @@ -110,7 +110,7 @@ gfbgraph_album_class_init (GFBGraphAlbumClass *klass) G_PARAM_READABLE | G_PARAM_WRITABLE)); /** - * GFBGraphAlbum:cover_photo. + * GFBGraphAlbum:cover_photo: * * The node ID for the album cover photo. It's an ID for a #GFBGraphPhoto node. **/ @@ -122,7 +122,7 @@ gfbgraph_album_class_init (GFBGraphAlbumClass *klass) G_PARAM_READABLE | G_PARAM_WRITABLE)); /** - * GFBGraphAlbum:count + * GFBGraphAlbum:count: * * The number of photos in the album. **/ @@ -234,7 +234,7 @@ gfbgraph_album_get_connection_post_params (GFBGraphConnectable *self, GType node * * Creates a new #GFBGraphAlbum. * - * Returns: a new #GFBGraphAlbum; unref with g_object_unref() + * Returns: (transfer full): a new #GFBGraphAlbum; unref with g_object_unref() **/ GFBGraphAlbum* gfbgraph_album_new (void) @@ -250,7 +250,7 @@ gfbgraph_album_new (void) * * Retrieves an album node from the Facebook Graph with the give ID. * - * Returns: a new #GFBGraphAlbum; unref with g_object_unref() + * Returns: (transfer full): a new #GFBGraphAlbum; unref with g_object_unref() **/ GFBGraphAlbum* gfbgraph_album_new_from_id (GFBGraphAuthorizer *authorizer, const gchar *id, GError **error) diff --git a/gfbgraph/gfbgraph-album.h b/gfbgraph/gfbgraph-album.h index 595fd0a..c78202a 100644 --- a/gfbgraph/gfbgraph-album.h +++ b/gfbgraph/gfbgraph-album.h @@ -39,6 +39,7 @@ typedef struct _GFBGraphAlbumPrivate GFBGraphAlbumPrivate; struct _GFBGraphAlbum { GFBGraphNode parent; + /*< private >*/ GFBGraphAlbumPrivate *priv; }; diff --git a/gfbgraph/gfbgraph-common.c b/gfbgraph/gfbgraph-common.c index fa7c13a..2dc7f65 100644 --- a/gfbgraph/gfbgraph-common.c +++ b/gfbgraph/gfbgraph-common.c @@ -30,7 +30,7 @@ * Create a new #RestProxyCall pointing to the Facebook Graph API url (https://graph.facebook.com) * and processed by the authorizer to allow queries. * - * Returns: a new #RestProxyCall or %NULL in case of error. + * Returns: (transfer full): a new #RestProxyCall or %NULL in case of error. **/ RestProxyCall* gfbgraph_new_rest_call (GFBGraphAuthorizer *authorizer) diff --git a/gfbgraph/gfbgraph-connectable.c b/gfbgraph/gfbgraph-connectable.c index 6233709..edc5de4 100644 --- a/gfbgraph/gfbgraph-connectable.c +++ b/gfbgraph/gfbgraph-connectable.c @@ -70,7 +70,7 @@ get_connections (GFBGraphConnectableInterface *iface) * Get the params to be inserted in a request to the Facebook Graph API * in order to append the node @self to a node of type @node_type. * - * Returns: A string based #GHashTable with the params and his values or %NULL. + * Returns: (transfer full): A string based #GHashTable with the params and his values or %NULL. **/ GHashTable* gfbgraph_connectable_get_connection_post_params (GFBGraphConnectable *self, GType node_type) @@ -96,7 +96,7 @@ gfbgraph_connectable_get_connection_post_params (GFBGraphConnectable *self, GTyp * Parse the response contained in @payload when a gfbgraph_node_get_connection_nodes() was * executed. * - * Returns: a #GList of #GFBGraphNode created from the @payload or %NULL. + * Returns: (transfer full): a #GList of #GFBGraphNode created from the @payload or %NULL. **/ GList* gfbgraph_connectable_parse_connected_data (GFBGraphConnectable *self, const gchar *payload, GError **error) @@ -146,7 +146,7 @@ gfbgraph_connectable_is_connectable_to (GFBGraphConnectable *self, GType node_ty * Get the Facebook Graph API function path to retrieve the nodes connected with @node_type * managed by the #GFBGraphConnectable object. * - * Returns: a const #gchar with the function path or %NULL. + * Returns: (transfer none): a const #gchar with the function path or %NULL. **/ const gchar* gfbgraph_connectable_get_connection_path (GFBGraphConnectable *self, GType node_type) @@ -177,7 +177,7 @@ gfbgraph_connectable_get_connection_path (GFBGraphConnectable *self, GType node_ * Normally, Facebook Graph API returns the connections in the same way, using JSON objects, * with a root object called "data". * - * Returns: a #GList of #GFBGraphNode with the same #GType as @self. + * Returns: (transfer full): a #GList of #GFBGraphNode with the same #GType as @self. **/ GList* gfbgraph_connectable_default_parse_connected_data (GFBGraphConnectable *self, const gchar *payload, GError **error) diff --git a/gfbgraph/gfbgraph-goa-authorizer.c b/gfbgraph/gfbgraph-goa-authorizer.c index 9c1cbe3..3a8d3b9 100644 --- a/gfbgraph/gfbgraph-goa-authorizer.c +++ b/gfbgraph/gfbgraph-goa-authorizer.c @@ -242,7 +242,7 @@ gfbgraph_goa_authorizer_set_goa_object (GFBGraphGoaAuthorizer *self, GoaObject * * * Creates a new #GFBGraphGoaAuthorizer using @goa_object as account. * - * Returns: A new #GFBGraphGoaAuthorizer. Use g_object_unref() to free it. + * Returns: (transfer full): A new #GFBGraphGoaAuthorizer. Use g_object_unref() to free it. */ GFBGraphGoaAuthorizer* gfbgraph_goa_authorizer_new (GoaObject *goa_object) diff --git a/gfbgraph/gfbgraph-goa-authorizer.h b/gfbgraph/gfbgraph-goa-authorizer.h index 84d3516..499248f 100644 --- a/gfbgraph/gfbgraph-goa-authorizer.h +++ b/gfbgraph/gfbgraph-goa-authorizer.h @@ -39,6 +39,7 @@ typedef struct _GFBGraphGoaAuthorizerPrivate GFBGraphGoaAuthorizerPrivate; struct _GFBGraphGoaAuthorizer { GObject parent; + /*< private >*/ GFBGraphGoaAuthorizerPrivate *priv; }; diff --git a/gfbgraph/gfbgraph-node.c b/gfbgraph/gfbgraph-node.c index 79a768d..69da087 100644 --- a/gfbgraph/gfbgraph-node.c +++ b/gfbgraph/gfbgraph-node.c @@ -92,7 +92,7 @@ gfbgraph_node_class_init (GFBGraphNodeClass *klass) g_type_class_add_private (gobject_class, sizeof(GFBGraphNodePrivate)); /** - * GFBGraphNode:id + * GFBGraphNode:id: * * The node ID. All nodes have one of this. **/ @@ -187,7 +187,7 @@ gfbgraph_node_get_connection_nodes_async_thread (GSimpleAsyncResult *simple_asyn * * Creates a new #GFBGraphNode. * - * Return value: a new #GFBGraphNode; unref with g_object_unref() + * Returns: (transfer full): a new #GFBGraphNode; unref with g_object_unref() **/ GFBGraphNode* gfbgraph_node_new (void) @@ -204,10 +204,10 @@ gfbgraph_node_new (void) * * Retrieve a node object as a #GFBgraphNode of #node_type type, with the given @id from the Facebook Graph. * - * Returns: a #GFBGraphNode or %NULL. + * Returns: (transfer full): a #GFBGraphNode or %NULL. **/ GFBGraphNode* - gfbgraph_node_new_from_id (GFBGraphAuthorizer *authorizer, const gchar *id, GType node_type, GError **error) +gfbgraph_node_new_from_id (GFBGraphAuthorizer *authorizer, const gchar *id, GType node_type, GError **error) { GFBGraphNode *node; RestProxyCall *rest_call; @@ -244,13 +244,13 @@ GFBGraphNode* * @node: a #GFBGraphNode object which retrieve the connected nodes. * @node_type: a #GFBGraphNode type #GType that determines the kind of nodes to retrieve. * @authorizer: a #GFBGraphAuthorizer. - * @error: (allow-none) a #GError or %NULL. + * @error: (allow-none): a #GError or %NULL. * * Retrieve the nodes of type @node_type connected to the @node object. The @node_type object must * implement the #GFBGraphConnectionable interface and be connectable to @node type object. * See gfbgraph_node_get_connection_nodes_async() for the asynchronous version of this call. * - * Returns: a #GList of type @node_type objects with the found nodes. + * Returns: (transfer full): a #GList of type @node_type objects with the found nodes. **/ GList* gfbgraph_node_get_connection_nodes (GFBGraphNode *node, GType node_type, GFBGraphAuthorizer *authorizer, GError **error) @@ -315,7 +315,7 @@ gfbgraph_node_get_connection_nodes (GFBGraphNode *node, GType node_type, GFBGrap * @authorizer: a #GFBGraphAuthorizer. * @cancellable: (allow-none): An optional #GCancellable object, or %NULL. * @callback: (scope async): A #GAsyncReadyCallback to call when the request is completed. - * @user_data: (closure); The data to pass to @callback. + * @user_data: (closure): The data to pass to @callback. * * Asynchronously retrieve the list of nodes of type @node_type connected to the @node object. See * gfbgraph_node_get_connection_nodes() for the synchronous version of this call. @@ -357,7 +357,7 @@ gfbgraph_node_get_connection_nodes_async (GFBGraphNode *node, GType node_type, G * Finishes an asynchronous operation started with * gfbgraph_node_get_connection_nodes_async(). * - * Returns: a #GList of type #node_type objects with the found nodes. + * Returns: (transfer full): a #GList of type #node_type objects with the found nodes. **/ GList* gfbgraph_node_get_connection_nodes_async_finish (GFBGraphNode *node, GAsyncResult *result, GError **error) diff --git a/gfbgraph/gfbgraph-node.h b/gfbgraph/gfbgraph-node.h index df545a1..f8fc879 100644 --- a/gfbgraph/gfbgraph-node.h +++ b/gfbgraph/gfbgraph-node.h @@ -41,6 +41,7 @@ typedef struct _GFBGraphNodePrivate GFBGraphNodePrivate; struct _GFBGraphNode { GObject parent; + /*< private >*/ GFBGraphNodePrivate *priv; }; diff --git a/gfbgraph/gfbgraph-photo.c b/gfbgraph/gfbgraph-photo.c index 582e52c..12b091a 100644 --- a/gfbgraph/gfbgraph-photo.c +++ b/gfbgraph/gfbgraph-photo.c @@ -86,7 +86,7 @@ gfbgraph_photo_class_init (GFBGraphPhotoClass *klass) g_type_class_add_private (gobject_class, sizeof(GFBGraphPhotoPrivate)); /** - * GFBGraphPhoto:name + * GFBGraphPhoto:name: * * The name of the photo given by his owner. **/ @@ -98,7 +98,7 @@ gfbgraph_photo_class_init (GFBGraphPhotoClass *klass) G_PARAM_READABLE | G_PARAM_WRITABLE)); /** - * GFBGraphPhoto:source + * GFBGraphPhoto:source: * * An URI for the photo, with a maximum width or height of 720px. **/ @@ -110,7 +110,7 @@ gfbgraph_photo_class_init (GFBGraphPhotoClass *klass) G_PARAM_READABLE | G_PARAM_WRITABLE)); /** - * GFBGraphPhoto:width + * GFBGraphPhoto:width: * * The default photo width, up to 720px. **/ @@ -122,7 +122,7 @@ gfbgraph_photo_class_init (GFBGraphPhotoClass *klass) G_PARAM_READABLE | G_PARAM_WRITABLE)); /** - * GFBGraphPhoto:height + * GFBGraphPhoto:height: * * The default photo height, up to 720px. **/ @@ -225,11 +225,11 @@ gfbgraph_photo_get_connection_post_params (GFBGraphConnectable *self, GType node } /** - * gfbgraph_photo_new() + * gfbgraph_photo_new: * * Creates a new #GFBGraphPhoto. * - * Returns: a new #GFBGraphPhoto; unref with g_object_unref() + * Returns: (transfer full): a new #GFBGraphPhoto; unref with g_object_unref() **/ GFBGraphPhoto* gfbgraph_photo_new (void) @@ -245,7 +245,7 @@ gfbgraph_photo_new (void) * * Retrieves an photo node from the Facebook Graph with the give ID. * - * Returns: a new #GFBGraphPhoto; unref with g_object_unref() + * Returns: (transfer full): a new #GFBGraphPhoto; unref with g_object_unref() **/ GFBGraphPhoto* gfbgraph_photo_new_from_id (GFBGraphAuthorizer *authorizer, const gchar *id, GError **error) @@ -263,7 +263,7 @@ gfbgraph_photo_new_from_id (GFBGraphAuthorizer *authorizer, const gchar *id, GEr * Download the default sized photo pointed by @photo, with a maximum width or height of 720px. * The photo always is a JPEG. * - * Returns: a #GInputStream with the photo content or %NULL in case of error. + * Returns: (transfer full): a #GInputStream with the photo content or %NULL in case of error. **/ GInputStream* gfbgraph_photo_download_default_size (GFBGraphPhoto *photo, GFBGraphAuthorizer *authorizer, GError **error) diff --git a/gfbgraph/gfbgraph-photo.h b/gfbgraph/gfbgraph-photo.h index 0791899..55ff3d9 100644 --- a/gfbgraph/gfbgraph-photo.h +++ b/gfbgraph/gfbgraph-photo.h @@ -39,6 +39,7 @@ typedef struct _GFBGraphPhotoPrivate GFBGraphPhotoPrivate; struct _GFBGraphPhoto { GFBGraphNode parent; + /*< private >*/ GFBGraphPhotoPrivate *priv; }; diff --git a/gfbgraph/gfbgraph-simple-authorizer.c b/gfbgraph/gfbgraph-simple-authorizer.c new file mode 100644 index 0000000..cae112a --- /dev/null +++ b/gfbgraph/gfbgraph-simple-authorizer.c @@ -0,0 +1,200 @@ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*- */ +/* + * libgfbgraph - GObject library for Facebook Graph API + * Copyright (C) 2013 Álvaro Peña <alvaropg@gmail.com> + * + * This library is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * libgfbgraph 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * SECTION:gfbgraph-simple-authorizer + * @short_description: GFBGraph simple authorization interface + * @stability: Unstable + * @include: gfbgraph/gfbgraph-simple-authorizer.h + * + * #GFBGraphSimpleAuthorizer provides an implementation of the #GFBGraphAuthorizer interface + * for authorization using a access token provided in creation time, no refresh, just a simple + * authorizer for test purposes, don't use in final code. + **/ + +#include "gfbgraph-authorizer.h" +#include "gfbgraph-simple-authorizer.h" + +enum +{ + PROP_0, + + PROP_ACCESS_TOKEN +}; + +struct _GFBGraphSimpleAuthorizerPrivate { + GMutex mutex; + gchar *access_token; +}; + +static void gfbgraph_simple_authorizer_init (GFBGraphSimpleAuthorizer *obj); +static void gfbgraph_simple_authorizer_class_init (GFBGraphSimpleAuthorizerClass *klass); +static void gfbgraph_simple_authorizer_finalize (GObject *obj); +static void gfbgraph_simple_authorizer_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); +static void gfbgraph_simple_authorizer_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); + +static void gfbgraph_simple_authorizer_iface_init (GFBGraphAuthorizerInterface *iface); + +void gfbgraph_simple_authorizer_process_call (GFBGraphAuthorizer *iface, RestProxyCall *call); +void gfbgraph_simple_authorizer_process_message (GFBGraphAuthorizer *iface, SoupMessage *message); +gboolean gfbgraph_simple_authorizer_refresh_authorization (GFBGraphAuthorizer *iface, GCancellable *cancellable, GError **error); + +#define GFBGRAPH_SIMPLE_AUTHORIZER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), GFBGRAPH_TYPE_SIMPLE_AUTHORIZER, GFBGraphSimpleAuthorizerPrivate)) + +static GObjectClass *parent_class = NULL; + +G_DEFINE_TYPE_WITH_CODE (GFBGraphSimpleAuthorizer, gfbgraph_simple_authorizer, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (GFBGRAPH_TYPE_AUTHORIZER, gfbgraph_simple_authorizer_iface_init)); + + +static void +gfbgraph_simple_authorizer_init (GFBGraphSimpleAuthorizer *obj) +{ + obj->priv = GFBGRAPH_SIMPLE_AUTHORIZER_GET_PRIVATE(obj); + g_mutex_init (&obj->priv->mutex); +} + +static void +gfbgraph_simple_authorizer_class_init (GFBGraphSimpleAuthorizerClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + gobject_class->finalize = gfbgraph_simple_authorizer_finalize; + gobject_class->set_property = gfbgraph_simple_authorizer_set_property; + gobject_class->get_property = gfbgraph_simple_authorizer_get_property; + + g_type_class_add_private (gobject_class, sizeof(GFBGraphSimpleAuthorizerPrivate)); + + /** + * GFBGraphSimpleAuthorizer:access_token: + * + * The access token for the Facebook Graph API, normally, take it by hand in the + * Graph API explorer tool: https://developers.facebook.com/tools/explorer. + **/ + g_object_class_install_property (gobject_class, + PROP_ACCESS_TOKEN, + g_param_spec_string ("access_token", + "The access token", "The access token for the Facebook Graph API.", + "", + G_PARAM_READABLE | G_PARAM_WRITABLE)); +} + +static void +gfbgraph_simple_authorizer_finalize (GObject *obj) +{ + G_OBJECT_CLASS(parent_class)->finalize (obj); +} + +static void +gfbgraph_simple_authorizer_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + GFBGraphSimpleAuthorizerPrivate *priv; + + priv = GFBGRAPH_SIMPLE_AUTHORIZER_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_ACCESS_TOKEN: + if (priv->access_token) + g_free (priv->access_token); + priv->access_token = g_strdup (g_value_get_string (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gfbgraph_simple_authorizer_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + GFBGraphSimpleAuthorizerPrivate *priv; + + priv = GFBGRAPH_SIMPLE_AUTHORIZER_GET_PRIVATE (object); + + switch (prop_id) { + case PROP_ACCESS_TOKEN: + g_value_set_string (value, priv->access_token); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gfbgraph_simple_authorizer_iface_init (GFBGraphAuthorizerInterface *iface) +{ + iface->process_call = gfbgraph_simple_authorizer_process_call; + iface->process_message = gfbgraph_simple_authorizer_process_message; + iface->refresh_authorization = gfbgraph_simple_authorizer_refresh_authorization; +} + +void +gfbgraph_simple_authorizer_process_call (GFBGraphAuthorizer *iface, RestProxyCall *call) +{ + GFBGraphSimpleAuthorizerPrivate *priv; + + priv = GFBGRAPH_SIMPLE_AUTHORIZER_GET_PRIVATE (GFBGRAPH_SIMPLE_AUTHORIZER (iface)); + + g_mutex_lock (&priv->mutex); + rest_proxy_call_add_param (call, "access_token", priv->access_token); + g_mutex_unlock (&priv->mutex); +} + +void +gfbgraph_simple_authorizer_process_message (GFBGraphAuthorizer *iface, SoupMessage *message) +{ + gchar *auth_value; + SoupURI *uri; + GFBGraphSimpleAuthorizerPrivate *priv; + + priv = GFBGRAPH_SIMPLE_AUTHORIZER_GET_PRIVATE (GFBGRAPH_SIMPLE_AUTHORIZER (iface)); + + g_mutex_lock (&priv->mutex); + + uri = soup_message_get_uri (message); + auth_value = g_strconcat ("access_token=", priv->access_token, NULL); + soup_uri_set_query (uri, auth_value); + + g_free (auth_value); + + g_mutex_unlock (&priv->mutex); +} + +gboolean +gfbgraph_simple_authorizer_refresh_authorization (GFBGraphAuthorizer *iface, GCancellable *cancellable, GError **error) +{ + return FALSE; +} + +/** + * gfbgraph_simple_authorizer_new: + * @access_token: a const @gchar. + * + * Creates a new #GFBGraphAuthorizer to use with the GFBGraph library using the @access_token as access token. + * It's only a test authorizer, don't use in final code. + * + * Returns: (transfer full): a #GFBGraphSimpleAuthorizer. + **/ +GFBGraphSimpleAuthorizer* +gfbgraph_simple_authorizer_new (const gchar *access_token) +{ + return GFBGRAPH_SIMPLE_AUTHORIZER (g_object_new (GFBGRAPH_TYPE_SIMPLE_AUTHORIZER, "access_token", access_token)); +} diff --git a/tests/gfbgraph-simple-authorizer.h b/gfbgraph/gfbgraph-simple-authorizer.h index ddd5e6a..74263e0 100644 --- a/tests/gfbgraph-simple-authorizer.h +++ b/gfbgraph/gfbgraph-simple-authorizer.h @@ -1,3 +1,22 @@ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*- */ +/* + * libgfbgraph - GObject library for Facebook Graph API + * Copyright (C) 2013 Álvaro Peña <alvaropg@gmail.com> + * + * This library is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * libgfbgraph 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + #ifndef __GFBGRAPH_SIMPLE_AUTHORIZER_H__ #define __GFBGRAPH_SIMPLE_AUTHORIZER_H__ @@ -5,7 +24,6 @@ G_BEGIN_DECLS -/* convenience macros */ #define GFBGRAPH_TYPE_SIMPLE_AUTHORIZER (gfbgraph_simple_authorizer_get_type()) #define GFBGRAPH_SIMPLE_AUTHORIZER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GFBGRAPH_TYPE_SIMPLE_AUTHORIZER,GFBGraphSimpleAuthorizer)) #define GFBGRAPH_SIMPLE_AUTHORIZER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GFBGRAPH_TYPE_SIMPLE_AUTHORIZER,GFBGraphSimpleAuthorizerClass)) @@ -20,6 +38,7 @@ typedef struct _GFBGraphSimpleAuthorizerPrivate GFBGraphSimpleAuthorizerPrivate; struct _GFBGraphSimpleAuthorizer { GObject parent; + /*< private >*/ GFBGraphSimpleAuthorizerPrivate *priv; }; @@ -28,7 +47,7 @@ struct _GFBGraphSimpleAuthorizerClass { }; GType gfbgraph_simple_authorizer_get_type (void) G_GNUC_CONST; -GFBGraphSimpleAuthorizer* gfbgraph_simple_authorizer_new (void); +GFBGraphSimpleAuthorizer* gfbgraph_simple_authorizer_new (const gchar *access_token); G_END_DECLS diff --git a/gfbgraph/gfbgraph-user.c b/gfbgraph/gfbgraph-user.c index 74f4c24..af21b7f 100644 --- a/gfbgraph/gfbgraph-user.c +++ b/gfbgraph/gfbgraph-user.c @@ -91,7 +91,7 @@ gfbgraph_user_class_init (GFBGraphUserClass *klass) g_type_class_add_private (gobject_class, sizeof(GFBGraphUserPrivate)); /** - * GFBGraphUser:name + * GFBGraphUser:name: * * The full name of the user **/ @@ -210,7 +210,7 @@ gfbgraph_user_new (void) * * Retrieves a user from the Facebook Graph with the give ID. * - * Returns: a new #GFBGraphUser; unref with g_object_unref() + * Returns: (transfer full): a new #GFBGraphUser; unref with g_object_unref() **/ GFBGraphUser* gfbgraph_user_new_from_id (GFBGraphAuthorizer *authorizer, const gchar *id, GError **error) @@ -226,7 +226,7 @@ gfbgraph_user_new_from_id (GFBGraphAuthorizer *authorizer, const gchar *id, GErr * Retrieve the current user logged using the https://graph.facebook.com/me Graph API function. * See gfbgraph_user_get_my_async() for the asynchronous version of this call. * - * Returns: a #GFBGraphUser with the current user information. + * Returns: (transfer full): a #GFBGraphUser with the current user information. **/ GFBGraphUser* gfbgraph_user_get_me (GFBGraphAuthorizer *authorizer, GError **error) @@ -306,7 +306,7 @@ gfbgraph_user_get_me_async (GFBGraphAuthorizer *authorizer, GCancellable *cancel * Finishes an asynchronous operation started with * gfbgraph_user_get_me_async(). * - * Returns: a #GFBGraphUser for to the current user logged. + * Returns: (transfer full): a #GFBGraphUser for to the current user logged. **/ GFBGraphUser* gfbgraph_user_get_me_async_finish (GFBGraphAuthorizer *authorizer, GAsyncResult *result, GError **error) @@ -334,7 +334,7 @@ gfbgraph_user_get_me_async_finish (GFBGraphAuthorizer *authorizer, GAsyncResult * * Retrieve the albums nodes owned by the @user. This functions call the function ID/albums. * - * Returns: a #GList with the albums nodes (#GFBGraphAlbums) owned by the given user. + * Returns: (transfer full): a #GList with the albums nodes (#GFBGraphAlbums) owned by the given user. **/ GList* gfbgraph_user_get_albums (GFBGraphUser *user, GFBGraphAuthorizer *authorizer, GError **error) @@ -393,7 +393,7 @@ gfbgraph_user_get_albums_async (GFBGraphUser *user, GFBGraphAuthorizer *authoriz * Finishes an asynchronous operation started with * gfbgraph_user_get_albums_async(). * - * Returns: a #GList of #GFBGraphAlbums owned by the @user. + * Returns: (transfer full): a #GList of #GFBGraphAlbums owned by the @user. **/ GList* gfbgraph_user_get_albums_async_finish (GFBGraphUser *user, GAsyncResult *result, GError **error) diff --git a/gfbgraph/gfbgraph-user.h b/gfbgraph/gfbgraph-user.h index ed8500b..f17a4dd 100644 --- a/gfbgraph/gfbgraph-user.h +++ b/gfbgraph/gfbgraph-user.h @@ -41,6 +41,7 @@ typedef struct _GFBGraphUserPrivate GFBGraphUserPrivate; struct _GFBGraphUser { GFBGraphNode parent; + /*< private >*/ GFBGraphUserPrivate *priv; }; diff --git a/tests/Makefile.am b/tests/Makefile.am index cceeab6..b67ad00 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,6 @@ TESTS = gtestutils test test-async -COMMON_SRC = credentials.h gfbgraph-simple-authorizer.h gfbgraph-simple-authorizer.c +COMMON_SRC = credentials.h AM_CPPFLAGS = -I$(top_srcdir) $(LIBGFBGRAPH_CFLAGS) AM_LDFLAGS = $(top_srcdir)/gfbgraph/libgfbgraph-@API_VERSION@.la $(LIBGFBGRAPH_LIBS) diff --git a/tests/credentials.h b/tests/credentials.h index ca153dd..6c4c519 100644 --- a/tests/credentials.h +++ b/tests/credentials.h @@ -1,2 +1,2 @@ #define GFBGRAPH_TEST_CLIENT_ID "" -#define GFBGRAPH_TEST_ACCESS_TOKEN "" +#define GFBGRAPH_TEST_ACCESS_TOKEN "CAACTgyJojTcBAJelKI3WZCsI665G4qUjZCSSZCvgEW2l311UYYxn6WOWPZBYAOQUljOwOsEIUKE1xAUKndnPqZAp27f0srnZA59jCwu45HTo4Y3u7ZCLJIGmVDZCcZAB5uch7QM4Qp9ANomSEUDgsLkjkdlFm6CYA8sYZD" diff --git a/tests/gfbgraph-simple-authorizer.c b/tests/gfbgraph-simple-authorizer.c deleted file mode 100644 index 61ba604..0000000 --- a/tests/gfbgraph-simple-authorizer.c +++ /dev/null @@ -1,102 +0,0 @@ -#include "gfbgraph-simple-authorizer.h" -#include "credentials.h" - -#include <gfbgraph/gfbgraph-authorizer.h> - -struct _GFBGraphSimpleAuthorizerPrivate { - GMutex mutex; -}; - -static void gfbgraph_simple_authorizer_init (GFBGraphSimpleAuthorizer *obj); -static void gfbgraph_simple_authorizer_class_init (GFBGraphSimpleAuthorizerClass *klass); -static void gfbgraph_simple_authorizer_finalize (GObject *obj); - -static void gfbgraph_simple_authorizer_iface_init (GFBGraphAuthorizerInterface *iface); - -void gfbgraph_simple_authorizer_process_call (GFBGraphAuthorizer *iface, RestProxyCall *call); -void gfbgraph_simple_authorizer_process_message (GFBGraphAuthorizer *iface, SoupMessage *message); -gboolean gfbgraph_simple_authorizer_refresh_authorization (GFBGraphAuthorizer *iface, GCancellable *cancellable, GError **error); - -#define GFBGRAPH_SIMPLE_AUTHORIZER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), GFBGRAPH_TYPE_SIMPLE_AUTHORIZER, GFBGraphSimpleAuthorizerPrivate)) - -static GObjectClass *parent_class = NULL; - -G_DEFINE_TYPE_WITH_CODE (GFBGraphSimpleAuthorizer, gfbgraph_simple_authorizer, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (GFBGRAPH_TYPE_AUTHORIZER, gfbgraph_simple_authorizer_iface_init)); - - -static void -gfbgraph_simple_authorizer_init (GFBGraphSimpleAuthorizer *obj) -{ - obj->priv = GFBGRAPH_SIMPLE_AUTHORIZER_GET_PRIVATE(obj); - g_mutex_init (&obj->priv->mutex); -} - -static void -gfbgraph_simple_authorizer_class_init (GFBGraphSimpleAuthorizerClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); - gobject_class->finalize = gfbgraph_simple_authorizer_finalize; - - g_type_class_add_private (gobject_class, sizeof(GFBGraphSimpleAuthorizerPrivate)); -} - -static void -gfbgraph_simple_authorizer_finalize (GObject *obj) -{ - G_OBJECT_CLASS(parent_class)->finalize (obj); -} - -static void -gfbgraph_simple_authorizer_iface_init (GFBGraphAuthorizerInterface *iface) -{ - iface->process_call = gfbgraph_simple_authorizer_process_call; - iface->process_message = gfbgraph_simple_authorizer_process_message; - iface->refresh_authorization = gfbgraph_simple_authorizer_refresh_authorization; -} - -void -gfbgraph_simple_authorizer_process_call (GFBGraphAuthorizer *iface, RestProxyCall *call) -{ - GFBGraphSimpleAuthorizerPrivate *priv; - - priv = GFBGRAPH_SIMPLE_AUTHORIZER_GET_PRIVATE (GFBGRAPH_SIMPLE_AUTHORIZER (iface)); - - g_mutex_lock (&priv->mutex); - rest_proxy_call_add_param (call, "access_token", GFBGRAPH_TEST_ACCESS_TOKEN); - g_mutex_unlock (&priv->mutex); -} - -void -gfbgraph_simple_authorizer_process_message (GFBGraphAuthorizer *iface, SoupMessage *message) -{ - gchar *auth_value; - SoupURI *uri; - GFBGraphSimpleAuthorizerPrivate *priv; - - priv = GFBGRAPH_SIMPLE_AUTHORIZER_GET_PRIVATE (GFBGRAPH_SIMPLE_AUTHORIZER (iface)); - - g_mutex_lock (&priv->mutex); - - uri = soup_message_get_uri (message); - auth_value = g_strconcat ("access_token=", GFBGRAPH_TEST_ACCESS_TOKEN, NULL); - soup_uri_set_query (uri, auth_value); - - g_free (auth_value); - - g_mutex_unlock (&priv->mutex); -} - -gboolean -gfbgraph_simple_authorizer_refresh_authorization (GFBGraphAuthorizer *iface, GCancellable *cancellable, GError **error) -{ - return FALSE; -} - -GFBGraphSimpleAuthorizer* -gfbgraph_simple_authorizer_new (void) -{ - return GFBGRAPH_SIMPLE_AUTHORIZER (g_object_new (GFBGRAPH_TYPE_SIMPLE_AUTHORIZER, NULL)); -} diff --git a/tests/gtestutils.c b/tests/gtestutils.c index e755ce4..0970b3d 100644 --- a/tests/gtestutils.c +++ b/tests/gtestutils.c @@ -1,8 +1,9 @@ #include "config.h" +#include "credentials.h" #include <glib.h> #include <gfbgraph/gfbgraph.h> +#include <gfbgraph/gfbgraph-simple-authorizer.h> -#include "gfbgraph-simple-authorizer.h" int main (int argc, char **argv) @@ -12,7 +13,7 @@ main (int argc, char **argv) g_type_init (); g_test_init (&argc, &argv, NULL); - authorizer = gfbgraph_simple_authorizer_new (); + authorizer = gfbgraph_simple_authorizer_new (GFBGRAPH_TEST_ACCESS_TOKEN); //g_test_add_data_func ("/GInstapaper/Bookmarks/List", proxy, (GTestDataFunc) ginstapaper_test_bookmarks_list); diff --git a/tests/test-async.c b/tests/test-async.c index df99b8d..bf43f20 100644 --- a/tests/test-async.c +++ b/tests/test-async.c @@ -1,5 +1,6 @@ #include <gfbgraph/gfbgraph.h> -#include "gfbgraph-simple-authorizer.h" +#include <gfbgraph/gfbgraph-simple-authorizer.h> +#include "credentials.h" static GMainLoop *main_loop; @@ -104,7 +105,7 @@ main (int argc, char **argv) g_type_init (); main_loop = g_main_loop_new (NULL, TRUE); - authorizer = gfbgraph_simple_authorizer_new (); + authorizer = gfbgraph_simple_authorizer_new (GFBGRAPH_TEST_ACCESS_TOKEN); /* Get "me" user */ gfbgraph_user_get_me_async (GFBGRAPH_AUTHORIZER (authorizer), NULL, (GAsyncReadyCallback) me_async_cb, NULL); diff --git a/tests/test.c b/tests/test.c index 9b4c8da..c186774 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1,5 +1,6 @@ #include <gfbgraph/gfbgraph.h> -#include "gfbgraph-simple-authorizer.h" +#include <gfbgraph/gfbgraph-simple-authorizer.h> +#include "credentials.h" int main (int argc, char **argv) @@ -12,7 +13,7 @@ main (int argc, char **argv) g_type_init (); - authorizer = gfbgraph_simple_authorizer_new (); + authorizer = gfbgraph_simple_authorizer_new (GFBGRAPH_TEST_ACCESS_TOKEN); /* Get "me" user */ me = gfbgraph_user_get_me (GFBGRAPH_AUTHORIZER (authorizer), &error); |