--- /dev/null
+/*
+ * This program 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 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Authors: Travis Reitter <treitter@gmail.com>
+ */
+
+#include <config.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <hildon/hildon.h>
+
+#include <rtm-glib/rtm-glib.h>
+
+#include "milk-auth.h"
+
+G_DEFINE_TYPE (MilkAuth, milk_auth, G_TYPE_OBJECT);
+
+/* less expensive than G_TYPE_INSTANCE_GET_PRIVATE */
+#define MILK_AUTH_PRIVATE(o) ((MILK_AUTH ((o)))->priv)
+
+#define RTM_API_KEY "81f5c6c904aeafbbc914d9845d250ea8"
+#define RTM_SHARED_SECRET "b08b15419378f913"
+
+struct _MilkAuthPrivate
+{
+ RtmGlib *rtm_glib;
+ char *api_key;
+ char *shared_secret;
+};
+
+enum {
+ PROP_API_KEY = 1,
+ PROP_SHARED_SECRET,
+};
+
+static MilkAuth *default_auth = NULL;
+
+
+static void
+milk_auth_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ MilkAuthPrivate *priv = MILK_AUTH_PRIVATE (object);
+
+ switch (property_id)
+ {
+ case PROP_API_KEY:
+ g_value_set_string (value, priv->api_key);
+ break;
+
+ case PROP_SHARED_SECRET:
+ g_value_set_string (value, priv->shared_secret);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
+ pspec);
+ }
+}
+
+static void
+milk_auth_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ MilkAuthPrivate *priv;
+ MilkAuth *auth;
+
+ auth = MILK_AUTH (object);
+ priv = MILK_AUTH_PRIVATE (auth);
+
+ switch (property_id)
+ {
+ case PROP_API_KEY:
+ priv->api_key = g_value_dup_string (value);
+ break;
+
+ case PROP_SHARED_SECRET:
+ priv->shared_secret = g_value_dup_string (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
+ pspec);
+ }
+}
+
+static void
+milk_auth_constructed (GObject *object)
+{
+ MilkAuthPrivate *priv = MILK_AUTH_PRIVATE (object);
+
+ priv->rtm_glib = rtm_glib_new (priv->api_key, priv->shared_secret);
+}
+
+static void
+milk_auth_finalize (GObject *object)
+{
+ MilkAuthPrivate *priv = MILK_AUTH_PRIVATE (object);
+
+ g_object_unref (priv->rtm_glib);
+
+ g_free (priv->api_key);
+ g_free (priv->shared_secret);
+}
+
+static void
+milk_auth_class_init (MilkAuthClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (MilkAuthPrivate));
+
+ object_class->get_property = milk_auth_get_property;
+ object_class->set_property = milk_auth_set_property;
+ object_class->constructed = milk_auth_constructed;
+ object_class->finalize = milk_auth_finalize;
+
+ /* FIXME: make these read-only */
+ g_object_class_install_property
+ (object_class,
+ PROP_API_KEY,
+ g_param_spec_string
+ ("api-key",
+ "API authentication key",
+ "Milk's API authentication key.",
+ RTM_API_KEY,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property
+ (object_class,
+ PROP_SHARED_SECRET,
+ g_param_spec_string
+ ("shared-secret",
+ "Shared secret",
+ "Milk's shared secret with the server.",
+ RTM_SHARED_SECRET,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+}
+
+static void
+milk_auth_init (MilkAuth *self)
+{
+ MilkAuthPrivate *priv;
+
+ self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (
+ self, MILK_TYPE_AUTH, MilkAuthPrivate);
+}
+
+MilkAuth*
+milk_auth_get_default ()
+{
+ if (!default_auth)
+ default_auth = g_object_new (MILK_TYPE_AUTH, NULL);
+
+ return default_auth;
+}
--- /dev/null
+/*
+ * This program 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 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * Authors: Travis Reitter <treitter@gmail.com>
+ */
+
+#ifndef _MILK_AUTH_H
+#define _MILK_AUTH_H
+
+G_BEGIN_DECLS
+
+#define MILK_TYPE_AUTH milk_auth_get_type()
+
+#define MILK_AUTH(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ MILK_TYPE_AUTH, MilkAuth))
+
+#define MILK_AUTH_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ MILK_TYPE_AUTH, MilkAuthClass))
+
+#define MILK_IS_AUTH(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ MILK_TYPE_AUTH))
+
+#define MILK_IS_AUTH_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ MILK_TYPE_AUTH))
+
+#define MILK_AUTH_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ MILK_TYPE_AUTH, MilkAuthClass))
+
+typedef struct _MilkAuth MilkAuth;
+typedef struct _MilkAuthClass MilkAuthClass;
+typedef struct _MilkAuthPrivate MilkAuthPrivate;
+
+struct _MilkAuth
+{
+ GObject parent;
+ MilkAuthPrivate *priv;
+};
+
+struct _MilkAuthClass
+{
+ GObjectClass parent_class;
+};
+
+GType milk_auth_get_type (void);
+
+
+MilkAuth* milk_auth_get_default ();
+
+#endif /* _MILK_AUTH_H */