[libgdata] Bug 598913 - Add gdata_picasaweb_service_insert_album()
- From: Richard Hans Schwarting <rschwart src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgdata] Bug 598913 - Add gdata_picasaweb_service_insert_album()
- Date: Sun, 6 Dec 2009 05:12:28 +0000 (UTC)
commit cf9d6021e4e46d0d169a6c15fc25e18e14f3a5fb
Author: Richard Schwarting <rschwart src gnome org>
Date: Sun Dec 6 18:03:05 2009 +1300
Bug 598913 - Add gdata_picasaweb_service_insert_album()
Add an API to facilitate the creation of new PicasaWeb albums
docs/reference/gdata-sections.txt | 1 +
gdata/gdata.symbols | 1 +
gdata/services/picasaweb/gdata-picasaweb-service.c | 48 +++++++++++++++
gdata/services/picasaweb/gdata-picasaweb-service.h | 3 +
gdata/tests/picasaweb.c | 63 ++++++++++++++++++++
5 files changed, 116 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gdata-sections.txt b/docs/reference/gdata-sections.txt
index 282babe..60bc041 100644
--- a/docs/reference/gdata-sections.txt
+++ b/docs/reference/gdata-sections.txt
@@ -1188,6 +1188,7 @@ 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_service_insert_album
<SUBSECTION Standard>
gdata_picasaweb_service_get_type
GDATA_IS_PICASAWEB_SERVICE
diff --git a/gdata/gdata.symbols b/gdata/gdata.symbols
index 8902029..ed18558 100644
--- a/gdata/gdata.symbols
+++ b/gdata/gdata.symbols
@@ -599,6 +599,7 @@ 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_service_insert_album
gdata_picasaweb_feed_get_type
gdata_picasaweb_user_get_type
gdata_picasaweb_user_get_user
diff --git a/gdata/services/picasaweb/gdata-picasaweb-service.c b/gdata/services/picasaweb/gdata-picasaweb-service.c
index 180f2e2..8a4131e 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-service.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-service.c
@@ -400,3 +400,51 @@ gdata_picasaweb_service_upload_file (GDataPicasaWebService *self, GDataPicasaWeb
return new_entry;
}
+
+/**
+ * gdata_picasaweb_service_insert_album:
+ * @self: a #GDataPicasaWebService
+ * @album: a #GDataPicasaWebAlbum to create on the server
+ * @cancellable: optional #GCancellable object, or %NULL
+ * @error: a #GError, or %NULL
+ *
+ * Inserts a new album described by @album. A user must be
+ * authenticated to use this function.
+ *
+ * Return value: the inserted #GDataPicasaWebAlbum; unref with
+ * g_object_unref()
+ *
+ * Since: 0.6.0
+ **/
+GDataPicasaWebAlbum *
+gdata_picasaweb_service_insert_album (GDataPicasaWebService *self, GDataPicasaWebAlbum *album, GCancellable *cancellable, GError **error)
+{
+ GDataCategory *album_kind;
+
+ g_return_val_if_fail (GDATA_IS_PICASAWEB_SERVICE (self), NULL);
+ g_return_val_if_fail (GDATA_IS_PICASAWEB_ALBUM (album), NULL);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ if (gdata_entry_is_inserted (GDATA_ENTRY (album)) == TRUE) {
+ g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_ENTRY_ALREADY_INSERTED,
+ _("The album has already been inserted."));
+ return NULL;
+ }
+
+ if (gdata_service_is_authenticated (GDATA_SERVICE (self)) == FALSE) {
+ g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
+ _("You must be authenticated to insert an album."));
+ return NULL;
+ }
+
+ /* PicasaWeb needs to know that this is an album, so we're adding the category when we insert it to make sure it's there.
+ gdata_entry_add_category() checks if it already exists for us. */
+ album_kind = gdata_category_new ("http://schemas.google.com/photos/2007#album", "http://schemas.google.com/g/2005#kind", NULL);
+ gdata_entry_add_category (GDATA_ENTRY (album), album_kind);
+ g_object_unref (album_kind);
+
+ return GDATA_PICASAWEB_ALBUM (gdata_service_insert_entry (GDATA_SERVICE (self), "http://picasaweb.google.com/data/feed/api/user/default",
+ GDATA_ENTRY (album), cancellable, error));
+}
+
diff --git a/gdata/services/picasaweb/gdata-picasaweb-service.h b/gdata/services/picasaweb/gdata-picasaweb-service.h
index 4dc227d..4e4a518 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-service.h
+++ b/gdata/services/picasaweb/gdata-picasaweb-service.h
@@ -84,6 +84,9 @@ GDataFeed *gdata_picasaweb_service_query_files (GDataPicasaWebService *self, GDa
GDataPicasaWebFile *gdata_picasaweb_service_upload_file (GDataPicasaWebService *self, GDataPicasaWebAlbum *album, GDataPicasaWebFile *file_entry,
GFile *file_data, GCancellable *cancellable, GError **error) G_GNUC_WARN_UNUSED_RESULT;
/* TODO: async version */
+GDataPicasaWebAlbum *gdata_picasaweb_service_insert_album (GDataPicasaWebService *self, GDataPicasaWebAlbum *album, GCancellable *cancellable,
+ GError **error) G_GNUC_WARN_UNUSED_RESULT;
+
G_END_DECLS
diff --git a/gdata/tests/picasaweb.c b/gdata/tests/picasaweb.c
index f5057ea..232cbe6 100644
--- a/gdata/tests/picasaweb.c
+++ b/gdata/tests/picasaweb.c
@@ -856,6 +856,68 @@ test_album_feed (GDataService *service)
}
static void
+test_insert_album (GDataService *service)
+{
+ GDataPicasaWebAlbum *album;
+ GDataPicasaWebAlbum *inserted_album;
+ GTimeVal timestamp;
+ gchar *timestr;
+ GError *error;
+
+ GDataFeed *album_feed;
+ GList *albums;
+ gboolean album_found;
+ GList *node;
+
+ error = NULL;
+
+ album = gdata_picasaweb_album_new ("album_id_72");
+ g_assert (GDATA_IS_PICASAWEB_ALBUM (album));
+
+ gdata_entry_set_title (GDATA_ENTRY (album), "Thanksgiving photos");
+ gdata_entry_set_summary (GDATA_ENTRY (album), "Family photos of the feast!");
+ gdata_picasaweb_album_set_location (album, "Winnipeg, MN");
+
+ g_time_val_from_iso8601 ("2002-10-14T09:58:59.643554Z", ×tamp);
+ gdata_picasaweb_album_set_timestamp (album, ×tamp);
+
+ inserted_album = gdata_picasaweb_service_insert_album (GDATA_PICASAWEB_SERVICE (service), album, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (GDATA_IS_PICASAWEB_ALBUM (inserted_album));
+
+ /* Test that it returns what we gave */
+ g_assert_cmpstr (gdata_entry_get_title (GDATA_ENTRY (inserted_album)), ==, "Thanksgiving photos");
+ g_assert_cmpstr (gdata_entry_get_summary (GDATA_ENTRY (inserted_album)), ==, "Family photos of the feast!");
+ g_assert_cmpstr (gdata_picasaweb_album_get_location (inserted_album), ==, "Winnipeg, MN");
+
+ gdata_picasaweb_album_get_timestamp (inserted_album, ×tamp);
+ timestr = g_time_val_to_iso8601 (×tamp);
+ g_assert_cmpstr (timestr, ==, "2002-10-14T09:58:59Z");
+ g_free (timestr);
+
+ /* Test that album is actually on server */
+ album_feed = gdata_picasaweb_service_query_all_albums (GDATA_PICASAWEB_SERVICE (service), NULL, NULL, NULL, NULL, NULL, &error);
+ g_assert_no_error (error);
+ albums = gdata_feed_get_entries (album_feed);
+
+ album_found = FALSE;
+ for (node = albums; node != NULL; node = node->next) {
+ if (g_strcmp0 (gdata_entry_get_title (GDATA_ENTRY (node->data)), "Thanksgiving photos")) {
+ album_found = TRUE;
+ }
+ }
+ g_assert (album_found);
+
+ /* Clean up the evidence */
+ gdata_service_delete_entry (service, GDATA_ENTRY (inserted_album), NULL, &error);
+ g_assert_no_error (error);
+
+ g_object_unref (album_feed);
+ g_object_unref (album);
+ g_object_unref (inserted_album);
+}
+
+static void
test_query_all_albums (GDataService *service)
{
GDataFeed *album_feed, *photo_feed;
@@ -1075,6 +1137,7 @@ main (int argc, char *argv[])
g_test_add_data_func ("/picasaweb/query/album_feed", service, test_album_feed);
g_test_add_data_func ("/picasaweb/query/album_feed_entry", service, test_album_feed_entry);
g_test_add_data_func ("/picasaweb/query/album", service, test_album);
+ g_test_add_data_func ("/picasaweb/insert/album", service, test_insert_album);
g_test_add_data_func ("/picasaweb/query/photo_feed", service, test_photo_feed);
g_test_add_data_func ("/picasaweb/query/photo_feed_entry", service, test_photo_feed_entry);
g_test_add_data_func ("/picasaweb/query/photo", service, test_photo);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]