diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2009-04-09 16:24:56 +0100 |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2009-04-09 16:24:56 +0100 |
commit | 41443aa559334b709b0e5d310096455b258cbdc9 (patch) | |
tree | ea2021521534974e70632e46c778bdbd980e24f8 | |
parent | 5657b4d6013f16700bd205a85963572b98c62522 (diff) | |
download | libgdata-41443aa559334b709b0e5d310096455b258cbdc9.tar.gz |
Return the updated entry when inserting an entry.
A few fixes for previous commits.
-rw-r--r-- | gdata/gdata-entry.c | 6 | ||||
-rw-r--r-- | gdata/gdata-service.c | 57 | ||||
-rw-r--r-- | gdata/gdata-service.h | 3 | ||||
-rw-r--r-- | gdata/services/calendar/gdata-calendar-calendar.c | 2 | ||||
-rw-r--r-- | gdata/services/calendar/gdata-calendar-event.c | 2 | ||||
-rw-r--r-- | gdata/services/youtube/gdata-youtube-video.c | 2 | ||||
-rw-r--r-- | gdata/tests/general.c | 2 | ||||
-rw-r--r-- | gdata/tests/youtube.c | 2 |
8 files changed, 58 insertions, 18 deletions
diff --git a/gdata/gdata-entry.c b/gdata/gdata-entry.c index 56e4bbf2..8f16cff6 100644 --- a/gdata/gdata-entry.c +++ b/gdata/gdata-entry.c @@ -176,6 +176,10 @@ gdata_entry_set_property (GObject *object, guint property_id, const GValue *valu GDataEntry *self = GDATA_ENTRY (object); switch (property_id) { + case PROP_ID: + /* Construct only */ + self->priv->id = g_value_dup_string (value); + break; case PROP_TITLE: gdata_entry_set_title (self, g_value_get_string (value)); break; @@ -363,7 +367,7 @@ _gdata_entry_new_from_xml_node (xmlDoc *doc, xmlNode *node, GError **error) g_return_val_if_fail (node != NULL, FALSE); g_return_val_if_fail (xmlStrcmp (node->name, (xmlChar*) "entry") == 0, FALSE); - entry = gdata_entry_new (); + entry = gdata_entry_new (NULL); node = node->xmlChildrenNode; while (node != NULL) { diff --git a/gdata/gdata-service.c b/gdata/gdata-service.c index 6c8fa8c0..09fb750b 100644 --- a/gdata/gdata-service.c +++ b/gdata/gdata-service.c @@ -878,6 +878,7 @@ gdata_service_query (GDataService *self, const gchar *feed_uri, GDataQuery *quer * @self: a #GDataService * @upload_uri: the URI to which the upload should be sent * @entry: the #GDataEntry to upload + * @parser_func: a #GDataEntryParserFunc to build a #GDataEntry from the updated XML * @cancellable: optional #GCancellable object, or %NULL * @error: a #GError, or %NULL * @@ -885,6 +886,8 @@ gdata_service_query (GDataService *self, const gchar *feed_uri, GDataQuery *quer * the <ulink type="http" url="http://code.google.com/apis/gdata/docs/2.0/reference.html#Queries">online documentation</ulink> for the GData * protocol. * + * The service will return an updated version of the entry, which is the return value of this function on success. + * * If @cancellable is not %NULL, then the operation can be cancelled by triggering the @cancellable object from another thread. * If the operation was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. * @@ -894,24 +897,28 @@ gdata_service_query (GDataService *self, const gchar *feed_uri, GDataQuery *quer * If there is an error inserting the entry, a %GDATA_SERVICE_ERROR_WITH_INSERTION error will be returned. Currently, subclasses * <emphasis>cannot</emphasis> cannot override this or provide more specific errors. * - * Return value: %TRUE on success, %FALSE otherwise + * Return value: an updated #GDataEntry, or %NULL **/ -gboolean -gdata_service_insert_entry (GDataService *self, const gchar *upload_uri, GDataEntry *entry, GCancellable *cancellable, GError **error) +GDataEntry * +gdata_service_insert_entry (GDataService *self, const gchar *upload_uri, GDataEntry *entry, GDataEntryParserFunc parser_func, + GCancellable *cancellable, GError **error) { GDataServiceClass *klass; SoupMessage *message; gchar *upload_data; guint status; + xmlDoc *doc; + xmlNode *node; - g_return_val_if_fail (GDATA_IS_SERVICE (self), FALSE); - g_return_val_if_fail (upload_uri != NULL, FALSE); - g_return_val_if_fail (GDATA_IS_ENTRY (entry), FALSE); + g_return_val_if_fail (GDATA_IS_SERVICE (self), NULL); + g_return_val_if_fail (upload_uri != NULL, NULL); + g_return_val_if_fail (GDATA_IS_ENTRY (entry), NULL); + g_return_val_if_fail (parser_func != NULL, NULL); if (gdata_entry_is_inserted (entry) == TRUE) { g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_ENTRY_ALREADY_INSERTED, _("The entry has already been inserted.")); - return FALSE; + return NULL; } message = soup_message_new (SOUP_METHOD_POST, upload_uri); @@ -931,7 +938,7 @@ gdata_service_insert_entry (GDataService *self, const gchar *upload_uri, GDataEn /* Check for cancellation */ if (g_cancellable_set_error_if_cancelled (cancellable, error) == TRUE) { g_object_unref (message); - return FALSE; + return NULL; } if (status != 201) { @@ -940,13 +947,41 @@ gdata_service_insert_entry (GDataService *self, const gchar *upload_uri, GDataEn g_set_error (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_WITH_INSERTION, _("TODO: error code %u when inserting"), status); g_object_unref (message); - return FALSE; + return NULL; } + /* Build the updated entry */ g_assert (message->response_body->data != NULL); - /* TODO: Update the entry such that it looks like it's been inserted */ - return TRUE; + /* Parse the XML */ + doc = xmlReadMemory (message->response_body->data, message->response_body->length, "entry.xml", NULL, 0); + if (doc == NULL) { + xmlError *xml_error = xmlGetLastError (); + g_set_error (error, GDATA_PARSER_ERROR, GDATA_PARSER_ERROR_PARSING_STRING, + _("Error parsing XML: %s"), + xml_error->message); + return NULL; + } + + /* Get the root element */ + node = xmlDocGetRootElement (doc); + if (node == NULL) { + /* XML document's empty */ + xmlFreeDoc (doc); + g_set_error (error, GDATA_PARSER_ERROR, GDATA_PARSER_ERROR_EMPTY_DOCUMENT, + _("Error parsing XML: %s"), + _("Empty document.")); + return NULL; + } + + if (xmlStrcmp (node->name, (xmlChar*) "entry") != 0) { + /* No <entry> element (required) */ + xmlFreeDoc (doc); + gdata_parser_error_required_element_missing ("entry", "root", error); + return NULL; + } + + return parser_func (doc, node, error); } /** diff --git a/gdata/gdata-service.h b/gdata/gdata-service.h index 4d53e4c6..70d35612 100644 --- a/gdata/gdata-service.h +++ b/gdata/gdata-service.h @@ -173,7 +173,8 @@ void gdata_service_query_async (GDataService *self, const gchar *feed_uri, GData GAsyncReadyCallback callback, gpointer user_data); GDataFeed *gdata_service_query_finish (GDataService *self, GAsyncResult *async_result, GError **error); -gboolean gdata_service_insert_entry (GDataService *self, const gchar *upload_uri, GDataEntry *entry, GCancellable *cancellable, GError **error); +GDataEntry *gdata_service_insert_entry (GDataService *self, const gchar *upload_uri, GDataEntry *entry, GDataEntryParserFunc parser_func, + GCancellable *cancellable, GError **error); /* TODO: async versions */ gboolean gdata_service_is_authenticated (GDataService *self); diff --git a/gdata/services/calendar/gdata-calendar-calendar.c b/gdata/services/calendar/gdata-calendar-calendar.c index 2be0b7dd..62393bb7 100644 --- a/gdata/services/calendar/gdata-calendar-calendar.c +++ b/gdata/services/calendar/gdata-calendar-calendar.c @@ -255,7 +255,7 @@ _gdata_calendar_calendar_new_from_xml_node (xmlDoc *doc, xmlNode *node, GError * g_return_val_if_fail (node != NULL, FALSE); g_return_val_if_fail (xmlStrcmp (node->name, (xmlChar*) "entry") == 0, FALSE); - calendar = gdata_calendar_calendar_new (); + calendar = gdata_calendar_calendar_new (NULL); node = node->xmlChildrenNode; while (node != NULL) { diff --git a/gdata/services/calendar/gdata-calendar-event.c b/gdata/services/calendar/gdata-calendar-event.c index 41dc7fc1..4b26ba67 100644 --- a/gdata/services/calendar/gdata-calendar-event.c +++ b/gdata/services/calendar/gdata-calendar-event.c @@ -343,7 +343,7 @@ _gdata_calendar_event_new_from_xml_node (xmlDoc *doc, xmlNode *node, GError **er g_return_val_if_fail (node != NULL, FALSE); g_return_val_if_fail (xmlStrcmp (node->name, (xmlChar*) "entry") == 0, FALSE); - event = gdata_calendar_event_new (); + event = gdata_calendar_event_new (NULL); node = node->xmlChildrenNode; while (node != NULL) { diff --git a/gdata/services/youtube/gdata-youtube-video.c b/gdata/services/youtube/gdata-youtube-video.c index 589fc3ef..e910f248 100644 --- a/gdata/services/youtube/gdata-youtube-video.c +++ b/gdata/services/youtube/gdata-youtube-video.c @@ -611,7 +611,7 @@ _gdata_youtube_video_new_from_xml_node (xmlDoc *doc, xmlNode *node, GError **err g_return_val_if_fail (node != NULL, FALSE); g_return_val_if_fail (xmlStrcmp (node->name, (xmlChar*) "entry") == 0, FALSE); - video = gdata_youtube_video_new (); + video = gdata_youtube_video_new (NULL); node = node->xmlChildrenNode; while (node != NULL) { diff --git a/gdata/tests/general.c b/gdata/tests/general.c index a6b60186..e9f026a3 100644 --- a/gdata/tests/general.c +++ b/gdata/tests/general.c @@ -32,7 +32,7 @@ test_entry_get_xml (void) gchar *xml; GError *error = NULL; - entry = gdata_entry_new (); + entry = gdata_entry_new (NULL); gdata_entry_set_title (entry, "Testing title & escaping"); gdata_entry_set_content (entry, "This is some sample content testing, amongst other things, <markup> & odd characters‽"); diff --git a/gdata/tests/youtube.c b/gdata/tests/youtube.c index 173c6272..1a99b3f7 100644 --- a/gdata/tests/youtube.c +++ b/gdata/tests/youtube.c @@ -277,7 +277,7 @@ test_upload_simple (void) g_assert (service != NULL); - video = gdata_youtube_video_new (); + video = gdata_youtube_video_new (NULL); gdata_entry_set_title (GDATA_ENTRY (video), "Bad Wedding Toast"); gdata_youtube_video_set_title (video, "Bad Wedding Toast"); |