[couchdb-glib] Use much easier format, without all the 'v's fields



commit 5e2273204cb84503721f7c30fb0f2672f75e4ad1
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Thu Jun 18 18:19:43 2009 +0200

    Use much easier format, without all the 'v's fields

 couchdb-glib/couchdb-document-contact.c |   96 ++++--------------------------
 couchdb-glib/couchdb-document.c         |    4 +-
 2 files changed, 15 insertions(+), 85 deletions(-)
---
diff --git a/couchdb-glib/couchdb-document-contact.c b/couchdb-glib/couchdb-document-contact.c
index 48539d6..f58591e 100644
--- a/couchdb-glib/couchdb-document-contact.c
+++ b/couchdb-glib/couchdb-document-contact.c
@@ -22,36 +22,13 @@
 #include "couchdb-document-contact.h"
 #include "utils.h"
 
-static void
-set_simple_string_value_field (CouchDBDocument *document, const char *field, const char *value)
-{
-	JsonObject *object;
-
-	object = json_object_get_object_member (json_node_get_object (document->root_node), field);
-	if (object)
-		json_object_set_string_member (object, "v", value);
-	else {
-		object = json_object_new ();
-		json_object_set_string_member (object, "v", value);
-		json_object_set_object_member (json_node_get_object (document->root_node), field, object);
-
-		json_object_unref (object);
-	}
-}
-
 const char *
 couchdb_document_contact_get_first_name (CouchDBDocument *document)
 {
-	JsonObject *object;
-
 	g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
 	g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
 
-	object = json_object_get_object_member (json_node_get_object (document->root_node), "first_name");
-	if (object)
-		return json_object_get_string_member (object, "v");
-
-	return NULL;
+	return json_object_get_string_member (json_node_get_object (document->root_node), "first_name");
 }
 
 void
@@ -61,22 +38,16 @@ couchdb_document_contact_set_first_name (CouchDBDocument *document, const char *
 	g_return_if_fail (couchdb_document_is_contact (document));
 	g_return_if_fail (first_name != NULL);
 
-	set_simple_string_value_field (document, "first_name", first_name);
+	json_object_set_string_member (json_node_get_object (document->root_node), "first_name", first_name);
 }
 
 const char *
 couchdb_document_contact_get_last_name (CouchDBDocument *document)
 {
-	JsonObject *object;
-
 	g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
 	g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
 
-	object = json_object_get_object_member (json_node_get_object (document->root_node), "last_name");
-	if (object)
-		return json_object_get_string_member (object, "v");
-
-	return NULL;
+	return json_object_get_string_member (json_node_get_object (document->root_node), "last_name");
 }
 
 void
@@ -86,7 +57,7 @@ couchdb_document_contact_set_last_name (CouchDBDocument *document, const char *l
 	g_return_if_fail (couchdb_document_is_contact (document));
 	g_return_if_fail (last_name != NULL);
 
-	set_simple_string_value_field (document, "last_name", last_name);
+	json_object_set_string_member (json_node_get_object (document->root_node), "last_name", last_name);
 }
 
 const char *
@@ -97,11 +68,7 @@ couchdb_document_contact_get_birth_date (CouchDBDocument *document)
 	g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), NULL);
 	g_return_val_if_fail (couchdb_document_is_contact (document), NULL);
 
-	object = json_object_get_object_member (json_node_get_object (document->root_node), "birth_date");
-	if (object)
-		return json_object_get_string_member (object, "v");
-
-	return NULL;
+	return json_object_get_string_member (json_node_get_object (document->root_node), "birth_date");
 }
 
 void
@@ -111,7 +78,7 @@ couchdb_document_contact_set_birth_date (CouchDBDocument *document, const char *
 	g_return_if_fail (couchdb_document_is_contact (document));
 	g_return_if_fail (birth_date != NULL);
 
-	set_simple_string_value_field (document, "birth_date", birth_date);
+	json_object_set_string_member (json_node_get_object (document->root_node), "birth_date", birth_date);
 }
 
 static void
