[couchdb-glib] Add couchdb_database_get_design_document API
- From: Rodrigo Moya <rodrigo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [couchdb-glib] Add couchdb_database_get_design_document API
- Date: Mon, 24 May 2010 16:06:49 +0000 (UTC)
commit 30620e73a1f73f8ce268a05714dbed21b9474cb5
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Mon May 24 17:27:23 2010 +0200
Add couchdb_database_get_design_document API
couchdb-glib/couchdb-database.c | 43 +++++++++++++++++++++++++++++++-
couchdb-glib/couchdb-database.h | 4 +++
couchdb-glib/couchdb-design-document.c | 1 +
couchdb-glib/couchdb-design-document.h | 8 +++---
4 files changed, 51 insertions(+), 5 deletions(-)
---
diff --git a/couchdb-glib/couchdb-database.c b/couchdb-glib/couchdb-database.c
index d7d6f75..ab3100c 100644
--- a/couchdb-glib/couchdb-database.c
+++ b/couchdb-glib/couchdb-database.c
@@ -458,7 +458,6 @@ couchdb_database_get_document (CouchdbDatabase *database,
} else {
document = couchdb_document_new_from_json_object (json_node_get_object (json_parser_get_root (parser)));
}
-
}
g_object_unref (G_OBJECT (parser));
@@ -469,6 +468,48 @@ couchdb_database_get_document (CouchdbDatabase *database,
}
/**
+ * couchdb_database_get_design_document:
+ * @database: A #CouchdbDatabase object
+ * @docid: ID of the design document
+ * @error: Placeholder for error information
+ *
+ * Retrieve a design document from the given database.
+ *
+ * Return value: A #CouchdbDesignDocument object if successful, NULL otherwise, in
+ * which case, the error argument will contain information about the error.
+ */
+CouchdbDesignDocument *
+couchdb_database_get_design_document (CouchdbDatabase *database, const char *docid, GError **error)
+{
+ char *url;
+ JsonParser *parser;
+ CouchdbDesignDocument *document = NULL;
+
+ g_return_val_if_fail (COUCHDB_IS_DATABASE (database), NULL);
+ g_return_val_if_fail (docid != NULL, NULL);
+
+ if (g_str_has_prefix (docid, "_design/")) {
+ url = g_strdup_printf ("%s/%s/%s", couchdb_session_get_uri (database->priv->session),
+ database->priv->dbname, docid);
+ } else {
+ url = g_strdup_printf ("%s/%s/_design/%s", couchdb_session_get_uri (database->priv->session),
+ database->priv->dbname, docid);
+ }
+
+ parser = json_parser_new ();
+ if (couchdb_session_send_message (database->priv->session, SOUP_METHOD_GET, url, NULL, parser, error)) {
+ document = couchdb_design_document_new ();
+ couchdb_document_set_from_json_object (COUCHDB_DOCUMENT (document),
+ json_node_get_object (json_parser_get_root (parser)));
+ }
+
+ g_object_unref (G_OBJECT (parser));
+ g_free (url);
+
+ return document;
+}
+
+/**
* couchdb_database_put_document:
* @database: A #CouchdbDatabase object
* @document: A #CouchdbDocument object
diff --git a/couchdb-glib/couchdb-database.h b/couchdb-glib/couchdb-database.h
index 84c7dd8..042cc2f 100644
--- a/couchdb-glib/couchdb-database.h
+++ b/couchdb-glib/couchdb-database.h
@@ -23,6 +23,7 @@
#define __COUCHDB_DATABASE_H__
#include <glib-object.h>
+#include "couchdb-design-document.h"
#include "couchdb-document.h"
#include "couchdb-session.h"
@@ -65,6 +66,9 @@ void couchdb_database_free_document_list (GSList *doclist);
CouchdbDocument *couchdb_database_get_document (CouchdbDatabase *database,
const char *docid,
GError **error);
+CouchdbDesignDocument *couchdb_database_get_design_document (CouchdbDatabase *database,
+ const char *docid,
+ GError **error);
gboolean couchdb_database_put_document (CouchdbDatabase *database,
CouchdbDocument *document,
GError **error);
diff --git a/couchdb-glib/couchdb-design-document.c b/couchdb-glib/couchdb-design-document.c
index a08fac4..4c46a40 100644
--- a/couchdb-glib/couchdb-design-document.c
+++ b/couchdb-glib/couchdb-design-document.c
@@ -20,6 +20,7 @@
*/
#include "couchdb-design-document.h"
+#include "utils.h"
G_DEFINE_TYPE(CouchdbDesignDocument, couchdb_design_document, COUCHDB_TYPE_DOCUMENT)
diff --git a/couchdb-glib/couchdb-design-document.h b/couchdb-glib/couchdb-design-document.h
index 29eca41..cb9c6a9 100644
--- a/couchdb-glib/couchdb-design-document.h
+++ b/couchdb-glib/couchdb-design-document.h
@@ -33,13 +33,13 @@ G_BEGIN_DECLS
#define COUCHDB_IS_DESIGN_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COUCHDB_TYPE_DESIGN_DOCUMENT))
#define COUCHDB_DESIGN_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COUCHDB_TYPE_DESIGN_DOCUMENT, CouchdbDesignDocumentClass))
-struct CouchdbDesignDocument {
+typedef struct {
CouchdbDocument parent;
-};
+} CouchdbDesignDocument;
-struct CouchdbDesignDocumentClass {
+typedef struct {
CouchdbDocumentClass parent_class;
-};
+} CouchdbDesignDocumentClass;
GType couchdb_design_document_get_type (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]