[libgdata] core: Use the GDataEntry.get_entry_uri() method for batch queries



commit a318351dc493529d43b325440920a3058994aa59
Author: Philip Withnall <philip tecnocode co uk>
Date:   Thu Aug 26 09:38:44 2010 +0100

    core: Use the GDataEntry.get_entry_uri() method for batch queries
    
    To fix the YouTube batch operations so that video IDs can be used in queries
    instead of self URIs, GDataEntry.get_entry_uri() needs to be used to get the
    "ID" to send in a batch query.

 gdata/gdata-batch-operation.c |   15 +++++++++++----
 gdata/tests/youtube.c         |   23 +++++++++--------------
 2 files changed, 20 insertions(+), 18 deletions(-)
---
diff --git a/gdata/gdata-batch-operation.c b/gdata/gdata-batch-operation.c
index 58b1c76..3fb9123 100644
--- a/gdata/gdata-batch-operation.c
+++ b/gdata/gdata-batch-operation.c
@@ -36,18 +36,16 @@
  *	GDataBatchOperation *operation;
  *	GDataContactsContact *contact;
  *	GDataService *service;
- *	GDataLink *self_link;
  *
  *	service = create_contacts_service ();
  *	contact = create_new_contact ();
- *	self_link = gdata_entry_look_up_link (other_contact, GDATA_LINK_SELF);
  *	batch_link = gdata_feed_look_up_link (contacts_feed, GDATA_LINK_BATCH);
  *
  *	operation = gdata_batchable_create_operation (GDATA_BATCHABLE (service), gdata_link_get_uri (batch_link));
  *
  *	/<!-- -->* Add to the operation to insert a new contact and query for another one *<!-- -->/
  *	op_id = gdata_batch_operation_add_insertion (operation, GDATA_ENTRY (contact), insertion_cb, user_data);
- *	op_id2 = gdata_batch_operation_add_query (operation, gdata_link_get_uri (self_link), GDATA_TYPE_CONTACTS_CONTACT, query_cb, user_data);
+ *	op_id2 = gdata_batch_operation_add_query (operation, gdata_entry_get_id (other_contact), GDATA_TYPE_CONTACTS_CONTACT, query_cb, user_data);
  *
  *	g_object_unref (contact);
  *	g_object_unref (service);
