[libsocialweb: 1/7] smugmug: Added SmugMug module.



commit 16c49889e144e21a459d847d969b36d3a03e4b52
Author: Eitan Isaacson <eitan isaacson collabora co uk>
Date:   Thu Feb 10 14:49:12 2011 -0800

    smugmug: Added SmugMug module.

 configure.ac                     |    2 +
 libsocialweb/sw-debug.c          |    1 +
 libsocialweb/sw-debug.h          |    1 +
 services/Makefile.am             |    4 +
 services/smugmug/Makefile.am     |   20 ++++
 services/smugmug/module.c        |   32 +++++++
 services/smugmug/smugmug.c       |  177 ++++++++++++++++++++++++++++++++++++++
 services/smugmug/smugmug.h       |   62 +++++++++++++
 services/smugmug/smugmug.keys.in |   11 +++
 9 files changed, 310 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 796baeb..bbc5793 100644
--- a/configure.ac
+++ b/configure.ac
@@ -130,6 +130,7 @@ SOCIALWEB_ENABLE_SERVICE(Flickr, flickr, FLICKR)
 SOCIALWEB_ENABLE_SERVICE(Last.fm, lastfm, LASTFM)
 SOCIALWEB_ENABLE_SERVICE(Twitter, twitter, TWITTER)
 SOCIALWEB_ENABLE_SERVICE(Vimeo, vimeo, VIMEO)
+SOCIALWEB_ENABLE_SERVICE(SumMug, smugmug, SMUGMUG)
 
 servicesdir='${libdir}'/libsocialweb/services
 AC_SUBST(servicesdir)
