[libgdata] media: Add JSON support to GDataMediaThumbnail



commit de74263ff38a9d3e9672b833e5883393b3a9854c
Author: Philip Withnall <philip tecnocode co uk>
Date:   Sun Apr 19 18:29:29 2015 +0100

    media: Add JSON support to GDataMediaThumbnail
    
    This will be used in the upcoming port to v3 of the YouTube API.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687597

 gdata/media/gdata-media-thumbnail.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/gdata/media/gdata-media-thumbnail.c b/gdata/media/gdata-media-thumbnail.c
index 413e0e9..be55c12 100644
--- a/gdata/media/gdata-media-thumbnail.c
+++ b/gdata/media/gdata-media-thumbnail.c
@@ -43,6 +43,9 @@ static void gdata_media_thumbnail_finalize (GObject *object);
 static void gdata_media_thumbnail_get_property (GObject *object, guint property_id, GValue *value, 
GParamSpec *pspec);
 static gboolean pre_parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, 
GError **error);
 static void get_namespaces (GDataParsable *parsable, GHashTable *namespaces);
+static gboolean
+parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data,
+            GError **error);
 
 struct _GDataMediaThumbnailPrivate {
        gchar *uri;
@@ -73,6 +76,7 @@ gdata_media_thumbnail_class_init (GDataMediaThumbnailClass *klass)
 
        parsable_class->pre_parse_xml = pre_parse_xml;
        parsable_class->get_namespaces = get_namespaces;
+       parsable_class->parse_json = parse_json;
        parsable_class->element_name = "thumbnail";
        parsable_class->element_namespace = "media";
 
@@ -293,6 +297,31 @@ get_namespaces (GDataParsable *parsable, GHashTable *namespaces)
        g_hash_table_insert (namespaces, (gchar*) "media", (gchar*) "http://search.yahoo.com/mrss/";);
 }
 
+/* Reference:
+ * https://developers.google.com/youtube/v3/docs/videos#snippet.thumbnails */
+static gboolean
+parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data,
+            GError **error)
+{
+       gboolean success;
+       GDataMediaThumbnail *self = GDATA_MEDIA_THUMBNAIL (parsable);
+       GDataMediaThumbnailPrivate *priv = self->priv;
+
+       if (gdata_parser_string_from_json_member (reader, "url", P_DEFAULT,
+                                                 &priv->uri, &success,
+                                                 error) ||
+           gdata_parser_int_from_json_member (reader, "width", P_DEFAULT,
+                                              (gint64 *) &priv->width,
+                                              &success, error) ||
+           gdata_parser_int_from_json_member (reader, "height", P_DEFAULT,
+                                              (gint64 *) &priv->height,
+                                              &success, error)) {
+               return success;
+       } else {
+               return GDATA_PARSABLE_CLASS (gdata_media_thumbnail_parent_class)->parse_json (parsable, 
reader, user_data, error);
+       }
+}
+
 /**
  * gdata_media_thumbnail_get_uri:
  * @self: a #GDataMediaThumbnail


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