[libgdata/wip/rishi/drive: 9/9] documents: Parse downloadUrl from JSON



commit 516f58364af17820f3c499fc17670d8b43e09396
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Apr 16 20:10:05 2015 +0200

    documents: Parse downloadUrl from JSON
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684920

 .../services/documents/gdata-documents-document.c  |   22 ++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)
---
diff --git a/gdata/services/documents/gdata-documents-document.c 
b/gdata/services/documents/gdata-documents-document.c
index 8178974..10d199c 100644
--- a/gdata/services/documents/gdata-documents-document.c
+++ b/gdata/services/documents/gdata-documents-document.c
@@ -2,6 +2,7 @@
 /*
  * GData Client
  * Copyright (C) Philip Withnall 2010 <philip tecnocode co uk>
+ * Copyright (C) Red Hat, Inc. 2015
  *
  * GData Client is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -206,13 +207,18 @@
 #include "gdata-private.h"
 #include "gdata-service.h"
 
+static gboolean parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error);
+
 G_DEFINE_TYPE (GDataDocumentsDocument, gdata_documents_document, GDATA_TYPE_DOCUMENTS_ENTRY)
 
 static void
 gdata_documents_document_class_init (GDataDocumentsDocumentClass *klass)
 {
+       GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass);
        GDataEntryClass *entry_class = GDATA_ENTRY_CLASS (klass);
 
+       parsable_class->parse_json = parse_json;
+
        entry_class->kind_term = "http://schemas.google.com/docs/2007#file";;
 }
 
@@ -222,6 +228,22 @@ gdata_documents_document_init (GDataDocumentsDocument *self)
        /* Nothing to see here. */
 }
 
+static gboolean
+parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, GError **error)
+{
+       gboolean success;
+       gchar *content_uri = NULL;
+
+       if (gdata_parser_string_from_json_member (reader, "downloadUrl", P_DEFAULT, &content_uri, &success, 
error) == TRUE) {
+               if (success && content_uri != NULL && content_uri[0] != '\0')
+                       gdata_entry_set_content_uri (GDATA_ENTRY (parsable), content_uri);
+               g_free (content_uri);
+               return success;
+       }
+
+       return GDATA_PARSABLE_CLASS (gdata_documents_document_parent_class)->parse_json (parsable, reader, 
user_data, error);
+}
+
 /**
  * gdata_documents_document_new:
  * @id: (allow-none): the entry's ID (not the document ID), or %NULL


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