[gnome-todo] todoist: Refactor compress code into a function
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] todoist: Refactor compress code into a function
- Date: Sun, 4 Mar 2018 17:19:39 +0000 (UTC)
commit 5f0dbcf20f7c46006963a72581526d0b02e50caa
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sat Mar 3 20:07:42 2018 -0300
todoist: Refactor compress code into a function
plugins/todoist/gtd-provider-todoist.c | 37 ++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 11 deletions(-)
---
diff --git a/plugins/todoist/gtd-provider-todoist.c b/plugins/todoist/gtd-provider-todoist.c
index cce23b2..71d5cd7 100644
--- a/plugins/todoist/gtd-provider-todoist.c
+++ b/plugins/todoist/gtd-provider-todoist.c
@@ -724,19 +724,14 @@ synchronize (GtdProviderTodoist *self)
post (self, params, (RestProxyCallAsyncCallback) on_synchronize_completed_cb, self);
}
-static void
-process_request_queue (GtdProviderTodoist *self)
+static gchar*
+compress_commands (GtdProviderTodoist *self,
+ GList **out_list)
{
- g_autoptr (JsonObject) params = NULL;
g_autoptr (GString) command = NULL;
g_autoptr (GList) requests = NULL;
guint i;
- if (g_queue_is_empty (self->queue) || self->timeout_id > 0)
- return;
-
- g_debug ("Processing request queue");
-
/*
* Compress at most MAX_COMMANDS_PER_REQUEST (which is 100 - see the developer doc at
* https://developer.todoist.com/sync/v7/#batching-commands) commands in the queue.
@@ -764,13 +759,33 @@ process_request_queue (GtdProviderTodoist *self)
/* We need to parse the commands back in the order they were sent */
requests = g_list_reverse (requests);
+ g_assert (out_list != NULL);
+ *out_list = g_steal_pointer (&requests);
+
+ g_debug ("Compressed %u commands, request is:\n%s", i, command->str);
+
+ return g_string_free (g_steal_pointer (&command), FALSE);
+}
+
+static void
+process_request_queue (GtdProviderTodoist *self)
+{
+ g_autoptr (JsonObject) params = NULL;
+ g_autoptr (GList) requests = NULL;
+ g_autofree gchar *command = NULL;
+
+ if (g_queue_is_empty (self->queue) || self->timeout_id > 0)
+ return;
+
+ g_debug ("Processing request queue");
+
+ command = compress_commands (self, &requests);
+
/* Build up the JSON command */
params = json_object_new ();
- json_object_set_string_member (params, "commands", command->str);
+ json_object_set_string_member (params, "commands", command);
json_object_set_string_member (params, "token", self->access_token);
- g_debug ("Compressed %u commands, request is:\n%s", i, command->str);
-
post (self, params, (RestProxyCallAsyncCallback) on_operation_completed_cb, g_steal_pointer (&requests));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]