@@ -186,6 +187,7 @@ AC_OUTPUT([
         services/lastfm/Makefile
         services/twitter/Makefile
         services/vimeo/Makefile
+	services/smugmug/Makefile
         tests/Makefile
         tools/Makefile
         examples/Makefile
diff --git a/libsocialweb/sw-debug.c b/libsocialweb/sw-debug.c
index 0569326..6480bd7 100644
--- a/libsocialweb/sw-debug.c
+++ b/libsocialweb/sw-debug.c
@@ -37,6 +37,7 @@ sw_debug_init (const char *string)
     { "core", SW_DEBUG_CORE },
     { "vimeo", SW_DEBUG_VIMEO },
     { "flickr", SW_DEBUG_FLICKR },
+    { "smugmug", SW_DEBUG_SMUGMUG },
     { "client-monitor", SW_DEBUG_CLIENT_MONITOR }
   };
 
diff --git a/libsocialweb/sw-debug.h b/libsocialweb/sw-debug.h
index ca23096..a9f8b4f 100644
--- a/libsocialweb/sw-debug.h
+++ b/libsocialweb/sw-debug.h
@@ -28,6 +28,7 @@ typedef enum {
   SW_DEBUG_CORE = 1 << 6,
   SW_DEBUG_VIMEO = 1 << 7,
   SW_DEBUG_FLICKR = 1 << 8,
+  SW_DEBUG_SMUGMUG = 1 << 7,
   SW_DEBUG_CLIENT_MONITOR = 1 << 9
 } SwDebugFlags;
 
diff --git a/services/Makefile.am b/services/Makefile.am
index d049379..1633760 100644
--- a/services/Makefile.am
+++ b/services/Makefile.am
@@ -19,3 +19,7 @@ endif
 if WITH_VIMEO
 SUBDIRS += vimeo
 endif
+
+if WITH_SMUGMUG
+SUBDIRS += smugmug
+endif
diff --git a/services/smugmug/Makefile.am b/services/smugmug/Makefile.am
new file mode 100644
index 0000000..44341cf
--- /dev/null
+++ b/services/smugmug/Makefile.am
@@ -0,0 +1,20 @@
+services_LTLIBRARIES = libsmugmug.la
+libsmugmug_la_SOURCES = module.c \
+		      smugmug.c smugmug.h
+
+libsmugmug_la_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/interfaces \
+		     $(REST_CFLAGS) $(KEYRING_CFLAGS) \
+		     $(DBUS_GLIB_CFLAGS) -DG_LOG_DOMAIN=\"SmugMug\" \
+		     $(GCOV_CFLAGS)
+libsmugmug_la_LIBADD = $(top_builddir)/libsocialweb/libsocialweb.la \
+		     $(top_builddir)/interfaces/libsocialweb-ginterfaces.la \
+		     $(top_builddir)/libsocialweb-keystore/libsocialweb-keystore.la \
+		     $(top_builddir)/libsocialweb-keyfob/libsocialweb-keyfob.la \
+		     $(REST_LIBS) $(KEYRING_LIBS) $(DBUS_GLIB_LIBS) \
+		     $(GCOV_LDFLAGS)
+libsmugmug_la_LDFLAGS = -module -avoid-version
+
+servicesdata_DATA = smugmug.keys
+CLEANFILES = smugmug.keys
+EXTRA_DIST = smugmug.keys.in
+ INTLTOOL_SOCIALWEB_KEYS@
diff --git a/services/smugmug/module.c b/services/smugmug/module.c
new file mode 100644
index 0000000..1bb40af
--- /dev/null
+++ b/services/smugmug/module.c
@@ -0,0 +1,32 @@
+/*
+ * libsocialweb - social data store
+ * Copyright (C) 2010 Intel Corporation.
+ *
+ * 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.
+ */
+
+#include <libsocialweb/sw-module.h>
+#include "smugmug.h"
+
+const gchar *
+sw_module_get_name (void)
+{
+  return "smugmug";
+}
+
+const GType
+sw_module_get_type (void)
+{
+  return SW_TYPE_SERVICE_SMUGMUG;
+}
diff --git a/services/smugmug/smugmug.c b/services/smugmug/smugmug.c
new file mode 100644
index 0000000..11c68ff
--- /dev/null
+++ b/services/smugmug/smugmug.c
@@ -0,0 +1,177 @@
+/*
+ * libsocialweb SmugMug service support
+ *
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * Authors: Eitan Isaacson <eitan isaacson collabora co uk>
+ *
+ * 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.
+ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <gnome-keyring.h>
+
+#include <libsocialweb/sw-service.h>
+#include <libsocialweb/sw-item.h>
+#include <libsocialweb/sw-utils.h>
+#include <libsocialweb/sw-web.h>
+#include <libsocialweb/sw-call-list.h>
+#include <libsocialweb/sw-debug.h>
+#include <libsocialweb/sw-client-monitor.h>
+#include <libsocialweb/sw-online.h>
+#include <libsocialweb-keyfob/sw-keyfob.h>
+#include <libsocialweb-keystore/sw-keystore.h>
+
+#include <rest/oauth-proxy.h>
+#include <rest/rest-xml-parser.h>
+
+#include <interfaces/sw-collections-ginterface.h>
+
+#include "smugmug.h"
+
+#define OAUTH_URL "http://api.smugmug.com/services/oauth/";
+#define REST_URL "https://secure.smugmug.com/services/api/rest/1.2.2/";
+
+static void collections_iface_init (gpointer g_iface, gpointer iface_data);
+
+G_DEFINE_TYPE_WITH_CODE (SwServiceSmugmug, sw_service_smugmug, SW_TYPE_SERVICE,
+                         G_IMPLEMENT_INTERFACE (SW_TYPE_COLLECTIONS_IFACE,
+                                                collections_iface_init));
+
+#define GET_PRIVATE(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), SW_TYPE_SERVICE_SMUGMUG, SwServiceSmugmugPrivate))
+
+struct _SwServiceSmugmugPrivate {
+  RestProxy *proxy;
+};
+
+static const char *
+get_name (SwService *service)
+{
+  return "smugmug";
+}
+
+static const char **
+get_static_caps (SwService *service)
+{
+  static const char * caps[] = {
+    HAS_BANISHABLE_IFACE,
+
+    NULL
+  };
+
+  return caps;
+}
+
+static void
+got_tokens_cb (RestProxy *proxy, gboolean authorised, gpointer user_data)
+{
+  SwServiceSmugmug *self = (SwServiceSmugmug *) user_data;
+  SwServiceSmugmugPrivate *priv = self->priv;
+
+  SW_DEBUG (SMUGMUG, "%sauthorized", authorised ? "" : "un");
+
+  g_object_set (G_OBJECT (priv->proxy), "url-format", REST_URL, NULL);
+}
+
+static void
+online_notify (gboolean online, gpointer user_data)
+{
+  SwServiceSmugmug *self = (SwServiceSmugmug *) user_data;
+  SwServiceSmugmugPrivate *priv = self->priv;
+
+  if (online) {
+    g_object_set (G_OBJECT (priv->proxy), "url-format", OAUTH_URL, NULL);
+    sw_keyfob_oauth ((OAuthProxy *)priv->proxy, got_tokens_cb, self);
+  }
+}
+
+/*
+ * The credentials have been updated (or we're starting up), so fetch them from
+ * the keyring.
+ */
+static void
+refresh_credentials (SwServiceSmugmug *smugmug)
+{
+  SW_DEBUG (SMUGMUG, "Credentials updated");
+
+  online_notify (FALSE, (SwService *) smugmug);
+  online_notify (TRUE, (SwService *) smugmug);
+}
+
+/*
+ * SwService:credentials_updated vfunc implementation
+ */
+static void
+credentials_updated (SwService *service)
+{
+  refresh_credentials (SW_SERVICE_SMUGMUG (service));
+}
+
+static void
+sw_service_smugmug_dispose (GObject *object)
+{
+  SwServiceSmugmugPrivate *priv = ((SwServiceSmugmug*)object)->priv;
+
+  if (priv->proxy) {
+    g_object_unref (priv->proxy);
+    priv->proxy = NULL;
+  }
+
+  G_OBJECT_CLASS (sw_service_smugmug_parent_class)->dispose (object);
+}
+
+static void
+collections_iface_init (gpointer g_iface,
+                  gpointer iface_data)
+{
+}
+
+static void
+sw_service_smugmug_class_init (SwServiceSmugmugClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  SwServiceClass *service_class = SW_SERVICE_CLASS (klass);
+
+  g_type_class_add_private (klass, sizeof (SwServiceSmugmugPrivate));
+
+  object_class->dispose = sw_service_smugmug_dispose;
+
+  service_class->get_name = get_name;
+  service_class->get_static_caps = get_static_caps;
+  service_class->credentials_updated = credentials_updated;
+}
+
+static void
+sw_service_smugmug_init (SwServiceSmugmug *self)
+{
+  SwServiceSmugmugPrivate *priv;
+  const gchar *key = NULL;
+  const gchar *secret = NULL;
+
+  priv = self->priv = GET_PRIVATE (self);
+
+  sw_keystore_get_key_secret ("smugmug", &key, &secret);
+
+  priv->proxy = oauth_proxy_new (key, secret, REST_URL, FALSE);
+
+  sw_online_add_notify (online_notify, self);
+
+  refresh_credentials (self);
+}
diff --git a/services/smugmug/smugmug.h b/services/smugmug/smugmug.h
new file mode 100644
index 0000000..e1d390d
--- /dev/null
+++ b/services/smugmug/smugmug.h
@@ -0,0 +1,62 @@
+/*
+ * libsocialweb SmugMug service support
+ *
+ * Copyright (C) 2011 Collabora Ltd.
+ *
+ * Authors: Eitan Isaacson <eitan isaacson collabora co uk>
+ *
+ * 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 _SW_SERVICE_SMUGMUG
+#define _SW_SERVICE_SMUGMUG
+
+#include <glib-object.h>
+#include <libsocialweb/sw-service.h>
+
+G_BEGIN_DECLS
+
+#define SW_TYPE_SERVICE_SMUGMUG sw_service_smugmug_get_type()
+
+#define SW_SERVICE_SMUGMUG(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), SW_TYPE_SERVICE_SMUGMUG, SwServiceSmugmug))
+
+#define SW_SERVICE_SMUGMUG_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST ((klass), SW_TYPE_SERVICE_SMUGMUG, SwServiceSmugmugClass))
+
+#define SW_IS_SERVICE_SMUGMUG(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SW_TYPE_SERVICE_SMUGMUG))
+
+#define SW_IS_SERVICE_SMUGMUG_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE ((klass), SW_TYPE_SERVICE_SMUGMUG))
+
+#define SW_SERVICE_SMUGMUG_GET_CLASS(obj) \
+  (G_TYPE_INSTANCE_GET_CLASS ((obj), SW_TYPE_SERVICE_SMUGMUG, SwServiceSmugmugClass))
+
+typedef struct _SwServiceSmugmugPrivate SwServiceSmugmugPrivate;
+
+typedef struct {
+  SwService parent;
+  SwServiceSmugmugPrivate *priv;
+} SwServiceSmugmug;
+
+typedef struct {
+  SwServiceClass parent_class;
+} SwServiceSmugmugClass;
+
+GType sw_service_smugmug_get_type (void);
+
+G_END_DECLS
+
+#endif /* _SW_SERVICE_SMUGMUG */
diff --git a/services/smugmug/smugmug.keys.in b/services/smugmug/smugmug.keys.in
new file mode 100644
index 0000000..a932e43
--- /dev/null
+++ b/services/smugmug/smugmug.keys.in
@@ -0,0 +1,11 @@
+[LibSocialWebService]
+_Name=SmugMug
+_Description=Your Photos Look Better Here. Billions of happy photos. Millions of passionate customers.
+Link=http://www.smugmug.com/
+AuthType=oauth
+
+[OAuth]
+BaseURL=http://api.smugmug.com/services/oauth/
+RequestTokenFunction=getRequestToken.mg
+AuthoriseFunction=authorize.mg
+AccessTokenFunction=getAccessToken.mg



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]