diff --git a/src/Todoist.Net.Tests/Services/TransactionTests.cs b/src/Todoist.Net.Tests/Services/TransactionTests.cs index 2f232aa..37a60ac 100644 --- a/src/Todoist.Net.Tests/Services/TransactionTests.cs +++ b/src/Todoist.Net.Tests/Services/TransactionTests.cs @@ -30,11 +30,12 @@ public void CreateProjectAndCreateNote_Success() var note = new Note("Demo note"); transaction.Notes.AddToProjectAsync(note, projectId).Wait(); - transaction.CommitAsync().Wait(); + var syncToken = transaction.CommitAsync().Result; var projectInfo = client.Projects.GetAsync(project.Id).Result; Assert.True(projectInfo.Notes.Count > 0); + Assert.NotNull(syncToken); var deleteTransaction = client.CreateTransaction(); diff --git a/src/Todoist.Net/IAdvancedTodoistClient.cs b/src/Todoist.Net/IAdvancedTodoistClient.cs index e4a7b21..0b21f73 100644 --- a/src/Todoist.Net/IAdvancedTodoistClient.cs +++ b/src/Todoist.Net/IAdvancedTodoistClient.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; @@ -12,11 +12,14 @@ internal interface IAdvancedTodoistClient : ITodoistClient /// Executes the commands asynchronous. /// </summary> /// <param name="commands">The commands.</param> - /// <returns>Returns <see cref="T:System.Threading.Tasks.Task" />.The task object representing the asynchronous operation.</returns> + /// <returns> + /// Returns <see cref="Task{TResult}" />. The task object representing the asynchronous operation + /// that at completion returns the commands execution sync_token. + /// </returns> /// <exception cref="System.ArgumentNullException">Value cannot be null - commands.</exception> /// <exception cref="System.AggregateException">Command execution exception.</exception> /// <exception cref="HttpRequestException">API exception.</exception> - Task ExecuteCommandsAsync(params Command[] commands); + Task<string> ExecuteCommandsAsync(params Command[] commands); /// <summary> /// Posts the request asynchronous. diff --git a/src/Todoist.Net/Models/SyncResponse.cs b/src/Todoist.Net/Models/SyncResponse.cs index ef30dea..28e6b99 100644 --- a/src/Todoist.Net/Models/SyncResponse.cs +++ b/src/Todoist.Net/Models/SyncResponse.cs @@ -12,5 +12,8 @@ internal class SyncResponse [JsonProperty("temp_id_mapping")] public Dictionary<Guid, string> TempIdMappings { get; set; } + + [JsonProperty("sync_token")] + public string SyncToken { get; set; } } } diff --git a/src/Todoist.Net/Services/ITransaction.cs b/src/Todoist.Net/Services/ITransaction.cs index d17b8d5..afd6390 100644 --- a/src/Todoist.Net/Services/ITransaction.cs +++ b/src/Todoist.Net/Services/ITransaction.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Net.Http; using System.Threading.Tasks; @@ -70,9 +70,12 @@ public interface ITransaction /// <summary> /// Commits the transaction asynchronous. /// </summary> - /// <returns>Returns <see cref="T:System.Threading.Tasks.Task" />.The task object representing the asynchronous operation.</returns> + /// <returns> + /// Returns <see cref="Task{TResult}" />. The task object representing the asynchronous operation + /// that at completion returns the transaction sync_token. + /// </returns> /// <exception cref="AggregateException">Command execution exception.</exception> /// <exception cref="HttpRequestException">API exception.</exception> - Task CommitAsync(); + Task<string> CommitAsync(); } } diff --git a/src/Todoist.Net/Services/Transaction.cs b/src/Todoist.Net/Services/Transaction.cs index d2be3fa..255fc6c 100644 --- a/src/Todoist.Net/Services/Transaction.cs +++ b/src/Todoist.Net/Services/Transaction.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; @@ -59,14 +59,17 @@ internal Transaction(IAdvancedTodoistClient todoistClient) /// <summary> /// Commits the transaction asynchronous. /// </summary> - /// <returns>Returns <see cref="T:System.Threading.Tasks.Task" />.The task object representing the asynchronous operation.</returns> + /// <returns> + /// Returns <see cref="Task{TResult}" />. The task object representing the asynchronous operation + /// that at completion returns the transaction sync_token. + /// </returns> /// <exception cref="AggregateException">Command execution exception.</exception> /// <exception cref="HttpRequestException">API exception.</exception> - public async Task CommitAsync() + public async Task<string> CommitAsync() { try { - await _todoistClient.ExecuteCommandsAsync(_commands.ToArray()).ConfigureAwait(false); + return await _todoistClient.ExecuteCommandsAsync(_commands.ToArray()).ConfigureAwait(false); } finally { diff --git a/src/Todoist.Net/TodoistClient.cs b/src/Todoist.Net/TodoistClient.cs index 951a920..8b89650 100644 --- a/src/Todoist.Net/TodoistClient.cs +++ b/src/Todoist.Net/TodoistClient.cs @@ -262,12 +262,15 @@ public Task<T> PostFormAsync<T>( /// Executes the commands asynchronous. /// </summary> /// <param name="commands">The commands.</param> - /// <returns>Returns <see cref="T:System.Threading.Tasks.Task" />.The task object representing the asynchronous operation.</returns> + /// <returns> + /// Returns <see cref="Task{TResult}" />. The task object representing the asynchronous operation + /// that at completion returns the commands execution sync_token. + /// </returns> /// <exception cref="System.ArgumentNullException">Value cannot be null - commands.</exception> /// <exception cref="System.AggregateException">Command execution exception.</exception> /// <exception cref="ArgumentException">Value cannot be an empty collection.</exception> /// <exception cref="HttpRequestException">API exception.</exception> - async Task IAdvancedTodoistClient.ExecuteCommandsAsync(params Command[] commands) + async Task<string> IAdvancedTodoistClient.ExecuteCommandsAsync(params Command[] commands) { if (commands == null) { @@ -294,6 +297,7 @@ async Task IAdvancedTodoistClient.ExecuteCommandsAsync(params Command[] commands { UpdateTempIds(commands, syncResponse.TempIdMappings); } + return syncResponse.SyncToken; } /// <summary>