[libgdata/wip/rishi/drive] documents: Support creating folders and copying files using Drive v2
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata/wip/rishi/drive] documents: Support creating folders and copying files using Drive v2
- Date: Wed, 17 Jun 2015 10:38:35 +0000 (UTC)
commit 60740c2c5ae337562d6c6cf93609d347d113a3df
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Jun 16 18:53:13 2015 +0200
documents: Support creating folders and copying files using Drive v2
It is no longer possible to create a new folder using
gdata_service_insert_entry(). One must now use
gdata_documents_service_add_entry_to_folder for creating folders and
copying existing files.
This is essentially a soft API break, but it’s unavoidable.
https://bugzilla.gnome.org/show_bug.cgi?id=684920
gdata/services/documents/gdata-documents-service.c | 40 +++++++++++++------
1 files changed, 27 insertions(+), 13 deletions(-)
---
diff --git a/gdata/services/documents/gdata-documents-service.c
b/gdata/services/documents/gdata-documents-service.c
index 48db18d..fe35016 100644
--- a/gdata/services/documents/gdata-documents-service.c
+++ b/gdata/services/documents/gdata-documents-service.c
@@ -1125,8 +1125,10 @@ gdata_documents_service_add_entry_to_folder (GDataDocumentsService *self, GDataD
GCancellable *cancellable, GError **error)
{
GDataDocumentsEntry *new_entry;
+ GDataOperationType operation_type;
+ const gchar *uri_prefix = "https://www.googleapis.com/drive/v2/files";
gchar *upload_data;
- const gchar *uri;
+ gchar *uri;
SoupMessage *message;
guint status;
@@ -1139,18 +1141,30 @@ gdata_documents_service_add_entry_to_folder (GDataDocumentsService *self, GDataD
if (gdata_authorizer_is_authorized_for_domain (gdata_service_get_authorizer (GDATA_SERVICE (self)),
get_documents_authorization_domain ()) == FALSE) {
g_set_error_literal (error, GDATA_SERVICE_ERROR, GDATA_SERVICE_ERROR_AUTHENTICATION_REQUIRED,
- _("You must be authenticated to move documents and folders."));
+ _("You must be authenticated to insert or move documents and folders."));
return NULL;
}
+ if (gdata_entry_is_inserted (GDATA_ENTRY (entry)) == TRUE) {
+ const gchar *id;
+
+ id = gdata_entry_get_id (GDATA_ENTRY (entry));
+ uri = g_strconcat (uri_prefix, "/", id, "/copy", NULL);
+ operation_type = GDATA_OPERATION_UPDATE;
+ } else {
+ uri = g_strdup (uri_prefix);
+ operation_type = GDATA_OPERATION_INSERTION;
+ }
+
+ add_folder_link_to_entry (entry, folder);
+
/* NOTE: adding a document to a folder doesn't have server-side ETag support (throws
"noPostConcurrency" error) */
- uri = gdata_entry_get_content_uri (GDATA_ENTRY (folder));
- g_assert (uri != NULL);
- message = _gdata_service_build_message (GDATA_SERVICE (self), get_documents_authorization_domain (),
SOUP_METHOD_POST, uri, NULL, TRUE);
+ message = _gdata_service_build_message (GDATA_SERVICE (self), get_documents_authorization_domain (),
SOUP_METHOD_POST, uri, NULL, FALSE);
+ g_free (uri);
/* Append the data */
- upload_data = gdata_parsable_get_xml (GDATA_PARSABLE (entry));
- soup_message_set_request (message, "application/atom+xml", SOUP_MEMORY_TAKE, upload_data, strlen
(upload_data));
+ upload_data = gdata_parsable_get_json (GDATA_PARSABLE (entry));
+ soup_message_set_request (message, "application/json", SOUP_MEMORY_TAKE, upload_data, strlen
(upload_data));
/* Send the message */
status = _gdata_service_send_message (GDATA_SERVICE (self), message, cancellable, error);
@@ -1159,20 +1173,20 @@ gdata_documents_service_add_entry_to_folder (GDataDocumentsService *self, GDataD
/* Redirect error or cancelled */
g_object_unref (message);
return NULL;
- } else if (status != SOUP_STATUS_CREATED) {
+ } else if (status != SOUP_STATUS_OK) {
/* Error */
GDataServiceClass *klass = GDATA_SERVICE_GET_CLASS (self);
g_assert (klass->parse_error_response != NULL);
- klass->parse_error_response (GDATA_SERVICE (self), GDATA_OPERATION_UPDATE, status,
message->reason_phrase,
- message->response_body->data, message->response_body->length,
error);
+ klass->parse_error_response (GDATA_SERVICE (self), operation_type, status,
message->reason_phrase, message->response_body->data,
+ message->response_body->length, error);
g_object_unref (message);
return NULL;
}
- /* Parse the XML; and update the entry */
+ /* Parse the JSON; and update the entry */
g_assert (message->response_body->data != NULL);
- new_entry = GDATA_DOCUMENTS_ENTRY (gdata_parsable_new_from_xml (G_OBJECT_TYPE (entry),
message->response_body->data,
- message->response_body->length,
error));
+ new_entry = GDATA_DOCUMENTS_ENTRY (gdata_parsable_new_from_json (G_OBJECT_TYPE (entry),
message->response_body->data,
+ message->response_body->length,
error));
g_object_unref (message);
return new_entry;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]