[libgdata] [contacts] Build query URIs for GDataContactsQuery
- From: Philip Withnall <pwithnall src gnome org>
- To: svn-commits-list gnome org
- Subject: [libgdata] [contacts] Build query URIs for GDataContactsQuery
- Date: Fri, 24 Apr 2009 12:37:22 -0400 (EDT)
commit 45b97b8400af31a21eb5730cadc54d93b925b5f5
Author: Philip Withnall <philip tecnocode co uk>
Date: Fri Apr 24 17:36:12 2009 +0100
[contacts] Build query URIs for GDataContactsQuery
GDataContactsQuery can now put its properties into a query URI. A test case
for contact query URIs has been added.
---
gdata/services/contacts/gdata-contacts-query.c | 42 ++++++++++++++++++++++--
gdata/tests/calendar.c | 2 +
gdata/tests/contacts.c | 40 ++++++++++++++++++++++
3 files changed, 81 insertions(+), 3 deletions(-)
diff --git a/gdata/services/contacts/gdata-contacts-query.c b/gdata/services/contacts/gdata-contacts-query.c
index e6baaf9..b7d800d 100644
--- a/gdata/services/contacts/gdata-contacts-query.c
+++ b/gdata/services/contacts/gdata-contacts-query.c
@@ -38,13 +38,11 @@
#include "gdata-contacts-query.h"
#include "gdata-query.h"
-/* Reference: http://code.google.com/apis/contacts/docs/2.0/reference.html#Parameters */
-
static void gdata_contacts_query_finalize (GObject *object);
static void gdata_contacts_query_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void gdata_contacts_query_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+static void get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboolean *params_started);
-/* TODO: Actually override GDataQuery's get_query_uri function to return a URI including all our custom parameters */
struct _GDataContactsQueryPrivate {
gchar *order_by; /* TODO: enum? #defined values? */
gboolean show_deleted;
@@ -66,6 +64,7 @@ static void
gdata_contacts_query_class_init (GDataContactsQueryClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GDataQueryClass *query_class = GDATA_QUERY_CLASS (klass);
g_type_class_add_private (klass, sizeof (GDataContactsQueryPrivate));
@@ -73,6 +72,8 @@ gdata_contacts_query_class_init (GDataContactsQueryClass *klass)
gobject_class->get_property = gdata_contacts_query_get_property;
gobject_class->finalize = gdata_contacts_query_finalize;
+ query_class->get_query_uri = get_query_uri;
+
/**
* GDataContactsQuery:order-by:
*
@@ -190,6 +191,41 @@ gdata_contacts_query_set_property (GObject *object, guint property_id, const GVa
}
}
+static void
+get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboolean *params_started)
+{
+ GDataContactsQueryPrivate *priv = GDATA_CONTACTS_QUERY (self)->priv;
+
+ #define APPEND_SEP g_string_append_c (query_uri, (*params_started == FALSE) ? '?' : '&'); *params_started = TRUE;
+
+ /* Chain up to the parent class */
+ GDATA_QUERY_CLASS (gdata_contacts_query_parent_class)->get_query_uri (self, feed_uri, query_uri, params_started);
+
+ if (priv->order_by != NULL) {
+ APPEND_SEP
+ g_string_append (query_uri, "orderby=");
+ g_string_append_uri_escaped (query_uri, priv->order_by, NULL, TRUE);
+ }
+
+ APPEND_SEP
+ if (priv->show_deleted == TRUE)
+ g_string_append (query_uri, "showdeleted=true");
+ else
+ g_string_append (query_uri, "showdeleted=false");
+
+ if (priv->sort_order != NULL) {
+ APPEND_SEP
+ g_string_append (query_uri, "sortorder=");
+ g_string_append_uri_escaped (query_uri, priv->sort_order, NULL, TRUE);
+ }
+
+ if (priv->group != NULL) {
+ APPEND_SEP
+ g_string_append (query_uri, "group=");
+ g_string_append_uri_escaped (query_uri, priv->group, NULL, TRUE);
+ }
+}
+
/**
* gdata_contacts_query_new:
* @q: a query string
diff --git a/gdata/tests/calendar.c b/gdata/tests/calendar.c
index 9ebd977..b04c5ea 100644
--- a/gdata/tests/calendar.c
+++ b/gdata/tests/calendar.c
@@ -439,6 +439,8 @@ test_query_uri (void)
"&singleevents=true&sortorder=descending&start-min=2009-04-17T15:00:00Z&start-max=2010-04-17T15:00:00Z"
"&ctz=America%2FLos_Angeles");
g_free (query_uri);
+
+ g_object_unref (query);
}
int
diff --git a/gdata/tests/contacts.c b/gdata/tests/contacts.c
index 8877d4c..4e4df19 100644
--- a/gdata/tests/contacts.c
+++ b/gdata/tests/contacts.c
@@ -169,6 +169,45 @@ test_insert_simple (void)
g_object_unref (new_contact);
}
+static void
+test_query_uri (void)
+{
+ gchar *query_uri;
+ GDataContactsQuery *query = gdata_contacts_query_new ("q");
+
+ gdata_contacts_query_set_order_by (query, "lastmodified");
+ g_assert_cmpstr (gdata_contacts_query_get_order_by (query), ==, "lastmodified");
+
+ gdata_contacts_query_set_show_deleted (query, TRUE);
+ g_assert (gdata_contacts_query_show_deleted (query) == TRUE);
+
+ gdata_contacts_query_set_sort_order (query, "descending");
+ g_assert_cmpstr (gdata_contacts_query_get_sort_order (query), ==, "descending");
+
+ gdata_contacts_query_set_group (query, "http://www.google.com/feeds/contacts/groups/jo gmail com/base/1234a");
+ g_assert_cmpstr (gdata_contacts_query_get_group (query), ==, "http://www.google.com/feeds/contacts/groups/jo gmail com/base/1234a");
+
+ /* Check the built query URI with a normal feed URI */
+ query_uri = gdata_query_get_query_uri (GDATA_QUERY (query), "http://example.com");
+ g_assert_cmpstr (query_uri, ==, "http://example.com?q=q&orderby=lastmodified&showdeleted=true&sortorder=descending"
+ "&group=http%3A%2F%2Fwww.google.com%2Ffeeds%2Fcontacts%2Fgroups%2Fjo%40gmail.com%2Fbase%2F1234a");
+ g_free (query_uri);
+
+ /* â?¦with a feed URI with a trailing slash */
+ query_uri = gdata_query_get_query_uri (GDATA_QUERY (query), "http://example.com/");
+ g_assert_cmpstr (query_uri, ==, "http://example.com/?q=q&orderby=lastmodified&showdeleted=true&sortorder=descending"
+ "&group=http%3A%2F%2Fwww.google.com%2Ffeeds%2Fcontacts%2Fgroups%2Fjo%40gmail.com%2Fbase%2F1234a");
+ g_free (query_uri);
+
+ /* â?¦with a feed URI with pre-existing arguments */
+ query_uri = gdata_query_get_query_uri (GDATA_QUERY (query), "http://example.com/bar/?test=test&this=that");
+ g_assert_cmpstr (query_uri, ==, "http://example.com/bar/?test=test&this=that&q=q&orderby=lastmodified&showdeleted=true&sortorder=descending"
+ "&group=http%3A%2F%2Fwww.google.com%2Ffeeds%2Fcontacts%2Fgroups%2Fjo%40gmail.com%2Fbase%2F1234a");
+ g_free (query_uri);
+
+ g_object_unref (query);
+}
+
int
main (int argc, char *argv[])
{
@@ -185,6 +224,7 @@ main (int argc, char *argv[])
g_test_add_func ("/contacts/query/all_contacts_async", test_query_all_contacts_async);
if (g_test_slow () == TRUE)
g_test_add_func ("/contacts/insert/simple", test_insert_simple);
+ g_test_add_func ("/contacts/query/uri", test_query_uri);
retval = g_test_run ();
if (service != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]