@@ -156,14 +123,9 @@ couchdb_document_contact_get_email_addresses (CouchDBDocument *document)
 	addresses_json = json_object_get_object_member (json_node_get_object (document->root_node),
 							"email_addresses");
 	if (addresses_json) {
-		JsonObject *json_value;
-
-		json_value = json_object_get_object_member (addresses_json, "v");
-		if (json_value) {
-			json_object_foreach_member (json_value,
-						    (JsonObjectForeach) foreach_email_cb,
-						    &list);
-		}
+		json_object_foreach_member (addresses_json,
+					    (JsonObjectForeach) foreach_email_cb,
+					    &list);
 	}
 
 	return list;
@@ -177,65 +139,33 @@ couchdb_document_contact_set_email_addresses (CouchDBDocument *document, GSList
 const char *
 couchdb_document_contact_email_get_address (CouchDBStructField *sf)
 {
-	JsonObject *top_level, *parent;
-
 	g_return_val_if_fail (sf != NULL, NULL);
 
-	top_level = json_object_get_object_member (sf->json_object, "v");
-	if (top_level) {
-		parent = json_object_get_object_member (top_level, "address");
-		if (parent)
-			return json_object_get_string_member (parent, "v");
-	}
-
-	return NULL;
+	return json_object_get_string_member (sf->json_object, "address");
 }
 
 void
 couchdb_document_contact_email_set_address (CouchDBStructField *sf, const char *email)
 {
-	JsonObject *top_level, *parent;
-
 	g_return_if_fail (sf != NULL);
 	g_return_if_fail (email != NULL);
 
-	top_level = json_object_get_object_member (sf->json_object, "v");
-	if (top_level) {
-		parent = json_object_get_object_member (top_level, "address");
-		if (parent)
-			json_object_set_string_member (parent, "v", email);
-	}
+	json_object_set_string_member (sf->json_object, "address", email);
 }
 
 const char *
 couchdb_document_contact_email_get_description (CouchDBStructField *sf)
 {
-	JsonObject *top_level, *parent;
-
 	g_return_val_if_fail (sf != NULL, NULL);
 
-	top_level = json_object_get_object_member (sf->json_object, "v");
-	if (top_level) {
-		parent = json_object_get_object_member (top_level, "description");
-		if (parent)
-			return json_object_get_string_member (parent, "v");
-	}
-
-	return NULL;
+	return json_object_get_string_member (sf->json_object, "description");
 }
 
 void
 couchdb_document_contact_email_set_description (CouchDBStructField *sf, const char *description)
 {
-	JsonObject *top_level, *parent;
-
 	g_return_if_fail (sf != NULL);
 	g_return_if_fail (description != NULL);
 
-	top_level = json_object_get_object_member (sf->json_object, "v");
-	if (top_level) {
-		parent = json_object_get_object_member (top_level, "description");
-		if (parent)
-			json_object_set_string_member (parent, "v", description);
-	}
+	json_object_set_string_member (sf->json_object, "description", description);
 }
diff --git a/couchdb-glib/couchdb-document.c b/couchdb-glib/couchdb-document.c
index 58113ae..1389f71 100644
--- a/couchdb-glib/couchdb-document.c
+++ b/couchdb-glib/couchdb-document.c
@@ -151,8 +151,8 @@ couchdb_document_is_contact (CouchDBDocument *document)
 	g_return_val_if_fail (COUCHDB_IS_DOCUMENT (document), FALSE);
 
 	return !g_ascii_strcasecmp (json_object_get_string_member (json_node_get_object (document->root_node),
-								   "u1_record_type"),
-				    "http://api.ubuntuone.com/schema/contact/0.1";);
+								   "record_type"),
+				    "http://example.com/contact-record";);
 }
 
 gboolean



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