diff options
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | docs/reference/gdata-docs.xml | 1 | ||||
-rw-r--r-- | docs/reference/gdata-sections.txt | 17 | ||||
-rw-r--r-- | gdata/gdata.h | 1 | ||||
-rw-r--r-- | gdata/gdata.symbols | 1 | ||||
-rw-r--r-- | gdata/services/youtube/gdata-youtube-feed.c | 102 | ||||
-rw-r--r-- | gdata/services/youtube/gdata-youtube-feed.h | 74 | ||||
-rw-r--r-- | gdata/services/youtube/gdata-youtube-service.c | 2 |
8 files changed, 201 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index 964ac4b6..1e1e0096 100644 --- a/Makefile.am +++ b/Makefile.am @@ -321,7 +321,8 @@ gdata_youtube_headers = \ gdata/services/youtube/gdata-youtube-query.h \ gdata/services/youtube/gdata-youtube-state.h \ gdata/services/youtube/gdata-youtube-category.h \ - gdata/services/youtube/gdata-youtube-comment.h + gdata/services/youtube/gdata-youtube-comment.h \ + gdata/services/youtube/gdata-youtube-feed.h private_headers += \ gdata/services/youtube/gdata-youtube-group.h \ gdata/services/youtube/gdata-youtube-control.h @@ -453,6 +454,7 @@ gdata_sources = \ gdata/services/youtube/gdata-youtube-control.c \ gdata/services/youtube/gdata-youtube-category.c \ gdata/services/youtube/gdata-youtube-comment.c \ + gdata/services/youtube/gdata-youtube-feed.c \ \ gdata/services/tasks/gdata-tasks-service.c \ gdata/services/tasks/gdata-tasks-tasklist.c \ diff --git a/docs/reference/gdata-docs.xml b/docs/reference/gdata-docs.xml index 2e4e0771..5233faa1 100644 --- a/docs/reference/gdata-docs.xml +++ b/docs/reference/gdata-docs.xml @@ -128,6 +128,7 @@ <chapter> <title>YouTube API</title> <xi:include href="xml/gdata-youtube-service.xml"/> + <xi:include href="xml/gdata-youtube-feed.xml"/> <xi:include href="xml/gdata-youtube-query.xml"/> <xi:include href="xml/gdata-youtube-video.xml"/> <xi:include href="xml/gdata-youtube-comment.xml"/> diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt index 0c109c21..22f78693 100644 --- a/docs/reference/gdata-sections.txt +++ b/docs/reference/gdata-sections.txt @@ -2795,3 +2795,20 @@ gdata_oauth2_authorizer_get_type <SUBSECTION Private> GDataOAuth2AuthorizerPrivate </SECTION> + +<SECTION> +<FILE>gdata-youtube-feed</FILE> +<TITLE>GDataYouTubeFeed</TITLE> +GDataYouTubeFeed +GDataYouTubeFeedClass +<SUBSECTION Standard> +gdata_youtube_feed_get_type +GDATA_YOUTUBE_FEED +GDATA_YOUTUBE_FEED_CLASS +GDATA_YOUTUBE_FEED_GET_CLASS +GDATA_IS_YOUTUBE_FEED +GDATA_IS_YOUTUBE_FEED_CLASS +GDATA_TYPE_YOUTUBE_FEED +<SUBSECTION Private> +GDataYouTubeFeedPrivate +</SECTION> diff --git a/gdata/gdata.h b/gdata/gdata.h index fe7a4c3a..e74dd06c 100644 --- a/gdata/gdata.h +++ b/gdata/gdata.h @@ -91,6 +91,7 @@ /* YouTube */ #include <gdata/services/youtube/gdata-youtube-service.h> +#include <gdata/services/youtube/gdata-youtube-feed.h> #include <gdata/services/youtube/gdata-youtube-query.h> #include <gdata/services/youtube/gdata-youtube-video.h> #include <gdata/services/youtube/gdata-youtube-content.h> diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols index 7ae3e955..830f0bf3 100644 --- a/gdata/gdata.symbols +++ b/gdata/gdata.symbols @@ -95,6 +95,7 @@ gdata_query_set_max_results gdata_query_get_etag gdata_query_set_etag gdata_youtube_standard_feed_type_get_type +gdata_youtube_feed_get_type gdata_youtube_service_error_get_type gdata_youtube_service_error_quark gdata_youtube_service_get_type diff --git a/gdata/services/youtube/gdata-youtube-feed.c b/gdata/services/youtube/gdata-youtube-feed.c new file mode 100644 index 00000000..469c5ae4 --- /dev/null +++ b/gdata/services/youtube/gdata-youtube-feed.c @@ -0,0 +1,102 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* + * GData Client + * Copyright (C) Philip Withnall 2015 <philip@tecnocode.co.uk> + * + * GData Client is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * GData Client is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GData Client. If not, see <http://www.gnu.org/licenses/>. + */ + +/** + * SECTION:gdata-youtube-feed + * @short_description: GData YouTube feed object + * @stability: Stable + * @include: gdata/services/youtube/gdata-youtube-feed.h + * + * #GDataYouTubeFeed is a list of entries (#GDataYouTubeVideo subclasses) + * returned as the result of a query to a #GDataYouTubeService, or given as the + * input to another operation on the online service. + * + * Each #GDataYouTubeVideo represents a single video on YouTube, and the + * #GDataYouTubeFeed represents a collection of those objects. + * + * Since: UNRELEASED + */ + +#include <config.h> +#include <glib.h> +#include <glib/gi18n-lib.h> +#include <string.h> + +#include "gdata-youtube-feed.h" +#include "gdata-youtube-video.h" +#include "gdata-types.h" +#include "gdata-private.h" +#include "gdata-service.h" + +static gboolean +parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, + GError **error); + +G_DEFINE_TYPE (GDataYouTubeFeed, gdata_youtube_feed, GDATA_TYPE_FEED) + +static void +gdata_youtube_feed_class_init (GDataYouTubeFeedClass *klass) +{ + GDataParsableClass *parsable_class = GDATA_PARSABLE_CLASS (klass); + parsable_class->parse_json = parse_json; +} + +static void +gdata_youtube_feed_init (GDataYouTubeFeed *self) +{ + /* Move along now. */ +} + +static gboolean +parse_json (GDataParsable *parsable, JsonReader *reader, gpointer user_data, + GError **error) +{ + if (g_strcmp0 (json_reader_get_member_name (reader), "pageInfo") == 0) { + guint total_results, items_per_page; + const GError *child_error = NULL; + + /* Check this is an object. */ + if (!json_reader_is_object (reader)) { + return gdata_parser_error_required_json_content_missing (reader, error); + } + + /* https://developers.google.com/youtube/v3/docs/playlists/list/ */ + json_reader_read_member (reader, "totalResults"); + total_results = json_reader_get_int_value (reader); + json_reader_end_member (reader); + + json_reader_read_member (reader, "resultsPerPage"); + items_per_page = json_reader_get_int_value (reader); + json_reader_end_member (reader); + + child_error = json_reader_get_error (reader); + if (child_error != NULL) { + return gdata_parser_error_from_json_error (reader, + child_error, + error); + } + + _gdata_feed_set_page_info (GDATA_FEED (parsable), total_results, + items_per_page); + + return TRUE; + } else { + return GDATA_PARSABLE_CLASS (gdata_youtube_feed_parent_class)->parse_json (parsable, reader, user_data, error); + } +} diff --git a/gdata/services/youtube/gdata-youtube-feed.h b/gdata/services/youtube/gdata-youtube-feed.h new file mode 100644 index 00000000..0ab173b8 --- /dev/null +++ b/gdata/services/youtube/gdata-youtube-feed.h @@ -0,0 +1,74 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* + * GData Client + * Copyright (C) Philip Withnall 2015 <philip@tecnocode.co.uk> + * + * GData Client is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * GData Client is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GData Client. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GDATA_YOUTUBE_FEED_H +#define GDATA_YOUTUBE_FEED_H + +#include <glib.h> +#include <glib-object.h> +#include <gdata/gdata-feed.h> + +G_BEGIN_DECLS + +#define GDATA_TYPE_YOUTUBE_FEED (gdata_youtube_feed_get_type ()) +#define GDATA_YOUTUBE_FEED(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GDATA_TYPE_YOUTUBE_FEED, GDataYouTubeFeed)) +#define GDATA_YOUTUBE_FEED_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GDATA_TYPE_YOUTUBE_FEED, GDataYouTubeFeedClass)) +#define GDATA_IS_YOUTUBE_FEED(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GDATA_TYPE_YOUTUBE_FEED)) +#define GDATA_IS_YOUTUBE_FEED_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GDATA_TYPE_YOUTUBE_FEED)) +#define GDATA_YOUTUBE_FEED_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GDATA_TYPE_YOUTUBE_FEED, GDataYouTubeFeedClass)) + +typedef struct _GDataYouTubeFeedPrivate GDataYouTubeFeedPrivate; + +/** + * GDataYouTubeFeed: + * + * All the fields in the #GDataYouTubeFeed structure are private and should + * never be accessed directly. + * + * Since: UNRELEASED + */ +typedef struct { + /*< private >*/ + GDataFeed parent; + GDataYouTubeFeedPrivate *priv; +} GDataYouTubeFeed; + +/** + * GDataYouTubeFeedClass: + * + * All the fields in the #GDataYouTubeFeedClass structure are private and should + * never be accessed directly. + * + * Since: UNRELEASED + */ +typedef struct { + /*< private >*/ + GDataFeedClass parent; + + /*< private >*/ + /* Padding for future expansion */ + void (*_g_reserved0) (void); + void (*_g_reserved1) (void); +} GDataYouTubeFeedClass; + +GType gdata_youtube_feed_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* !GDATA_YOUTUBE_FEED_H */ diff --git a/gdata/services/youtube/gdata-youtube-service.c b/gdata/services/youtube/gdata-youtube-service.c index e1210ae4..7e54fafa 100644 --- a/gdata/services/youtube/gdata-youtube-service.c +++ b/gdata/services/youtube/gdata-youtube-service.c @@ -244,6 +244,7 @@ #include <string.h> #include "gdata-youtube-service.h" +#include "gdata-youtube-feed.h" #include "gdata-service.h" #include "gdata-private.h" #include "gdata-parser.h" @@ -292,6 +293,7 @@ gdata_youtube_service_class_init (GDataYouTubeServiceClass *klass) gobject_class->get_property = gdata_youtube_service_get_property; gobject_class->finalize = gdata_youtube_service_finalize; + service_class->feed_type = GDATA_TYPE_YOUTUBE_FEED; service_class->append_query_headers = append_query_headers; service_class->parse_error_response = parse_error_response; service_class->get_authorization_domains = get_authorization_domains; |