[libgdata] Bug 589858 — Handle gphoto XML elements found in 'GDataFeed'
- From: Philip Withnall <pwithnall src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgdata] Bug 589858 — Handle gphoto XML elements found in 'GDataFeed'
- Date: Sun, 25 Oct 2009 15:11:55 +0000 (UTC)
commit 68b774ab2134e311cd564139aa899d8fe8ecbb65
Author: Richard Schwarting <aquarichy gmail com>
Date: Sun Oct 25 14:46:23 2009 +0000
Bug 589858 â?? Handle gphoto XML elements found in 'GDataFeed'
Adds a GDataPicasaWebUser, which exposes information about each
registered user on PicasaWeb, queryable from the PicasaWeb service. The
patch also suppresses gphoto XML elements on PicasaWeb feeds, since
they duplicate data available in other, better places.
Closes: bgo#589858
docs/reference/gdata-sections.txt | 39 +++++++++++++
gdata/gdata.h | 1 +
gdata/gdata.symbols | 9 +++
gdata/services/picasaweb/Makefile.am | 8 ++-
gdata/services/picasaweb/gdata-picasaweb-query.c | 2 +-
gdata/services/picasaweb/gdata-picasaweb-service.c | 60 +++++++++++++++++--
gdata/services/picasaweb/gdata-picasaweb-service.h | 3 +
gdata/tests/picasaweb.c | 22 +++++++
8 files changed, 134 insertions(+), 10 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 63d7b27..9f5bdd8 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -1183,6 +1183,7 @@ GDataYouTubeStatePrivate
GDataPicasaWebService
GDataPicasaWebServiceClass
gdata_picasaweb_service_new
+gdata_picasaweb_service_get_user
gdata_picasaweb_service_query_all_albums
gdata_picasaweb_service_query_all_albums_async
gdata_picasaweb_service_query_files
@@ -1198,6 +1199,44 @@ GDATA_TYPE_PICASAWEB_SERVICE
</SECTION>
<SECTION>
+<FILE>gdata-picasaweb-feed</FILE>
+<TITLE>GDataPicasaWebFeed</TITLE>
+GDataPicasaWebFeed
+GDataPicasaWebFeedClass
+<SUBSECTION Standard>
+gdata_picasaweb_feed_get_type
+GDATA_PICASAWEB_FEED
+GDATA_PICASAWEB_FEED_CLASS
+GDATA_PICASAWEB_FEED_GET_CLASS
+GDATA_IS_PICASAWEB_FEED
+GDATA_IS_PICASAWEB_FEED_CLASS
+GDATA_TYPE_PICASAWEB_FEED
+</SECTION>
+
+<SECTION>
+<FILE>gdata-picasaweb-user</FILE>
+<TITLE>GDataPicasaWebUser</TITLE>
+GDataPicasaWebUser
+GDataPicasaWebUserClass
+gdata_picasaweb_user_get_user
+gdata_picasaweb_user_get_nickname
+gdata_picasaweb_user_get_quota_limit
+gdata_picasaweb_user_get_quota_current
+gdata_picasaweb_user_get_max_photos_per_album
+gdata_picasaweb_user_get_thumbnail_uri
+<SUBSECTION Standard>
+gdata_picasaweb_user_get_type
+GDATA_PICASAWEB_USER
+GDATA_PICASAWEB_USER_CLASS
+GDATA_PICASAWEB_USER_GET_CLASS
+GDATA_IS_PICASAWEB_USER
+GDATA_IS_PICASAWEB_USER_CLASS
+GDATA_TYPE_PICASAWEB_USER
+<SUBSECTION Private>
+GDataPicasaWebUserPrivate
+</SECTION>
+
+<SECTION>
<FILE>gdata-picasaweb-query</FILE>
<TITLE>GDataPicasaWebQuery</TITLE>
GDataPicasaWebQuery
diff --git a/gdata/gdata.h b/gdata/gdata.h
index c5830be..347694c 100644
--- a/gdata/gdata.h
+++ b/gdata/gdata.h
@@ -84,6 +84,7 @@
#include <gdata/services/picasaweb/gdata-picasaweb-album.h>
#include <gdata/services/picasaweb/gdata-picasaweb-file.h>
#include <gdata/services/picasaweb/gdata-picasaweb-enums.h>
+#include <gdata/services/picasaweb/gdata-picasaweb-user.h>
/* Google Contacts */
#include <gdata/services/contacts/gdata-contacts-service.h>
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 2ee91d5..672b3e9 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -597,10 +597,19 @@ gdata_picasaweb_file_get_coordinates
gdata_picasaweb_file_set_coordinates
gdata_picasaweb_service_get_type
gdata_picasaweb_service_new
+gdata_picasaweb_service_get_user
gdata_picasaweb_service_query_all_albums
gdata_picasaweb_service_query_all_albums_async
gdata_picasaweb_service_query_files
gdata_picasaweb_service_upload_file
+gdata_picasaweb_feed_get_type
+gdata_picasaweb_user_get_type
+gdata_picasaweb_user_get_user
+gdata_picasaweb_user_get_nickname
+gdata_picasaweb_user_get_quota_limit
+gdata_picasaweb_user_get_quota_current
+gdata_picasaweb_user_get_max_photos_per_album
+gdata_picasaweb_user_get_thumbnail_uri
gdata_picasaweb_query_get_type
gdata_picasaweb_query_new
gdata_picasaweb_query_new_with_limits
diff --git a/gdata/services/picasaweb/Makefile.am b/gdata/services/picasaweb/Makefile.am
index 15d1bde..1734bbf 100644
--- a/gdata/services/picasaweb/Makefile.am
+++ b/gdata/services/picasaweb/Makefile.am
@@ -32,7 +32,9 @@ gdata_picasaweb_headers = \
gdata-picasaweb-service.h \
gdata-picasaweb-query.h \
gdata-picasaweb-file.h \
- gdata-picasaweb-album.h
+ gdata-picasaweb-album.h \
+ gdata-picasaweb-user.h \
+ gdata-picasaweb-feed.h
gdatapicasawebinclude_HEADERS = \
$(gdata_picasaweb_headers) \
@@ -45,7 +47,9 @@ libgdatapicasaweb_la_SOURCES = \
gdata-picasaweb-album.c \
gdata-picasaweb-query.c \
gdata-picasaweb-file.c \
- gdata-picasaweb-service.c
+ gdata-picasaweb-service.c \
+ gdata-picasaweb-user.c \
+ gdata-picasaweb-feed.c
libgdatapicasaweb_la_CPPFLAGS = \
-I$(top_srcdir) \
diff --git a/gdata/services/picasaweb/gdata-picasaweb-query.c b/gdata/services/picasaweb/gdata-picasaweb-query.c
index 8306b3a..f1e12ef 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-query.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-query.c
@@ -248,7 +248,7 @@ get_query_uri (GDataQuery *self, const gchar *feed_uri, GString *query_uri, gboo
APPEND_SEP
if (priv->visibility == 0)
- g_string_append (query_uri, "access=all");
+ ; // Appending nothing to retrieve all for authenticated users and just public albums for unauthenticated
else if (priv->visibility == GDATA_PICASAWEB_PUBLIC)
g_string_append (query_uri, "access=public");
else if (priv->visibility == GDATA_PICASAWEB_PRIVATE)
diff --git a/gdata/services/picasaweb/gdata-picasaweb-service.c b/gdata/services/picasaweb/gdata-picasaweb-service.c
index 20b0119..7b29311 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-service.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-service.c
@@ -41,6 +41,7 @@
#include "gdata-parser.h"
#include "atom/gdata-link.h"
#include "gdata-upload-stream.h"
+#include "gdata-picasaweb-feed.h"
G_DEFINE_TYPE (GDataPicasaWebService, gdata_picasaweb_service, GDATA_TYPE_SERVICE)
@@ -49,6 +50,7 @@ gdata_picasaweb_service_class_init (GDataPicasaWebServiceClass *klass)
{
GDataServiceClass *service_class = GDATA_SERVICE_CLASS (klass);
service_class->service_name = "lh2";
+ service_class->feed_type = GDATA_TYPE_PICASAWEB_FEED;
}
static void
@@ -58,12 +60,17 @@ gdata_picasaweb_service_init (GDataPicasaWebService *self)
}
/*
- * This constructs the URI we want to access for querying albums.
+ * create_uri:
+ * @self: a #GDataPicasaWebService
+ * @username: the username to use, or %NULL to use the currently logged in user
+ * @type: the type of object to access: "entry" for a user, or "feed" for an album
+ *
+ * Builds a URI to use when querying for albums or a user.
*
- * Remember to free the URI in the caller.
-*/
+ * Return value: a constructed URI; free with g_free()
+ */
static gchar *
-create_uri (GDataPicasaWebService *self, const gchar *username)
+create_uri (GDataPicasaWebService *self, const gchar *username, const gchar *type)
{
if (username == NULL) {
/* Ensure we're authenticated first */
@@ -74,7 +81,7 @@ create_uri (GDataPicasaWebService *self, const gchar *username)
username = "default";
}
- return g_strdup_printf ("http://picasaweb.google.com/data/feed/api/user/%s", username);
+ return g_strdup_printf ("http://picasaweb.google.com/data/%s/api/user/%s", type, username);
}
/**
@@ -98,6 +105,45 @@ gdata_picasaweb_service_new (const gchar *client_id)
}
/**
+ * gdata_picasaweb_service_get_user
+ * @self: a #GDataPicasaWebService
+ * @username: the username of the user whose information you wish to retrieve, or %NULL for the currently authenticated user.
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @error: a #GError, or %NULL
+ *
+ * Queries the service to return the user specified by @username.
+ *
+ * Return value: a #GDataPicasaWebUser; unref with g_object_unref()
+ *
+ * Since: 0.6.0
+ **/
+GDataPicasaWebUser *
+gdata_picasaweb_service_get_user (GDataPicasaWebService *self, const gchar *username, GCancellable *cancellable, GError **error)
+{
+ gchar *uri;
+ GDataParsable *user;
+ SoupMessage *message;
+
+ g_return_val_if_fail (GDATA_IS_PICASAWEB_SERVICE (self), NULL);
+
+ uri = create_uri (self, username, "entry");
+ if (uri == NULL) {
+ g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
+ _("You must specify a username or be authenticated to query a user."));
+ return NULL;
+ }
+ message = _gdata_service_query (GDATA_SERVICE (self), uri, NULL, cancellable, NULL, NULL, error);
+ if (message == NULL)
+ return NULL;
+
+ g_assert (message->response_body->data != NULL);
+ user = gdata_parsable_new_from_xml (GDATA_TYPE_PICASAWEB_USER, message->response_body->data, message->response_body->length, error);
+ g_object_unref (message);
+
+ return GDATA_PICASAWEB_USER (user);
+}
+
+/**
* gdata_picasaweb_service_query_all_albums:
* @self: a #GDataPicasaWebService
* @query: a #GDataQuery with the query parameters, or %NULL
@@ -136,7 +182,7 @@ gdata_picasaweb_service_query_all_albums (GDataPicasaWebService *self, GDataQuer
return NULL;
}
- uri = create_uri (self, username);
+ uri = create_uri (self, username, "feed");
if (uri == NULL) {
g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
_("You must specify a username or be authenticated to query all albums."));
@@ -190,7 +236,7 @@ gdata_picasaweb_service_query_all_albums_async (GDataPicasaWebService *self, GDa
return;
}
- uri = create_uri (self, username);
+ uri = create_uri (self, username, "feed");
if (uri == NULL) {
g_simple_async_report_error_in_idle (G_OBJECT (self), callback, user_data,
GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
diff --git a/gdata/services/picasaweb/gdata-picasaweb-service.h b/gdata/services/picasaweb/gdata-picasaweb-service.h
index 96eb9c1..4dc227d 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-service.h
+++ b/gdata/services/picasaweb/gdata-picasaweb-service.h
@@ -26,6 +26,7 @@
#include <gdata/gdata-service.h>
#include <gdata/services/picasaweb/gdata-picasaweb-album.h>
+#include <gdata/services/picasaweb/gdata-picasaweb-user.h>
G_BEGIN_DECLS
@@ -65,6 +66,8 @@ GDataPicasaWebService *gdata_picasaweb_service_new (const gchar *client_id) G_GN
#include <gdata/services/picasaweb/gdata-picasaweb-query.h>
+GDataPicasaWebUser *gdata_picasaweb_service_get_user (GDataPicasaWebService *self, const gchar *username, GCancellable *cancellable, GError **error) G_GNUC_WARN_UNUSED_RESULT;
+
GDataFeed *gdata_picasaweb_service_query_all_albums (GDataPicasaWebService *self, GDataQuery *query, const gchar *username,
GCancellable *cancellable, GDataQueryProgressCallback progress_callback, gpointer progress_user_data,
GError **error) G_GNUC_WARN_UNUSED_RESULT;
diff --git a/gdata/tests/picasaweb.c b/gdata/tests/picasaweb.c
index c98cbaf..6c7519f 100644
--- a/gdata/tests/picasaweb.c
+++ b/gdata/tests/picasaweb.c
@@ -590,6 +590,27 @@ test_query_all_albums (GDataService *service)
}
static void
+test_query_user (GDataService *service)
+{
+ GDataPicasaWebUser *user;
+ GError *error = NULL;
+
+ user = gdata_picasaweb_service_get_user (GDATA_PICASAWEB_SERVICE (service), NULL, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (GDATA_IS_PICASAWEB_USER (user));
+ g_clear_error (&error);
+
+ g_assert_cmpstr (gdata_picasaweb_user_get_user (user), ==, "libgdata.picasaweb");
+ g_assert_cmpstr (gdata_picasaweb_user_get_nickname (user), ==, "libgdata.picasaweb");
+ g_assert_cmpint (gdata_picasaweb_user_get_quota_limit (user), ==, 1073741824); /* 1GiB: it'll be a beautiful day when this assert gets tripped */
+ g_assert_cmpint (gdata_picasaweb_user_get_quota_current (user), >, 0);
+ g_assert_cmpint (gdata_picasaweb_user_get_max_photos_per_album (user), ==, 500);
+ g_assert_cmpstr (gdata_picasaweb_user_get_thumbnail_uri (user), ==, "http://lh6.ggpht.com/_1kdcGyvOb8c/AAAA9mDag3s/AAAAAAAAAAA/Jq-NWYWKFao/s64-c/libgdata.picasaweb.jpg");
+
+ g_object_unref (user);
+}
+
+static void
test_query_new_with_limits (GDataService *service)
{
GDataQuery *query;
@@ -725,6 +746,7 @@ main (int argc, char *argv[])
g_test_add_func ("/picasaweb/authentication_async", test_authentication_async);
g_test_add_data_func ("/picasaweb/upload/photo", service, test_upload_simple);
g_test_add_data_func ("/picasaweb/query/all_albums", service, test_query_all_albums);
+ g_test_add_data_func ("/picasaweb/query/user", service, test_query_user);
if (g_test_thorough () == TRUE)
g_test_add_data_func ("/picasaweb/query/all_albums_async", service, test_query_all_albums_async);
g_test_add_data_func ("/picasaweb/query/new_with_limits", service, test_query_new_with_limits);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]