Commit e33112bf authored by Álvaro Peña's avatar Álvaro Peña

First commit, some use of the API for user, album and photo

parents
Álvaro Peña <alvaropg@gmail.com>
This diff is collapsed.
This diff is collapsed.
SUBDIRS = gfbgraph tests
ACLOCAL_AMFLAGS = -I m4
libgfbgraphdocdir = ${prefix}/doc/libgfbgraph
libgfbgraphdoc_DATA = \
README\
COPYING\
AUTHORS\
ChangeLog\
INSTALL\
NEWS
%-$(API_VERSION).pc: %.pc
$(AM_V_GEN)cp $< $@
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libgfbgraph-$(API_VERSION).pc
CLEANFILES = $(pkgconfig_DATA)
all-local: libgfbgraph-$(API_VERSION).pc
EXTRA_DIST = $(libgfbgraphdoc_DATA)
# Introspection
DISTCHECK_CONFIGURE_FLAGS = --enable-introspection
EXTRA_DIST += m4/introspection.m4
# Remove doc directory on uninstall
uninstall-local:
-rm -r $(libgfbgraphdocdir)
-include $(top_srcdir)/git.mk
LibGFBGraph
==============
A GObject library for Facebook Graph API
This library is in a very early stage of development,
don't use in a final application right now. Use it just
for test purposes at your own risk.
#!/bin/sh
set -e
test -n "$srcdir" || srcdir=`dirname "$0"`
test -n "$srcdir" || srcdir=.
olddir=`pwd`
cd "$srcdir"
ACLOCAL="${ACLOCAL-aclocal} $ACLOCAL_FLAGS" autoreconf -v -i
cd "$olddir"
test -n "$NOCONFIGURE" || "$srcdir/configure" "$@"
m4_define([api_major], [0])
m4_define([api_minor], [1])
m4_define([gfbgraph_version], [api_major.api_minor])
AC_PREREQ([2.63])
AC_INIT([gfbgraph], [gfbgraph_version],
[],
[gfbgraph],
[https://github.com/alvaropg/libgfbgraph.git])
AC_CONFIG_SRCDIR([gfbgraph/gfbgraph-proxy.h])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([1.11 -Wno-portability])
AM_SILENT_RULES([yes])
API_MAJOR=api_major
API_MINOR=api_minor
AC_SUBST([API_MAJOR],[$API_MAJOR])
AC_SUBST([API_MINOR],[$API_MINOR])
AC_SUBST([API_VERSION],[$API_MAJOR.$API_MINOR])
AC_SUBST([API_VERSION_AM],[$API_MAJOR\_$API_MINOR])
AC_DEFINE_UNQUOTED(API_VERSION, [$API_VERSION], [API version])
AC_PROG_CC
LT_INIT
GOBJECT_INTROSPECTION_CHECK([1.30.0])
PKG_CHECK_MODULES(LIBGFBGRAPH, [glib-2.0 rest-0.7 gobject-2.0 json-glib-1.0])
AC_OUTPUT([
Makefile
libgfbgraph.pc
gfbgraph/Makefile
tests/Makefile])
lib_sources = \
gfbgraph-album.c \
gfbgraph-authorizer.c \
gfbgraph-common.c \
gfbgraph-connectable.c \
gfbgraph-node.c \
gfbgraph-photo.c \
gfbgraph-user.c
lib_headers = \
gfbgraph.h \
gfbgraph-album.h \
gfbgraph-authorizer.h \
gfbgraph-common.h \
gfbgraph-connectable.h \
gfbgraph-node.h \
gfbgraph-photo.h \
gfbgraph-user.h
lib_LTLIBRARIES = libgfbgraph-@API_VERSION@.la
libgfbgraph_@API_VERSION@_la_CFLAGS = $(LIBGFBGRAPH_CFLAGS) -I$(top_srcdir) \
-Wall -g -DG_LOG_DOMAIN=\"GFBGraph\"
libgfbgraph_@API_VERSION@_la_LDFLAGS = -no-undefined
libgfbgraph_@API_VERSION@_la_LIBADD = $(LIBGFBGRAPH_LIBS)
libgfbgraph_@API_VERSION@_la_SOURCES = $(lib_sources) $(lib_headers)
libgfbgraph_@API_VERSION@_la_HEADERS = $(lib_headers)
libgfbgraph_@API_VERSION@_ladir = $(includedir)/gfbgraph-@API_VERSION@/gfbgraph
# Introspection
-include $(INTROSPECTION_MAKEFILE)
INTROSPECTION_GIRS =
INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir)
INTROSPECTION_COMPILER_ARGS = --includedir=$(srcdir)
if HAVE_INTROSPECTION
introspection_sources = $(libgfbgraph_@API_MAJOR@_@API_MINOR@_la_SOURCES)
GFBGraph-@API_VERSION@.gir: libgfbgraph-@API_VERSION@.la
GFBGraph_@API_MAJOR@_@API_MINOR@_gir_INCLUDES = GObject-2.0 Rest-0.7 Json-1.0
GFBGraph_@API_MAJOR@_@API_MINOR@_gir_CFLAGS = $(LIBGFBGRAPH_CFLAGS) -I$(top_srcdir)
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_SCANNERFLAGS = \
--nsversion=$(API_VERSION) \
--symbol-prefix=gfbgraph \
--c-include="gfbgraph/gfbgraph.h"
INTROSPECTION_GIRS += GFBGraph-$(API_VERSION).gir
girdir = $(datadir)/gir-1.0
gir_DATA = $(INTROSPECTION_GIRS)
typelibdir = ../girepository-1.0
typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
CLEANFILES = $(gir_DATA) $(typelib_DATA)
endif
-include $(top_srcdir)/git.mk
/* -*- 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.
*
* libginstapaper 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/>.
*/
#include "gfbgraph-album.h"
#include "gfbgraph-user.h"
#include "gfbgraph-connectable.h"
enum {
PROP_O,
PROP_NAME,
PROP_DESCRIPTION,
PROP_COVER_PHOTO,
PROP_COUNT
};
struct _GFBGraphAlbumPrivate {
gchar *name;
gchar *description;
gchar *cover_photo;
guint count;
};
static void gfbgraph_album_init (GFBGraphAlbum *obj);
static void gfbgraph_album_class_init (GFBGraphAlbumClass *klass);
static void gfbgraph_album_finalize (GObject *obj);
static void gfbgraph_album_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
static void gfbgraph_album_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
static void gfbgraph_album_connectable_iface_init (GFBGraphConnectableInterface *iface);
GHashTable* gfbgraph_album_get_connection_post_params (GFBGraphConnectable *self, GType node_type);
#define GFBGRAPH_ALBUM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), GFBGRAPH_TYPE_ALBUM, GFBGraphAlbumPrivate))
static GFBGraphNodeClass *parent_class = NULL;
G_DEFINE_TYPE_WITH_CODE (GFBGraphAlbum, gfbgraph_album, GFBGRAPH_TYPE_NODE,
G_IMPLEMENT_INTERFACE (GFBGRAPH_TYPE_CONNECTABLE, gfbgraph_album_connectable_iface_init));
static void
gfbgraph_album_init (GFBGraphAlbum *obj)
{
obj->priv = GFBGRAPH_ALBUM_GET_PRIVATE(obj);
}
static void
gfbgraph_album_class_init (GFBGraphAlbumClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
gobject_class->finalize = gfbgraph_album_finalize;
gobject_class->set_property = gfbgraph_album_set_property;
gobject_class->get_property = gfbgraph_album_get_property;
g_type_class_add_private (gobject_class, sizeof(GFBGraphAlbumPrivate));
g_object_class_install_property (gobject_class,
PROP_NAME,
g_param_spec_string ("name",
"The title", "The name of the album",
"",
G_PARAM_READABLE | G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class,
PROP_DESCRIPTION,
g_param_spec_string ("description",
"The description", "The description of the album",
"",
G_PARAM_READABLE | G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class,
PROP_COVER_PHOTO,
g_param_spec_string ("cover_photo",
"Cover photo", "The ID for the cover photo of the album",
"",
G_PARAM_READABLE | G_PARAM_WRITABLE));
g_object_class_install_property (gobject_class,
PROP_COUNT,
g_param_spec_uint ("count",
"Number of photos", "The number of photos in the album",
0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_WRITABLE));
}
static void
gfbgraph_album_finalize (GObject *obj)
{
G_OBJECT_CLASS(parent_class)->finalize (obj);
}
static void
gfbgraph_album_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
GFBGraphAlbumPrivate *priv;
priv = GFBGRAPH_ALBUM_GET_PRIVATE (object);
switch (prop_id) {
case PROP_NAME:
if (priv->name)
g_free (priv->name);
priv->name = g_strdup (g_value_get_string (value));
break;
case PROP_DESCRIPTION:
if (priv->description)
g_free (priv->description);
priv->description = g_strdup (g_value_get_string (value));
break;
case PROP_COVER_PHOTO:
if (priv->cover_photo)
g_free (priv->cover_photo);
priv->cover_photo = g_strdup (g_value_get_string (value));
break;
case PROP_COUNT:
priv->count = g_value_get_uint (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gfbgraph_album_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
GFBGraphAlbumPrivate *priv;
priv = GFBGRAPH_ALBUM_GET_PRIVATE (object);
switch (prop_id) {
case PROP_NAME:
g_value_set_string (value, priv->name);
break;
case PROP_DESCRIPTION:
g_value_set_string (value, priv->description);
break;
case PROP_COVER_PHOTO:
g_value_set_string (value, priv->cover_photo);
break;
case PROP_COUNT:
g_value_set_uint (value, priv->count);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gfbgraph_album_connectable_iface_init (GFBGraphConnectableInterface *iface)
{
GHashTable *connections;
connections = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (connections, (gpointer) g_type_name (GFBGRAPH_TYPE_USER), (gpointer) "albums");
iface->connections = connections;
iface->get_connection_post_params = gfbgraph_album_get_connection_post_params;
iface->parse_connected_data = gfbgraph_connectable_default_parse_connected_data;
}
GHashTable*
gfbgraph_album_get_connection_post_params (GFBGraphConnectable *self, GType node_type)
{
GHashTable *params;
GFBGraphAlbumPrivate *priv;
priv = GFBGRAPH_ALBUM_GET_PRIVATE (self);
params = g_hash_table_new (g_str_hash, g_str_equal);
g_hash_table_insert (params, "name", priv->name);
if (priv->description != NULL)
g_hash_table_insert (params, "message", priv->description);
/* TODO: Incorpate the "privacy" param */
return params;
}
GFBGraphAlbum*
gfbgraph_album_new (void)
{
return GFBGRAPH_ALBUM (g_object_new(GFBGRAPH_TYPE_ALBUM, NULL));
}
/* -*- 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.
*
* libginstapaper 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_ALBUM_H__
#define __GFBGRAPH_ALBUM_H__
#include <gfbgraph/gfbgraph-node.h>
G_BEGIN_DECLS
#define GFBGRAPH_TYPE_ALBUM (gfbgraph_album_get_type())
#define GFBGRAPH_ALBUM(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GFBGRAPH_TYPE_ALBUM,GFBGraphAlbum))
#define GFBGRAPH_ALBUM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GFBGRAPH_TYPE_ALBUM,GFBGraphAlbumClass))
#define GFBGRAPH_IS_ALBUM(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GFBGRAPH_TYPE_ALBUM))
#define GFBGRAPH_IS_ALBUM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GFBGRAPH_TYPE_ALBUM))
#define GFBGRAPH_ALBUM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GFBGRAPH_TYPE_ALBUM,GFBGraphAlbumClass))
typedef struct _GFBGraphAlbum GFBGraphAlbum;
typedef struct _GFBGraphAlbumClass GFBGraphAlbumClass;
typedef struct _GFBGraphAlbumPrivate GFBGraphAlbumPrivate;
struct _GFBGraphAlbum {
GFBGraphNode parent;
GFBGraphAlbumPrivate *priv;
};
struct _GFBGraphAlbumClass {
GFBGraphNodeClass parent_class;
};
GType gfbgraph_album_get_type (void) G_GNUC_CONST;
GFBGraphAlbum* gfbgraph_album_new (void);
G_END_DECLS
#endif /* __GFBGRAPH_ALBUM_H__ */
/* -*- 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.
*
* libginstapaper 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/>.
*/
#include "gfbgraph-authorizer.h"
G_DEFINE_INTERFACE (GFBGraphAuthorizer, gfbgraph_authorizer, G_TYPE_OBJECT)
static void
gfbgraph_authorizer_default_init (GFBGraphAuthorizerInterface *iface)
{
}
/**
* GFBGraph_authorizer_process_call:
* @iface: A #GFBGraphAuthorizer.
* @call: A #RestProxyCall.
*
* Adds the necessary authorization to @call.
*
* This method modifies @call in place and is thread safe.
*/
void
gfbgraph_authorizer_process_call (GFBGraphAuthorizer *iface, RestProxyCall *call)
{
g_return_if_fail (GFBGRAPH_IS_AUTHORIZER (iface));
GFBGRAPH_AUTHORIZER_GET_IFACE (iface)->process_call (iface, call);
}
/**
* GFBGraph_authorizer_process_message:
* @iface: A #GFBGraphAuthorizer.
* @message: A #SoupMessage.
*
* Adds the necessary authorization to @message. The type of @message
* can be DELETE, GET and POST.
*
* This method modifies @message in place and is thread safe.
*/
void
gfbgraph_authorizer_process_message (GFBGraphAuthorizer *iface, SoupMessage *message)
{
g_return_if_fail (GFBGRAPH_IS_AUTHORIZER (iface));
GFBGRAPH_AUTHORIZER_GET_IFACE (iface)->process_message (iface, message);
}
/**
* GFBGraph_authorizer_refresh_authorization:
* @iface: A #GFBGraphAuthorizer.
* @cancellable: (allow-none): An optional #GCancellable object, or
* %NULL.
* @error: (allow-none): An optional #GError, or %NULL.
*
* Synchronously forces @iface to refresh any authorization tokens
* held by it.
*
* This method is thread safe.
*
* Returns: %TRUE if the authorizer now has a valid token.
*/
gboolean
gfbgraph_authorizer_refresh_authorization (GFBGraphAuthorizer *iface, GCancellable *cancellable, GError **error)
{
g_return_val_if_fail (GFBGRAPH_IS_AUTHORIZER (iface), FALSE);
return GFBGRAPH_AUTHORIZER_GET_IFACE (iface)->refresh_authorization (iface, cancellable, error);
}
/* -*- 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.
*
* libginstapaper 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_AUTHORIZER_H__
#define __GFBGRAPH_AUTHORIZER_H__
#include <glib-object.h>
#include <gio/gio.h>
#include <libsoup/soup.h>
#include <rest/rest-proxy-call.h>
G_BEGIN_DECLS
#define GFBGRAPH_TYPE_AUTHORIZER (gfbgraph_authorizer_get_type ())
#define GFBGRAPH_AUTHORIZER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GFBGRAPH_TYPE_AUTHORIZER, GFBGraphAuthorizer))
#define GFBGRAPH_AUTHORIZER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GFBGRAPH_TYPE_AUTHORIZER, GFBGraphAuthorizerInterface))
#define GFBGRAPH_IS_AUTHORIZER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GFBGRAPH_TYPE_AUTHORIZER))
#define GFBGRAPH_AUTHORIZER_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), GFBGRAPH_TYPE_AUTHORIZER, GFBGraphAuthorizerInterface))
typedef struct _GFBGraphAuthorizer GFBGraphAuthorizer;
typedef struct _GFBGraphAuthorizerInterface GFBGraphAuthorizerInterface;
struct _GFBGraphAuthorizerInterface {
GTypeInterface parent;
void (*process_call) (GFBGraphAuthorizer *iface,
RestProxyCall *call);
void (*process_message) (GFBGraphAuthorizer *iface,
SoupMessage *message);
gboolean (*refresh_authorization) (GFBGraphAuthorizer *iface,
GCancellable *cancellable,
GError **error);
};
GType gfbgraph_authorizer_get_type (void) G_GNUC_CONST;
void gfbgraph_authorizer_process_call (GFBGraphAuthorizer *iface,
RestProxyCall *call);
void gfbgraph_authorizer_process_message (GFBGraphAuthorizer *iface,
SoupMessage *message);
gboolean gfbgraph_authorizer_refresh_authorization (GFBGraphAuthorizer *iface,
GCancellable *cancellable,
GError **error);
G_END_DECLS
#endif /* __GFBGRAPH_AUTHORIZER_H__ */
/* -*- 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.
*
* libginstapaper 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/>.
*/
#include "gfbgraph-common.h"
#include <rest/rest-proxy.h>
#define FACEBOOK_ENDPOINT "https://graph.facebook.com"
RestProxyCall*
gfbgraph_new_rest_call (GFBGraphAuthorizer *authorizer)
{
RestProxy *proxy;
RestProxyCall *rest_call;
g_return_val_if_fail (GFBGRAPH_IS_AUTHORIZER (authorizer), NULL);
proxy = rest_proxy_new (FACEBOOK_ENDPOINT, FALSE);
rest_call = rest_proxy_new_call (proxy);
gfbgraph_authorizer_process_call (authorizer, rest_call);
g_object_unref (proxy);
return rest_call;
}
/* -*- 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.
*
* libginstapaper 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_COMMON_H__
#define __GFBGRAPH_COMMON_H__
#include <rest/rest-proxy-call.h>
#include <gfbgraph/gfbgraph-authorizer.h>
RestProxyCall* gfbgraph_new_rest_call (GFBGraphAuthorizer *authorizer);
#endif /* __GFBGRAPH_COMMON_H__ */
/* -*- 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.
*
* libginstapaper 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/>.
*/
#include "gfbgraph-connectable.h"
#include "gfbgraph-node.h"
#include <json-glib/json-glib.h>
G_DEFINE_INTERFACE (GFBGraphConnectable, gfbgraph_connectable, GFBGRAPH_TYPE_NODE)
static void
gfbgraph_connectable_default_init (GFBGraphConnectableInterface *iface)
{
iface->connections = NULL;
iface->get_connection_post_params = NULL;
iface->parse_connected_data = NULL;
}
static GHashTable*
get_connections (GFBGraphConnectableInterface *iface)
{
GHashTable *connections;
connections = iface->connections;
/* If no connections... Why you implement this iface? */
g_assert (g_hash_table_size (connections) > 0);
return connections;
}
GHashTable*
gfbgraph_connectable_get_connection_post_params (GFBGraphConnectable *self, GType node_type)
{
GFBGraphConnectableInterface *iface;
g_return_val_if_fail (GFBGRAPH_IS_CONNECTABLE (self), NULL);
g_return_val_if_fail (g_type_is_a (node_type, GFBGRAPH_TYPE_NODE), NULL);
g_return_val_if_fail (gfbgraph_connectable_is_connectable_to (self, node_type), NULL);
iface = GFBGRAPH_CONNECTABLE_GET_IFACE (self);
g_assert (iface->get_connection_post_params != NULL);
return iface->get_connection_post_params (self, node_type);
}
GList*
gfbgraph_connectable_parse_connected_data (GFBGraphConnectable *self, const gchar *payload, GError **error)
{
GFBGraphConnectableInterface *iface;
g_return_val_if_fail (GFBGRAPH_IS_CONNECTABLE (self), NULL);
iface = GFBGRAPH_CONNECTABLE_GET_IFACE (self);
g_assert (iface->parse_connected_data != NULL);
return iface->parse_connected_data (self, payload, error);
}
gboolean
gfbgraph_connectable_is_connectable_to (GFBGraphConnectable *self, GType node_type)
{
GFBGraphConnectableInterface *iface;
GHashTable *connections;
g_return_val_if_fail (GFBGRAPH_IS_CONNECTABLE (self), FALSE);
g_return_val_if_fail (g_type_is_a (node_type, GFBGRAPH_TYPE_NODE), FALSE);
iface = GFBGRAPH_CONNECTABLE_GET_IFACE (self);
connections = get_connections (iface);
return g_hash_table_contains (connections, g_type_name (node_type));
}
const gchar*
gfbgraph_connectable_get_connection_path (GFBGraphConnectable *self, GType node_type)
{