[libgdata] [contacts] Added gdata_contacts_service_update_contact



commit 65531a6bae54340722c2cdaa5e156a9ca9a49637
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Jul 2 16:09:37 2009 +0100

    [contacts] Added gdata_contacts_service_update_contact
    
    Added gdata_contacts_service_update_contact to work around some weirdness
    with the edit URIs the contacts service gives us, and also fixed some bugs
    with handling empty extended properties.

 gdata/gdata.symbols                              |    1 +
 gdata/services/contacts/gdata-contacts-contact.c |    2 +-
 gdata/services/contacts/gdata-contacts-service.c |   39 +++++++++++++++++++++-
 gdata/services/contacts/gdata-contacts-service.h |    2 +
 gdata/tests/contacts.c                           |    6 +++
 5 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index be406c1..c0a0167 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -247,6 +247,7 @@ gdata_contacts_service_new
 gdata_contacts_service_query_contacts
 gdata_contacts_service_query_contacts_async
 gdata_contacts_service_insert_contact
+gdata_contacts_service_update_contact
 gdata_contacts_query_get_type
 gdata_contacts_query_new
 gdata_contacts_query_new_with_limits
diff --git a/gdata/services/contacts/gdata-contacts-contact.c b/gdata/services/contacts/gdata-contacts-contact.c
index 28a41de..3e5671c 100644
--- a/gdata/services/contacts/gdata-contacts-contact.c
+++ b/gdata/services/contacts/gdata-contacts-contact.c
@@ -851,7 +851,7 @@ gdata_contacts_contact_set_extended_property (GDataContactsContact *self, const
 	g_return_val_if_fail (GDATA_IS_CONTACTS_CONTACT (self), FALSE);
 	g_return_val_if_fail (name != NULL, FALSE);
 
-	if (value == NULL) {
+	if (value == NULL || *value == '\0') {
 		/* Removing a property */
 		g_hash_table_remove (extended_properties, name);
 		return TRUE;
diff --git a/gdata/services/contacts/gdata-contacts-service.c b/gdata/services/contacts/gdata-contacts-service.c
index 03ced35..3ab26d0 100644
--- a/gdata/services/contacts/gdata-contacts-service.c
+++ b/gdata/services/contacts/gdata-contacts-service.c
@@ -170,9 +170,46 @@ gdata_contacts_service_insert_contact (GDataContactsService *self, GDataContacts
 	g_return_val_if_fail (GDATA_IS_CONTACTS_CONTACT (contact), NULL);
 
 	uri = g_strdup_printf ("http://www.google.com/m8/feeds/contacts/%s/full";, gdata_service_get_username (GDATA_SERVICE (self)));
-
 	entry = gdata_service_insert_entry (GDATA_SERVICE (self), uri, GDATA_ENTRY (contact), cancellable, error);
 	g_free (uri);
 
 	return GDATA_CONTACTS_CONTACT (entry);
 }
+
+/**
+ * gdata_contacts_service_update_contact:
+ * @self: a #GDataContactsService
+ * @contact: the #GDataContactsContact to update
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @error: a #GError, or %NULL
+ *
+ * Updates @contact on the online contacts service.
+ *
+ * For more details, see gdata_service_update_entry().
+ *
+ * Return value: an updated #GDataContactsContact, or %NULL
+ *
+ * Since: 0.4.0
+ **/
+GDataContactsContact *
+gdata_contacts_service_update_contact (GDataContactsService *self, GDataContactsContact *contact, GCancellable *cancellable, GError **error)
+{
+	/* TODO: Async variant */
+	const gchar *uri;
+	GDataLink *link;
+
+	g_return_val_if_fail (GDATA_IS_CONTACTS_SERVICE (self), NULL);
+	g_return_val_if_fail (GDATA_IS_CONTACTS_CONTACT (contact), NULL);
+
+	/* Can't trust the edit URI the contact gives us, as it has the wrong projection; it uses the base projection, which
+	 * doesn't allow for extended attributes to be set (for some weird reason). */
+	link = gdata_entry_look_up_link (GDATA_ENTRY (contact), GDATA_LINK_EDIT);
+	g_assert (link != NULL);
+	uri = gdata_link_get_uri (link);
+	g_assert (uri != NULL);
+	uri = strstr (uri, "/base/");
+	if (uri != NULL)
+		memcpy ((char*) uri, "/full/", 6);
+
+	return GDATA_CONTACTS_CONTACT (gdata_service_update_entry (GDATA_SERVICE (self), GDATA_ENTRY (contact), cancellable, error));
+}
diff --git a/gdata/services/contacts/gdata-contacts-service.h b/gdata/services/contacts/gdata-contacts-service.h
index eea077e..e5b06ce 100644
--- a/gdata/services/contacts/gdata-contacts-service.h
+++ b/gdata/services/contacts/gdata-contacts-service.h
@@ -71,6 +71,8 @@ void gdata_contacts_service_query_contacts_async (GDataContactsService *self, GD
 
 GDataContactsContact *gdata_contacts_service_insert_contact (GDataContactsService *self, GDataContactsContact *contact,
 							     GCancellable *cancellable, GError **error) G_GNUC_WARN_UNUSED_RESULT;
+GDataContactsContact *gdata_contacts_service_update_contact (GDataContactsService *self, GDataContactsContact *contact,
+							     GCancellable *cancellable, GError **error) G_GNUC_WARN_UNUSED_RESULT;
 
 G_END_DECLS
 
diff --git a/gdata/tests/contacts.c b/gdata/tests/contacts.c
index b845a42..34e8115 100644
--- a/gdata/tests/contacts.c
+++ b/gdata/tests/contacts.c
@@ -168,6 +168,11 @@ test_insert_simple (void)
 	gdata_contacts_contact_add_postal_address (contact, postal_address);
 	g_object_unref (postal_address);
 
+	/* Add some extended properties */
+	g_assert (gdata_contacts_contact_set_extended_property (contact, "TITLE", NULL) == TRUE);
+	g_assert (gdata_contacts_contact_set_extended_property (contact, "ROLE", "") == TRUE);
+	g_assert (gdata_contacts_contact_set_extended_property (contact, "CALURI", "http://example.com/";) == TRUE);
+
 	/* Check the XML */
 	xml = gdata_parsable_get_xml (GDATA_PARSABLE (contact));
 	g_assert_cmpstr (xml, ==,
@@ -187,6 +192,7 @@ test_insert_simple (void)
 				"<gd:postalAddress rel='http://schemas.google.com/g/2005#work' primary='true'>"
 					"1600 Amphitheatre Pkwy Mountain View"
 				"</gd:postalAddress>"
+				"<gd:extendedProperty name='CALURI'>http://example.com/</gd:extendedProperty>"
 			 "</entry>");
 	g_free (xml);
 



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