@@ -513,17 +511,26 @@ run_cb (gpointer key, BatchOperation *op, GDataFeed *feed)
 	if (op->type == GDATA_BATCH_OPERATION_QUERY) {
 		/* Queries are weird; build a new throwaway entry, and add it to the feed */
 		GDataEntry *entry;
+		GDataEntryClass *klass;
+		gchar *entry_uri;
 		GTimeVal updated;
 
 		g_get_current_time (&updated);
 
-		entry = gdata_entry_new (op->query_id);
+		klass = g_type_class_ref (op->entry_type);
+		g_assert (klass->get_entry_uri != NULL);
+
+		entry_uri = klass->get_entry_uri (op->query_id);
+		entry = gdata_entry_new (entry_uri);
+		g_free (entry_uri);
+
 		gdata_entry_set_title (entry, "Batch operation query");
 		_gdata_entry_set_updated (entry, &updated);
 
 		_gdata_entry_set_batch_data (entry, op->id, op->type);
 		_gdata_feed_add_entry (feed, entry);
 
+		g_type_class_unref (klass);
 		g_object_unref (entry);
 	} else {
 		/* Everything else just dumps the entry's XML in the request */
diff --git a/gdata/tests/youtube.c b/gdata/tests/youtube.c
index 55abdbc..b2d2ae3 100644
--- a/gdata/tests/youtube.c
+++ b/gdata/tests/youtube.c
@@ -950,7 +950,6 @@ test_batch (BatchData *data, gconstpointer service)
 {
 	GDataBatchOperation *operation;
 	GDataService *service2;
-	GDataLink *self_link;
 	gchar *feed_uri;
 	guint op_id, op_id2;
 	GError *error = NULL;
@@ -975,8 +974,7 @@ test_batch (BatchData *data, gconstpointer service)
 	g_free (feed_uri);
 
 	/* Run a singleton batch operation to query one of the entries */
-	self_link = gdata_entry_look_up_link (data->new_video, GDATA_LINK_SELF);
-	gdata_test_batch_operation_query (operation, gdata_link_get_uri (self_link), GDATA_TYPE_YOUTUBE_VIDEO, data->new_video, NULL, NULL);
+	gdata_test_batch_operation_query (operation, gdata_entry_get_id (data->new_video), GDATA_TYPE_YOUTUBE_VIDEO, data->new_video, NULL, NULL);
 
 	g_assert (gdata_batch_operation_run (operation, NULL, &error) == TRUE);
 	g_assert_no_error (error);
@@ -986,9 +984,10 @@ test_batch (BatchData *data, gconstpointer service)
 
 	/* Run another batch operation to query the two entries */
 	operation = gdata_batchable_create_operation (GDATA_BATCHABLE (service), "http://gdata.youtube.com/feeds/api/videos/batch";);
-	op_id = gdata_test_batch_operation_query (operation, gdata_link_get_uri (self_link), GDATA_TYPE_YOUTUBE_VIDEO, data->new_video, NULL, NULL);
-	self_link = gdata_entry_look_up_link (data->new_video2, GDATA_LINK_SELF);
-	op_id2 = gdata_test_batch_operation_query (operation, gdata_link_get_uri (self_link), GDATA_TYPE_YOUTUBE_VIDEO, data->new_video2, NULL, NULL);
+	op_id = gdata_test_batch_operation_query (operation, gdata_entry_get_id (data->new_video), GDATA_TYPE_YOUTUBE_VIDEO, data->new_video, NULL,
+	                                          NULL);
+	op_id2 = gdata_test_batch_operation_query (operation, gdata_entry_get_id (data->new_video2), GDATA_TYPE_YOUTUBE_VIDEO, data->new_video2, NULL,
+	                                           NULL);
 	g_assert_cmpuint (op_id, !=, op_id2);
 
 	g_assert (gdata_batch_operation_run (operation, NULL, &error) == TRUE);
@@ -1014,15 +1013,13 @@ static void
 test_batch_async (BatchData *data, gconstpointer service)
 {
 	GDataBatchOperation *operation;
-	GDataLink *self_link;
 	guint op_id;
 	GMainLoop *main_loop;
 
 	/* Run an async query operation on the video */
-	self_link = gdata_entry_look_up_link (data->new_video, GDATA_LINK_SELF);
-
 	operation = gdata_batchable_create_operation (GDATA_BATCHABLE (service), "http://gdata.youtube.com/feeds/api/videos/batch";);
-	op_id = gdata_test_batch_operation_query (operation, gdata_link_get_uri (self_link), GDATA_TYPE_YOUTUBE_VIDEO, data->new_video, NULL, NULL);
+	op_id = gdata_test_batch_operation_query (operation, gdata_entry_get_id (data->new_video), GDATA_TYPE_YOUTUBE_VIDEO, data->new_video, NULL,
+	                                          NULL);
 
 	main_loop = g_main_loop_new (NULL, TRUE);
 
@@ -1048,16 +1045,14 @@ static void
 test_batch_async_cancellation (BatchData *data, gconstpointer service)
 {
 	GDataBatchOperation *operation;
-	GDataLink *self_link;
 	guint op_id;
 	GMainLoop *main_loop;
 	GCancellable *cancellable;
 
 	/* Run an async query operation on the video */
-	self_link = gdata_entry_look_up_link (data->new_video, GDATA_LINK_SELF);
-
 	operation = gdata_batchable_create_operation (GDATA_BATCHABLE (service), "http://gdata.youtube.com/feeds/api/videos/batch";);
-	op_id = gdata_test_batch_operation_query (operation, gdata_link_get_uri (self_link), GDATA_TYPE_YOUTUBE_VIDEO, data->new_video, NULL, NULL);
+	op_id = gdata_test_batch_operation_query (operation, gdata_entry_get_id (data->new_video), GDATA_TYPE_YOUTUBE_VIDEO, data->new_video, NULL,
+	                                          NULL);
 
 	main_loop = g_main_loop_new (NULL, TRUE);
 	cancellable = g_cancellable_new ();



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