├── .editorconfig ├── .gitignore ├── .idea └── .idea.Todoist.Net │ └── .idea │ ├── .gitignore │ ├── .name │ ├── GitLink.xml │ ├── encodings.xml │ ├── indexLayout.xml │ └── vcs.xml ├── .nuke ├── build.schema.json └── parameters.json ├── LICENSE ├── README.md ├── Todoist.Net.sln ├── Todoist.Net.sln.DotSettings ├── appveyor.yml ├── build.cmd ├── build.ps1 ├── build.sh ├── build ├── .editorconfig ├── Build.cs ├── Configuration.cs ├── Directory.Build.props ├── Directory.Build.targets ├── _build.csproj └── _build.csproj.DotSettings ├── images └── todoist-net-nuget.png └── src ├── Todoist.Net.Tests ├── Extensions │ └── Constants.cs ├── Helpers │ ├── FakeLocalTimeZone.cs │ └── FakeLocalTimeZoneTests.cs ├── JsonResolverModifiersTests.cs ├── Models │ ├── DueDateTests.cs │ ├── DurationTests.cs │ └── StringEnumTests.cs ├── RateLimitAwareRestClient.cs ├── Services │ ├── ActivityServiceTests.cs │ ├── BackupServiceTests.cs │ ├── EmailServiceTests.cs │ ├── FiltersServiceTests.cs │ ├── ItemsServiceTests.cs │ ├── LabelsServiceTests.cs │ ├── NotesServiceTests.cs │ ├── NotificationsServiceTests.cs │ ├── ProjectsServiceTests.cs │ ├── RemindersServiceTests.cs │ ├── SectionServiceTests.cs │ ├── SharingServiceTests.cs │ ├── TemplateServiceTests.cs │ ├── TransactionTests.cs │ ├── UploadServiceTests.cs │ └── UsersServiceTests.cs ├── Settings │ └── SettingsProvider.cs ├── Todoist.Net.Tests.csproj ├── TodoistClientFactory.cs └── TodoistClientTests.cs └── Todoist.Net ├── Exceptions └── TodoistException.cs ├── Extensions ├── DateTimeExtensions.cs ├── TodoistServiceCollectionExtensions.cs └── UnsettablePropertiesExtensions.cs ├── IAdvancedTodoistClient.cs ├── ITodoistClient.cs ├── ITodoistClientFactory.cs ├── ITodoistRestClient.cs ├── Models ├── Activity.cs ├── ActivityLog.cs ├── AddItem.cs ├── Backup.cs ├── BaseEntity.cs ├── BaseInvitation.cs ├── BaseItem.cs ├── BaseUnsetEntity.cs ├── Collaborator.cs ├── CollaboratorState.cs ├── CollaboratorStatus.cs ├── Command.cs ├── CommandError.cs ├── CommandResult.cs ├── CommandType.cs ├── CompleteItemArgument.cs ├── CompleteRecurringItemArgument.cs ├── CompletedItem.cs ├── CompletedItemsInfo.cs ├── ComplexId.cs ├── DateFormat.cs ├── DayOfWeek.cs ├── Deadline.cs ├── DueDate.cs ├── Duration.cs ├── DurationUnit.cs ├── EmailInfo.cs ├── EmptyCommand.cs ├── FileAttachment.cs ├── FileBase.cs ├── Filter.cs ├── FilterInfo.cs ├── ICommandArgument.cs ├── IUnsettableProperties.cs ├── IWithRelationsArgument.cs ├── IdToOrderArgument.cs ├── IdToOrderMappingArgument.cs ├── IdsArgument.cs ├── Invitation.cs ├── Item.cs ├── ItemFilter.cs ├── ItemInfo.cs ├── ItemMoveArgument.cs ├── KarmaGoals.cs ├── Label.cs ├── Language.cs ├── LocationTrigger.cs ├── LogExtraData.cs ├── LogFilter.cs ├── MoveArgument.cs ├── Note.cs ├── NotesInfo.cs ├── Notification.cs ├── NotificationService.cs ├── NotificationSetting.cs ├── NotificationSettings.cs ├── NotificationType.cs ├── ObjectEventTypes.cs ├── ObjectType.cs ├── OrderEntry.cs ├── OrderType.cs ├── Priority.cs ├── Project.cs ├── ProjectData.cs ├── ProjectInfo.cs ├── ProjectReorderArgument.cs ├── QuickAddItem.cs ├── Reminder.cs ├── ReminderInfo.cs ├── ReminderService.cs ├── ReminderType.cs ├── ReorderArgument.cs ├── ReorderItemsArgument.cs ├── ReorderProjectArgument.cs ├── ReorderSectionArgument.cs ├── ResourceType.cs ├── Resources.cs ├── Section.cs ├── SectionMoveArgument.cs ├── SectionOrderEntry.cs ├── ShareCommandArgument.cs ├── StringEnum.cs ├── SyncResponse.cs ├── TimeFormat.cs ├── TimeZoneInfo.cs ├── UpdateItem.cs ├── Upload.cs ├── User.cs └── UserInfo.cs ├── Serialization ├── Converters │ ├── BoolConverter.cs │ ├── CommandArgumentConverter.cs │ ├── CommandResultConverter.cs │ ├── ComplexIdConverter.cs │ ├── DateOnlyConverter.cs │ └── StringEnumTypeConverter.cs └── Resolvers │ └── JsonResolverModifiers.cs ├── Services ├── ActivityService.cs ├── BackupService.cs ├── CommandServiceBase.cs ├── EmailService.cs ├── FiltersCommandService.cs ├── FiltersService.cs ├── IActivityService.cs ├── IBackupService.cs ├── IEmailService.cs ├── IFiltersCommandService.cs ├── IFiltersService.cs ├── IItemsCommandService.cs ├── IItemsService.cs ├── ILabelsCommandService.cs ├── ILabelsService.cs ├── INotesCommandServices.cs ├── INotesServices.cs ├── INotificationsCommandService.cs ├── INotificationsService.cs ├── IProjectCommandService.cs ├── IProjectsService.cs ├── IReminersCommandService.cs ├── IReminersService.cs ├── ISectionService.cs ├── ISectionsCommandService.cs ├── ISharingCommandService.cs ├── ISharingService.cs ├── ITemplateService.cs ├── ITransaction.cs ├── IUploadService.cs ├── IUsersCommandService.cs ├── IUsersService.cs ├── ItemsCommandService.cs ├── ItemsService.cs ├── LabelsCommandService.cs ├── LabelsService.cs ├── NotesCommandService.cs ├── NotesService.cs ├── NotificationsCommandService.cs ├── NotificationsService.cs ├── ProjectsCommandService.cs ├── ProjectsService.cs ├── ReminersCommandService.cs ├── ReminersService.cs ├── SectionService.cs ├── SectionsCommandService.cs ├── SharingCommandService.cs ├── SharingService.cs ├── TemplateService.cs ├── Transaction.cs ├── UploadService.cs ├── UsersCommandService.cs └── UsersService.cs ├── Todoist.Net.csproj ├── TodoistClient.cs ├── TodoistClientFactory.cs └── TodoistRestClient.cs /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_size = 4 6 | indent_style = space 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | 10 | [{*.csproj,*.json,*.config}] 11 | indent_size = 2 12 | 13 | [*.cs] 14 | dotnet_separate_import_directive_groups = true 15 | dotnet_sort_system_directives_first = true 16 | -------------------------------------------------------------------------------- /.idea/.idea.Todoist.Net/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Rider ignored files 5 | /modules.xml 6 | /projectSettingsUpdater.xml 7 | /.idea.Todoist.Net.iml 8 | /contentModel.xml 9 | # Editor-based HTTP Client requests 10 | /httpRequests/ 11 | # Datasource local storage ignored files 12 | /dataSources/ 13 | /dataSources.local.xml 14 | -------------------------------------------------------------------------------- /.idea/.idea.Todoist.Net/.idea/.name: -------------------------------------------------------------------------------- 1 | Todoist.Net -------------------------------------------------------------------------------- /.idea/.idea.Todoist.Net/.idea/GitLink.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/.idea.Todoist.Net/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/.idea.Todoist.Net/.idea/indexLayout.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/.idea.Todoist.Net/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuke/parameters.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./build.schema.json", 3 | "Solution": "Todoist.Net.sln" 4 | } 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Oleg Shevchenko 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Todoist.Net 2 | [![Build status](https://ci.appveyor.com/api/projects/status/r5ylbxtpjya9ayk2?svg=true)](https://ci.appveyor.com/project/olsh/todoist-net) 3 | [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=todoist-net&metric=alert_status)](https://sonarcloud.io/dashboard?id=todoist-net) 4 | [![NuGet](https://img.shields.io/nuget/v/Todoist.Net.svg)](https://www.nuget.org/packages/Todoist.Net/) 5 | 6 | A [Todoist Sync API](https://developer.todoist.com/sync/v9/) client for .NET. 7 | ## Installation 8 | 9 | The library is available as a [Nuget package](https://www.nuget.org/packages/Todoist.Net/). 10 | ``` 11 | Install-Package Todoist.Net 12 | ``` 13 | 14 | ## Get started 15 | 16 | ### Creating Todoist client 17 | 18 | ```csharp 19 | ITodoistClient client = new TodoistClient("API token"); 20 | ``` 21 | 22 | ### Quick add 23 | 24 | Implementation of the Quick Add Task available in the official clients. 25 | ```csharp 26 | var quickAddItem = new QuickAddItem("Task title @Label1 #Project1 +ExampleUser"); 27 | var task = await client.Items.QuickAddAsync(quickAddItem); 28 | ``` 29 | 30 | ### Simple API calls 31 | ```csharp 32 | // Get all resources (labels, projects, tasks, notes etc.). 33 | var resources = await client.GetResourcesAsync(); 34 | 35 | // Get only projects and labels. 36 | var projectsAndLabels = await client.GetResourcesAsync(ResourceType.Projects, ResourceType.Labels); 37 | 38 | // Get only projects. 39 | var projectsOnly = await client.GetResourcesAsync(ResourceType.Projects); 40 | 41 | // Alternatively you can use this API to get projects. 42 | var projects = await client.Projects.GetAsync(); 43 | 44 | // Add a task with a note. 45 | var taskId = await client.Items.AddAsync(new Item("New task")); 46 | await client.Notes.AddToItemAsync(new Note("Task description"), taskId); 47 | ``` 48 | 49 | ### Transactions (Batching) 50 | Batching: reading and writing of multiple resources can be done in a single HTTP request. 51 | 52 | Add a new project, task and note in one request. 53 | ```csharp 54 | // Create a new transaction. 55 | var transaction = client.CreateTransaction(); 56 | 57 | // These requests are queued and will be executed later. 58 | var projectId = await transaction.Project.AddAsync(new Project("New project")); 59 | var taskId = await transaction.Items.AddAsync(new Item("New task", projectId)); 60 | await transaction.Notes.AddToItemAsync(new Note("Task description"), taskId); 61 | 62 | // Execute all the requests in the transaction in a single HTTP request. 63 | await transaction.CommitAsync(); 64 | 65 | ``` 66 | 67 | ### Sending null values when updating entities. 68 | When updating entities, **Todoist API** only updates properties included in the request body, using a `PATCH` request style. 69 | That's why all properties with `null` values are not included by default, to allow updating without fetching the entity first, 70 | since including `null` properties will update them to `null`. 71 | 72 | However, if you want to intentionally send a `null` value to the API, you need to use the `Unset` extension method, for example: 73 | ```csharp 74 | // This code removes a task's due date. 75 | var task = new UpdateItem("TASK_ID"); 76 | task.Unset(t => t.DueDate); 77 | 78 | await client.Items.UpdateAsync(task); 79 | ``` 80 | -------------------------------------------------------------------------------- /Todoist.Net.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26430.16 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{32567012-95F2-4535-A545-6A48FEAF0A32}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{28A18847-32D8-4A08-A1BF-BC51E3FBAB96}" 9 | ProjectSection(SolutionItems) = preProject 10 | appveyor.yml = appveyor.yml 11 | README.md = README.md 12 | .gitignore = .gitignore 13 | EndProjectSection 14 | EndProject 15 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Todoist.Net", "src\Todoist.Net\Todoist.Net.csproj", "{0D84413B-43C0-4F0E-92A6-669F2E9EA5CB}" 16 | EndProject 17 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Todoist.Net.Tests", "src\Todoist.Net.Tests\Todoist.Net.Tests.csproj", "{6F7D284C-2790-41E6-BAB5-DB0524F630D7}" 18 | EndProject 19 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{51A0DD62-8257-48DA-BE1C-5E1F3DE9A5F2}" 20 | EndProject 21 | Global 22 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 23 | Debug|Any CPU = Debug|Any CPU 24 | Release|Any CPU = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 27 | {51A0DD62-8257-48DA-BE1C-5E1F3DE9A5F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 28 | {51A0DD62-8257-48DA-BE1C-5E1F3DE9A5F2}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {0D84413B-43C0-4F0E-92A6-669F2E9EA5CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {0D84413B-43C0-4F0E-92A6-669F2E9EA5CB}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {0D84413B-43C0-4F0E-92A6-669F2E9EA5CB}.Release|Any CPU.ActiveCfg = Release|Any CPU 32 | {0D84413B-43C0-4F0E-92A6-669F2E9EA5CB}.Release|Any CPU.Build.0 = Release|Any CPU 33 | {6F7D284C-2790-41E6-BAB5-DB0524F630D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {6F7D284C-2790-41E6-BAB5-DB0524F630D7}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {6F7D284C-2790-41E6-BAB5-DB0524F630D7}.Release|Any CPU.ActiveCfg = Release|Any CPU 36 | {6F7D284C-2790-41E6-BAB5-DB0524F630D7}.Release|Any CPU.Build.0 = Release|Any CPU 37 | EndGlobalSection 38 | GlobalSection(SolutionProperties) = preSolution 39 | HideSolutionNode = FALSE 40 | EndGlobalSection 41 | GlobalSection(NestedProjects) = preSolution 42 | {0D84413B-43C0-4F0E-92A6-669F2E9EA5CB} = {32567012-95F2-4535-A545-6A48FEAF0A32} 43 | {6F7D284C-2790-41E6-BAB5-DB0524F630D7} = {32567012-95F2-4535-A545-6A48FEAF0A32} 44 | EndGlobalSection 45 | GlobalSection(ExtensibilityGlobals) = postSolution 46 | SolutionGuid = {B041B20E-5078-409B-A474-8004179914FC} 47 | EndGlobalSection 48 | EndGlobal 49 | -------------------------------------------------------------------------------- /Todoist.Net.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2022 2 | 3 | skip_branch_with_pr: true 4 | skip_tags: true 5 | 6 | install: 7 | - SET JAVA_HOME=C:\Program Files\Java\jdk17 8 | - SET PATH=%JAVA_HOME%\bin;%PATH% 9 | 10 | build_script: 11 | - cmd: >- 12 | build.cmd update-build-version sonar unit-test nuget-pack --configuration Release 13 | 14 | test: off 15 | 16 | cache: 17 | - '%USERPROFILE%\.sonar\cache' 18 | - '%USERPROFILE%\.nuget\packages -> **\*.csproj' 19 | 20 | artifacts: 21 | - path: 'artifacts\*.nupkg' 22 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | :; set -eo pipefail 2 | :; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) 3 | :; ${SCRIPT_DIR}/build.sh "$@" 4 | :; exit $? 5 | 6 | @ECHO OFF 7 | powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %* 8 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | bash --version 2>&1 | head -n 1 4 | 5 | set -eo pipefail 6 | SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) 7 | 8 | ########################################################################### 9 | # CONFIGURATION 10 | ########################################################################### 11 | 12 | BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj" 13 | TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp" 14 | 15 | DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json" 16 | DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh" 17 | DOTNET_CHANNEL="STS" 18 | 19 | export DOTNET_CLI_TELEMETRY_OPTOUT=1 20 | export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 21 | export DOTNET_MULTILEVEL_LOOKUP=0 22 | 23 | ########################################################################### 24 | # EXECUTION 25 | ########################################################################### 26 | 27 | function FirstJsonValue { 28 | perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}" 29 | } 30 | 31 | # If dotnet CLI is installed globally and it matches requested version, use for execution 32 | if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then 33 | export DOTNET_EXE="$(command -v dotnet)" 34 | else 35 | # Download install script 36 | DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh" 37 | mkdir -p "$TEMP_DIRECTORY" 38 | curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL" 39 | chmod +x "$DOTNET_INSTALL_FILE" 40 | 41 | # If global.json exists, load expected version 42 | if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then 43 | DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")") 44 | if [[ "$DOTNET_VERSION" == "" ]]; then 45 | unset DOTNET_VERSION 46 | fi 47 | fi 48 | 49 | # Install by channel or version 50 | DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix" 51 | if [[ -z ${DOTNET_VERSION+x} ]]; then 52 | "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path 53 | else 54 | "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path 55 | fi 56 | export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet" 57 | fi 58 | 59 | echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)" 60 | 61 | if [[ ! -z ${NUKE_ENTERPRISE_TOKEN+x} && "$NUKE_ENTERPRISE_TOKEN" != "" ]]; then 62 | "$DOTNET_EXE" nuget remove source "nuke-enterprise" &>/dev/null || true 63 | "$DOTNET_EXE" nuget add source "https://f.feedz.io/nuke/enterprise/nuget" --name "nuke-enterprise" --username "PAT" --password "$NUKE_ENTERPRISE_TOKEN" --store-password-in-clear-text &>/dev/null || true 64 | fi 65 | 66 | "$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet 67 | "$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@" 68 | -------------------------------------------------------------------------------- /build/.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | dotnet_style_qualification_for_field = false:warning 3 | dotnet_style_qualification_for_property = false:warning 4 | dotnet_style_qualification_for_method = false:warning 5 | dotnet_style_qualification_for_event = false:warning 6 | dotnet_style_require_accessibility_modifiers = never:warning 7 | 8 | csharp_style_expression_bodied_methods = true:silent 9 | csharp_style_expression_bodied_properties = true:warning 10 | csharp_style_expression_bodied_indexers = true:warning 11 | csharp_style_expression_bodied_accessors = true:warning 12 | 13 | dotnet_diagnostic.S3903.severity = none 14 | -------------------------------------------------------------------------------- /build/Configuration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Linq; 4 | using Nuke.Common.Tooling; 5 | 6 | [TypeConverter(typeof(TypeConverter))] 7 | public class Configuration : Enumeration 8 | { 9 | public static Configuration Debug = new Configuration { Value = nameof(Debug) }; 10 | public static Configuration Release = new Configuration { Value = nameof(Release) }; 11 | 12 | public static implicit operator string(Configuration configuration) 13 | { 14 | return configuration.Value; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /build/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /build/Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /build/_build.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | 7 | CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006 8 | .. 9 | .. 10 | 1 11 | false 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /images/todoist-net-nuget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olsh/todoist-net/3cf5408029efdacaf88622dd4caf32742d76bc8a/images/todoist-net-nuget.png -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Extensions/Constants.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Tests.Extensions; 2 | 3 | internal static class Constants 4 | { 5 | public const string TodoistApiTestCollectionName = "todoist-api-tests"; 6 | 7 | public const string TraitName = "trait"; 8 | 9 | public const string UnitTraitValue = "unit"; 10 | 11 | public const string IntegrationFreeTraitValue = "integration-free"; 12 | 13 | public const string IntegrationPremiumTraitValue = "integration-premium"; 14 | 15 | /// 16 | /// These kind of test won't work with MFA enabled. 17 | /// 18 | public const string MfaRequiredTraitValue = "mfa-required"; 19 | } 20 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Helpers/FakeLocalTimeZoneTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Todoist.Net.Tests.Extensions; 4 | 5 | using Xunit; 6 | 7 | namespace Todoist.Net.Tests.Helpers; 8 | 9 | [Trait(Constants.TraitName, Constants.UnitTraitValue)] 10 | public class FakeLocalTimeZoneTests 11 | { 12 | 13 | [Fact] 14 | public void FakeLocalTimeZone_ShouldChangeLocalTimeZoneWithinScope_AndResetItBackOutsideScope() 15 | { 16 | var offsetDifference = TimeZoneInfo.Local.BaseUtcOffset < TimeSpan.FromHours(10) ? 2 : -2; 17 | var fakeTimeZoneOffset = TimeZoneInfo.Local.BaseUtcOffset + TimeSpan.FromHours(offsetDifference); 18 | 19 | var fakeLocalTimeZone = FakeLocalTimeZone.ChangeLocalTimeZone(fakeTimeZoneOffset); 20 | using (fakeLocalTimeZone) 21 | { 22 | Assert.Equal(fakeLocalTimeZone.FakeTimeZoneInfo, TimeZoneInfo.Local); 23 | } 24 | Assert.NotEqual(fakeLocalTimeZone.FakeTimeZoneInfo, TimeZoneInfo.Local); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Models/DurationTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using Todoist.Net.Models; 4 | using Todoist.Net.Tests.Extensions; 5 | using Xunit; 6 | 7 | namespace Todoist.Net.Tests.Models 8 | { 9 | [Trait(Constants.TraitName, Constants.UnitTraitValue)] 10 | public class DurationTests 11 | { 12 | [Fact] 13 | public void AmountAssignment_InvalidValue_ThrowsException() 14 | { 15 | Duration duration; 16 | 17 | Assert.Throws(() => 18 | duration = new Duration(0, DurationUnit.Minute)); 19 | 20 | duration = new Duration(15, DurationUnit.Minute); 21 | 22 | Assert.Throws(() => 23 | duration.Amount = -5); 24 | } 25 | 26 | [Fact] 27 | public void UnitAssignment_InvalidValue_ThrowsException() 28 | { 29 | Duration duration; 30 | 31 | Assert.Throws(() => 32 | duration = new Duration(15, null)); 33 | 34 | duration = new Duration(15, DurationUnit.Minute); 35 | 36 | Assert.Throws(() => 37 | duration.Unit = null); 38 | } 39 | 40 | [Fact] 41 | public void UnitInstantiation_UnsetValue_HasNoTime() 42 | { 43 | var duration = new Duration(); 44 | 45 | Assert.Equal(duration.TimeValue, TimeSpan.Zero); 46 | 47 | duration.Amount = 15; 48 | 49 | Assert.Equal(duration.TimeValue, TimeSpan.Zero); 50 | } 51 | 52 | [Fact] 53 | public void TimeValueEvaluation_Success() 54 | { 55 | var duration = new Duration(15, DurationUnit.Minute); 56 | 57 | Assert.Equal(TimeSpan.FromMinutes(15), duration.TimeValue); 58 | 59 | duration.Amount = 3; 60 | duration.Unit = DurationUnit.Day; 61 | 62 | Assert.Equal(TimeSpan.FromDays(3), duration.TimeValue); 63 | } 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Models/StringEnumTests.cs: -------------------------------------------------------------------------------- 1 | using Todoist.Net.Models; 2 | using Todoist.Net.Tests.Extensions; 3 | 4 | using Xunit; 5 | 6 | namespace Todoist.Net.Tests.Models 7 | { 8 | [Trait(Constants.TraitName, Constants.UnitTraitValue)] 9 | public class StringEnumTests 10 | { 11 | [Fact] 12 | public void TryParse_InvalidValue_Fail() 13 | { 14 | Assert.False(StringEnum.TryParse("all1", out ResourceType result)); 15 | Assert.Null(result); 16 | } 17 | 18 | [Fact] 19 | public void TryParse_ValidValue_Success() 20 | { 21 | Assert.True(StringEnum.TryParse("all", out ResourceType result)); 22 | Assert.NotNull(result); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Services/ActivityServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | using Todoist.Net.Models; 4 | using Todoist.Net.Tests.Extensions; 5 | 6 | using Xunit; 7 | using Xunit.Abstractions; 8 | 9 | namespace Todoist.Net.Tests.Services 10 | { 11 | [Collection(Constants.TodoistApiTestCollectionName)] 12 | [Trait(Constants.TraitName, Constants.IntegrationPremiumTraitValue)] 13 | public class ActivityServiceTests 14 | { 15 | private readonly ITestOutputHelper _outputHelper; 16 | 17 | public ActivityServiceTests(ITestOutputHelper outputHelper) 18 | { 19 | _outputHelper = outputHelper; 20 | } 21 | 22 | [Fact] 23 | public async Task TestActivityLogIsNotEmpty() 24 | { 25 | var client = TodoistClientFactory.Create(_outputHelper); 26 | 27 | const int LogEntriesLimit = 50; 28 | var logFilter = new LogFilter { Limit = LogEntriesLimit }; 29 | var logEntries = await client.Activity.GetAsync(logFilter); 30 | 31 | Assert.NotEmpty(logEntries.Events); 32 | } 33 | 34 | [Fact] 35 | public async Task GetActivityWithEventObjectFilter_HasEntries() 36 | { 37 | var client = TodoistClientFactory.Create(_outputHelper); 38 | 39 | var logFilter = new LogFilter(); 40 | logFilter.ObjectEventTypes.Add(new ObjectEventTypes { ObjectType = "project" }); 41 | 42 | var logEntries = await client.Activity.GetAsync(logFilter); 43 | 44 | Assert.NotEmpty(logEntries.Events); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Services/BackupServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Threading.Tasks; 3 | 4 | using Todoist.Net.Tests.Extensions; 5 | 6 | using Xunit; 7 | using Xunit.Abstractions; 8 | 9 | namespace Todoist.Net.Tests.Services 10 | { 11 | [Collection(Constants.TodoistApiTestCollectionName)] 12 | [Trait(Constants.TraitName, Constants.MfaRequiredTraitValue)] 13 | public class BackupServiceTests 14 | { 15 | private readonly ITestOutputHelper _outputHelper; 16 | 17 | public BackupServiceTests(ITestOutputHelper outputHelper) 18 | { 19 | _outputHelper = outputHelper; 20 | } 21 | 22 | [Fact] 23 | public async Task GetBackups_Success() 24 | { 25 | var client = TodoistClientFactory.Create(_outputHelper); 26 | 27 | var backups = await client.Backups.GetAsync(); 28 | 29 | Assert.True(backups.Any()); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Services/EmailServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | 4 | using Todoist.Net.Models; 5 | using Todoist.Net.Tests.Extensions; 6 | 7 | using Xunit; 8 | using Xunit.Abstractions; 9 | 10 | namespace Todoist.Net.Tests.Services 11 | { 12 | [Collection(Constants.TodoistApiTestCollectionName)] 13 | public class EmailServiceTests 14 | { 15 | private readonly ITestOutputHelper _outputHelper; 16 | 17 | public EmailServiceTests(ITestOutputHelper outputHelper) 18 | { 19 | _outputHelper = outputHelper; 20 | } 21 | 22 | [Fact] 23 | [Trait(Constants.TraitName, Constants.IntegrationPremiumTraitValue)] 24 | public async Task GetOrCreateAsyncDisable_NewProject_Success() 25 | { 26 | var client = TodoistClientFactory.Create(_outputHelper); 27 | 28 | var project = new Project(Guid.NewGuid().ToString()); 29 | var projectId = await client.Projects.AddAsync(project); 30 | try 31 | { 32 | var emailInfo = await client.Emails.GetOrCreateAsync(ObjectType.Project, projectId); 33 | try 34 | { 35 | Assert.NotNull(emailInfo); 36 | Assert.NotNull(emailInfo.Email); 37 | } 38 | finally 39 | { 40 | await client.Emails.DisableAsync(ObjectType.Project, projectId); 41 | } 42 | } 43 | finally 44 | { 45 | await client.Projects.DeleteAsync(projectId); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Services/FiltersServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | using Todoist.Net.Tests.Extensions; 7 | 8 | using Xunit; 9 | using Xunit.Abstractions; 10 | 11 | namespace Todoist.Net.Tests.Services 12 | { 13 | [Collection(Constants.TodoistApiTestCollectionName)] 14 | [Trait(Constants.TraitName, Constants.IntegrationPremiumTraitValue)] 15 | public class FiltersServiceTests 16 | { 17 | private readonly ITestOutputHelper _outputHelper; 18 | 19 | public FiltersServiceTests(ITestOutputHelper outputHelper) 20 | { 21 | _outputHelper = outputHelper; 22 | } 23 | 24 | [Fact] 25 | public async Task GetFilterInfo_Success() 26 | { 27 | var client = TodoistClientFactory.Create(_outputHelper); 28 | 29 | var filters = (await client.Filters.GetAsync()).ToList(); 30 | 31 | Assert.True(filters.Count > 0); 32 | 33 | var result = await client.Filters.GetAsync(filters.First().Id); 34 | 35 | Assert.NotNull(result); 36 | } 37 | 38 | [Fact] 39 | public async Task CreateUpdateDelete_Success() 40 | { 41 | var client = TodoistClientFactory.Create(_outputHelper); 42 | 43 | var filter = new Filter(Guid.NewGuid().ToString(), "today"); 44 | await client.Filters.AddAsync(filter); 45 | try 46 | { 47 | var filters = await client.Filters.GetAsync(); 48 | 49 | Assert.Contains(filters, f => f.Name == filter.Name); 50 | 51 | filter.Query = "test"; 52 | await client.Filters.UpdateAsync(filter); 53 | var filterOrder = 2; 54 | await client.Filters.UpdateOrderAsync(new OrderEntry(filter.Id, filterOrder)); 55 | 56 | var filterInfo = await client.Filters.GetAsync(filter.Id); 57 | Assert.Equal(filter.Query, filterInfo.Filter.Query); 58 | Assert.Equal(filterOrder, filterInfo.Filter.ItemOrder); 59 | } 60 | finally 61 | { 62 | await client.Filters.DeleteAsync(filter.Id); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Services/LabelsServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | using Todoist.Net.Models; 4 | using Todoist.Net.Tests.Extensions; 5 | 6 | using Xunit; 7 | using Xunit.Abstractions; 8 | 9 | namespace Todoist.Net.Tests.Services 10 | { 11 | [Collection(Constants.TodoistApiTestCollectionName)] 12 | public class LabelsServiceTests 13 | { 14 | private readonly ITestOutputHelper _outputHelper; 15 | 16 | public LabelsServiceTests(ITestOutputHelper outputHelper) 17 | { 18 | _outputHelper = outputHelper; 19 | } 20 | 21 | [Fact] 22 | [Trait(Constants.TraitName, Constants.IntegrationFreeTraitValue)] 23 | public async Task CreateUpdateOrderDelete_Success() 24 | { 25 | var client = TodoistClientFactory.Create(_outputHelper); 26 | 27 | var label = new Label("Test label"); 28 | try 29 | { 30 | await client.Labels.AddAsync(label); 31 | await client.Labels.UpdateOrderAsync(new OrderEntry(label.Id, 1)); 32 | } 33 | finally 34 | { 35 | await client.Labels.DeleteAsync(label.Id); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Services/NotificationsServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Threading.Tasks; 3 | 4 | using Todoist.Net.Tests.Extensions; 5 | 6 | using Xunit; 7 | using Xunit.Abstractions; 8 | 9 | namespace Todoist.Net.Tests.Services 10 | { 11 | [Collection(Constants.TodoistApiTestCollectionName)] 12 | [Trait(Constants.TraitName, Constants.IntegrationFreeTraitValue)] 13 | public class NotificationsServiceTests 14 | { 15 | private readonly ITestOutputHelper _outputHelper; 16 | 17 | public NotificationsServiceTests(ITestOutputHelper outputHelper) 18 | { 19 | _outputHelper = outputHelper; 20 | } 21 | 22 | [Fact] 23 | public async Task GetNotification_Success() 24 | { 25 | var client = TodoistClientFactory.Create(_outputHelper); 26 | 27 | var notifications = await client.Notifications.GetAsync(); 28 | 29 | Assert.True(notifications.Any()); 30 | } 31 | 32 | [Fact] 33 | public async Task MarkAllAsRead_Success() 34 | { 35 | var client = TodoistClientFactory.Create(_outputHelper); 36 | 37 | await client.Notifications.MarkAllReadAsync(); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Services/RemindersServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | using Todoist.Net.Tests.Extensions; 7 | 8 | using Xunit; 9 | using Xunit.Abstractions; 10 | 11 | namespace Todoist.Net.Tests.Services 12 | { 13 | [Collection(Constants.TodoistApiTestCollectionName)] 14 | [Trait(Constants.TraitName, Constants.IntegrationPremiumTraitValue)] 15 | public class RemindersServiceTests 16 | { 17 | private readonly ITestOutputHelper _outputHelper; 18 | 19 | public RemindersServiceTests(ITestOutputHelper outputHelper) 20 | { 21 | _outputHelper = outputHelper; 22 | } 23 | 24 | [Fact] 25 | public async Task CreateDelete_Success() 26 | { 27 | var client = TodoistClientFactory.Create(_outputHelper); 28 | 29 | var transaction = client.CreateTransaction(); 30 | 31 | var itemId = await transaction.Items.AddAsync(new AddItem("Temp")); 32 | var reminder = new Reminder(itemId) { DueDate = DueDate.CreateFloating(DateTime.UtcNow.AddDays(1)) }; 33 | await transaction.Reminders.AddAsync(reminder); 34 | await transaction.CommitAsync(); 35 | try 36 | { 37 | var reminders = await client.Reminders.GetAsync(); 38 | 39 | Assert.Contains(reminders, r => r.Id == reminder.Id); 40 | } 41 | finally 42 | { 43 | await client.Reminders.DeleteAsync(reminder.Id); 44 | await client.Items.DeleteAsync(itemId); 45 | } 46 | } 47 | 48 | [Fact] 49 | public async Task AddRelativeReminder_Success() 50 | { 51 | var client = TodoistClientFactory.Create(_outputHelper); 52 | 53 | var item = new AddItem("Test") 54 | { 55 | DueDate = DueDate.CreateFloating(DateTime.UtcNow.AddDays(1)) 56 | }; 57 | 58 | var taskId = await client.Items.AddAsync(item); 59 | try 60 | { 61 | var user = await client.Users.GetCurrentAsync(); 62 | var reminder = new Reminder(taskId) 63 | { 64 | MinuteOffset = 60, 65 | NotifyUid = user.Id 66 | }; 67 | 68 | var reminderId = await client.Reminders.AddAsync(reminder); 69 | 70 | Assert.NotNull(reminderId.PersistentId); 71 | } 72 | finally 73 | { 74 | await client.Items.DeleteAsync(item.Id); 75 | } 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Services/SectionServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | using Todoist.Net.Models; 4 | using Todoist.Net.Tests.Extensions; 5 | 6 | using Xunit; 7 | using Xunit.Abstractions; 8 | 9 | namespace Todoist.Net.Tests.Services 10 | { 11 | [Collection(Constants.TodoistApiTestCollectionName)] 12 | [Trait(Constants.TraitName, Constants.IntegrationFreeTraitValue)] 13 | public class SectionServiceTests 14 | { 15 | private readonly ITestOutputHelper _outputHelper; 16 | 17 | public SectionServiceTests(ITestOutputHelper outputHelper) 18 | { 19 | _outputHelper = outputHelper; 20 | } 21 | 22 | [Fact] 23 | public async Task CreateArchiveUnarchiveDelete_Success() 24 | { 25 | var client = TodoistClientFactory.Create(_outputHelper); 26 | 27 | var projectId = await client.Projects.AddAsync(new Project("test")); 28 | try 29 | { 30 | var sectionId = await client.Sections.AddAsync(new Section("test", projectId)); 31 | await client.Sections.ArchiveAsync(sectionId); 32 | await client.Sections.UnarchiveAsync(sectionId); 33 | 34 | var projectTwoId = await client.Projects.AddAsync(new Project("test2")); 35 | try 36 | { 37 | var sectionMoveArgument = new SectionMoveArgument(sectionId, projectTwoId); 38 | await client.Sections.MoveAsync(sectionMoveArgument); 39 | 40 | await client.Sections.DeleteAsync(sectionId); 41 | } 42 | finally 43 | { 44 | await client.Projects.DeleteAsync(projectTwoId); 45 | } 46 | } 47 | finally 48 | { 49 | await client.Projects.DeleteAsync(projectId); 50 | } 51 | } 52 | 53 | [Fact] 54 | public async Task Reorder_Success() 55 | { 56 | var client = TodoistClientFactory.Create(_outputHelper); 57 | 58 | var projectId = await client.Projects.AddAsync(new Project("test")); 59 | try 60 | { 61 | var firstId = await client.Sections.AddAsync(new Section("test", projectId)); 62 | var secondId = await client.Sections.AddAsync(new Section("test2", projectId)); 63 | 64 | await client.Sections.ReorderAsync(new SectionOrderEntry(secondId, 1), new SectionOrderEntry(firstId, 2)); 65 | } 66 | finally 67 | { 68 | await client.Projects.DeleteAsync(projectId); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Services/SharingServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | using Todoist.Net.Tests.Extensions; 7 | 8 | using Xunit; 9 | using Xunit.Abstractions; 10 | 11 | namespace Todoist.Net.Tests.Services 12 | { 13 | [Collection(Constants.TodoistApiTestCollectionName)] 14 | [Trait(Constants.TraitName, Constants.IntegrationPremiumTraitValue)] 15 | public class SharingServiceTests 16 | { 17 | private readonly ITestOutputHelper _outputHelper; 18 | 19 | public SharingServiceTests(ITestOutputHelper outputHelper) 20 | { 21 | _outputHelper = outputHelper; 22 | } 23 | 24 | [Fact] 25 | public async Task ShareProjectGetCollaboratorAndUnshare_NewUser_Success() 26 | { 27 | var client = TodoistClientFactory.Create(_outputHelper); 28 | 29 | var projectId = await client.Projects.AddAsync(new Project(Guid.NewGuid().ToString())); 30 | try 31 | { 32 | var email = "you@example.com"; 33 | await client.Sharing.ShareProjectAsync(projectId, email); 34 | try 35 | { 36 | var collaborators = await client.Sharing.GetCollaboratorsAsync(); 37 | Assert.Contains(collaborators, c => c.Email == email); 38 | 39 | var collaboratorId = collaborators.First(c => c.Email == email).Id; 40 | 41 | var collaboratorStates = await client.Sharing.GetCollaboratorStatesAsync(); 42 | Assert.Contains(collaboratorStates, c => c.UserId == collaboratorId && c.ProjectId == projectId); 43 | 44 | var collaboratorStatus = collaboratorStates.First(c => c.UserId == collaboratorId && c.ProjectId == projectId).State; 45 | 46 | Assert.Equal(CollaboratorStatus.Invited, collaboratorStatus); 47 | } 48 | finally 49 | { 50 | await client.Sharing.DeleteCollaboratorAsync(projectId, email); 51 | } 52 | } 53 | finally 54 | { 55 | await client.Projects.DeleteAsync(projectId); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Services/TemplateServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | using Todoist.Net.Tests.Extensions; 8 | 9 | using Xunit; 10 | using Xunit.Abstractions; 11 | 12 | namespace Todoist.Net.Tests.Services 13 | { 14 | [Collection(Constants.TodoistApiTestCollectionName)] 15 | [Trait(Constants.TraitName, Constants.IntegrationPremiumTraitValue)] 16 | public class TemplateServiceTests 17 | { 18 | private readonly ITestOutputHelper _outputHelper; 19 | 20 | public TemplateServiceTests(ITestOutputHelper outputHelper) 21 | { 22 | _outputHelper = outputHelper; 23 | } 24 | 25 | [Fact] 26 | public async Task ExportAndImportTemplate_Success() 27 | { 28 | var client = TodoistClientFactory.Create(_outputHelper); 29 | 30 | var firstProject = (await client.Projects.GetAsync()).First(); 31 | 32 | var template = await client.Templates.ExportAsFileAsync(firstProject.Id); 33 | 34 | var tempProject = new Project(Guid.NewGuid().ToString()); 35 | await client.Projects.AddAsync(tempProject); 36 | try 37 | { 38 | await client.Templates.ImportIntoProjectAsync(tempProject.Id, Encoding.UTF8.GetBytes(template)); 39 | } 40 | finally 41 | { 42 | await client.Projects.DeleteAsync(tempProject.Id); 43 | } 44 | } 45 | 46 | [Fact] 47 | public async Task ExportAsShareableUrl_Success() 48 | { 49 | var client = TodoistClientFactory.Create(_outputHelper); 50 | 51 | var firstProject = (await client.Projects.GetAsync()).First(); 52 | var template = await client.Templates.ExportAsShareableUrlAsync(firstProject.Id); 53 | 54 | Assert.False(string.IsNullOrEmpty(template.FileUrl)); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Services/UploadServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Tests.Extensions; 7 | 8 | using Xunit; 9 | using Xunit.Abstractions; 10 | 11 | namespace Todoist.Net.Tests.Services 12 | { 13 | [Collection(Constants.TodoistApiTestCollectionName)] 14 | public class UploadServiceTests 15 | { 16 | private readonly ITestOutputHelper _outputHelper; 17 | 18 | public UploadServiceTests(ITestOutputHelper outputHelper) 19 | { 20 | _outputHelper = outputHelper; 21 | } 22 | 23 | [Fact] 24 | [Trait(Constants.TraitName, Constants.IntegrationFreeTraitValue)] 25 | public async Task CreateGetDeleteAsync_Success() 26 | { 27 | var client = TodoistClientFactory.Create(_outputHelper); 28 | 29 | var fileName = $"{Guid.NewGuid()}.txt"; 30 | var upload = await client.Uploads.UploadAsync(fileName, Encoding.UTF8.GetBytes("hello")); 31 | try 32 | { 33 | var allUploads = await client.Uploads.GetAsync(); 34 | Assert.Contains(allUploads, u => u.FileUrl == upload.FileUrl); 35 | } 36 | finally 37 | { 38 | await client.Uploads.DeleteAsync(upload.FileUrl); 39 | } 40 | var otherUploads = await client.Uploads.GetAsync(); 41 | Assert.DoesNotContain(otherUploads, u => u.FileUrl == upload.FileUrl); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Services/UsersServiceTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | using Todoist.Net.Tests.Extensions; 4 | 5 | using Xunit; 6 | using Xunit.Abstractions; 7 | 8 | namespace Todoist.Net.Tests.Services 9 | { 10 | [Collection(Constants.TodoistApiTestCollectionName)] 11 | public class UsersServiceTests 12 | { 13 | private readonly ITestOutputHelper _outputHelper; 14 | 15 | public UsersServiceTests(ITestOutputHelper outputHelper) 16 | { 17 | _outputHelper = outputHelper; 18 | } 19 | 20 | [Fact] 21 | [Trait(Constants.TraitName, Constants.IntegrationFreeTraitValue)] 22 | public async Task GetCurrentAsync_Success() 23 | { 24 | var client = TodoistClientFactory.Create(_outputHelper); 25 | 26 | var user = await client.Users.GetCurrentAsync(); 27 | 28 | Assert.NotNull(user); 29 | Assert.NotNull(user.Id); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Settings/SettingsProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Todoist.Net.Tests.Settings 4 | { 5 | public static class SettingsProvider 6 | { 7 | public static string GetToken() 8 | { 9 | return Environment.GetEnvironmentVariable("todoist:token"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/Todoist.Net.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net8.0 4 | 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | all 13 | runtime; build; native; contentfiles; analyzers 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/TodoistClientFactory.cs: -------------------------------------------------------------------------------- 1 | using Todoist.Net.Tests.Settings; 2 | 3 | using Xunit.Abstractions; 4 | 5 | namespace Todoist.Net.Tests 6 | { 7 | public static class TodoistClientFactory 8 | { 9 | public static ITodoistClient Create(ITestOutputHelper outputHelper) 10 | { 11 | var token = SettingsProvider.GetToken(); 12 | return new TodoistClient(new RateLimitAwareRestClient(token, outputHelper)); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Todoist.Net.Tests/TodoistClientTests.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | using Todoist.Net.Tests.Extensions; 4 | 5 | using Xunit; 6 | using Xunit.Abstractions; 7 | 8 | namespace Todoist.Net.Tests 9 | { 10 | [Collection(Constants.TodoistApiTestCollectionName)] 11 | [Trait(Constants.TraitName, Constants.IntegrationFreeTraitValue)] 12 | public class TodoistClientTests 13 | { 14 | private readonly ITestOutputHelper _outputHelper; 15 | 16 | public TodoistClientTests(ITestOutputHelper outputHelper) 17 | { 18 | _outputHelper = outputHelper; 19 | } 20 | 21 | [Fact] 22 | public async Task GetAllResources_Success() 23 | { 24 | var client = TodoistClientFactory.Create(_outputHelper); 25 | 26 | var resources = await client.GetResourcesAsync(); 27 | 28 | Assert.NotNull(resources); 29 | } 30 | 31 | [Fact] 32 | public async Task GetAllResourcesWithSyncToken_Success() 33 | { 34 | var client = TodoistClientFactory.Create(_outputHelper); 35 | 36 | var resources = await client.GetResourcesAsync(); 37 | resources = await client.GetResourcesAsync(resources.SyncToken); 38 | 39 | Assert.NotNull(resources); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Todoist.Net/Extensions/DateTimeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Todoist.Net.Extensions 4 | { 5 | internal static class DateTimeExtensions 6 | { 7 | public static string ToFilterParameter(this DateTime dateTime) 8 | { 9 | return dateTime.ToString("s"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Todoist.Net/Extensions/TodoistServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | #if NETSTANDARD2_0 2 | 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace Todoist.Net.Extensions 6 | { 7 | /// 8 | /// Extension methods for setting up todoist client services in an . 9 | /// 10 | public static class TodoistServiceCollectionExtensions 11 | { 12 | /// 13 | /// Adds todoist client services to the specified . 14 | /// 15 | /// The to add services to. 16 | /// The so that additional calls can be chained. 17 | public static IServiceCollection AddTodoistClient(this IServiceCollection services) 18 | { 19 | services.AddHttpClient(); 20 | services.AddSingleton(); 21 | 22 | return services; 23 | } 24 | } 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /src/Todoist.Net/Extensions/UnsettablePropertiesExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | using System.Reflection; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net 8 | { 9 | /// 10 | /// Provides extension methods to the interface. 11 | /// 12 | public static class UnsettablePropertiesExtensions 13 | { 14 | /// 15 | /// Specifies that the targeted property should be included in the outgoing requests with no value () 16 | /// 17 | /// 18 | /// This method can be used as follows: 19 | /// 20 | /// item.Unset(x => x.DueDate); 21 | /// 22 | /// 23 | /// The type of the entity. 24 | /// The type of the targeted property. 25 | /// The entity to unset its property. 26 | /// A lambda expression representing the property to be unset (x => x.MyProperty). 27 | /// is not a nullable property. 28 | /// is not a lambda for property. 29 | public static void Unset(this T entity, Expression> propertyExpression) where T : IUnsettableProperties 30 | { 31 | // We use runtime check instead of generic constraints to allow both reference and Nullable types. 32 | if (default(TProp) != null) 33 | { 34 | throw new InvalidOperationException("Property type is required to be a nullable type."); 35 | } 36 | var propertyInfo = (propertyExpression.Body as MemberExpression)?.Member as PropertyInfo 37 | ?? throw new ArgumentException($"Invalid property expression: ({propertyExpression})", nameof(propertyExpression)); 38 | 39 | // If the property doesn't have an internal setter. 40 | if (!propertyInfo.SetMethod.IsAssembly) 41 | { 42 | // Make sure that the property is null. 43 | propertyInfo.SetValue(entity, null); 44 | } 45 | 46 | entity.UnsetProperties.Add(propertyInfo); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Todoist.Net/ITodoistClientFactory.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net 2 | { 3 | /// 4 | /// A factory abstraction for a component that can create instances with user tokens. 5 | /// 6 | public interface ITodoistClientFactory 7 | { 8 | /// 9 | /// Creates a new instance of with the specified user token."/> 10 | /// 11 | /// The user token to use. 12 | /// The created 13 | TodoistClient CreateClient(string token); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Todoist.Net/ITodoistRestClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace Todoist.Net 8 | { 9 | /// 10 | /// Represents a REST client. 11 | /// 12 | public interface ITodoistRestClient : IDisposable 13 | { 14 | /// 15 | /// Sends a GET request, and handles response asynchronously. 16 | /// 17 | /// The resource. 18 | /// The parameters. 19 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 20 | /// Returns .The task object representing the asynchronous operation. 21 | /// Value cannot be null or empty - resource 22 | /// is 23 | Task GetAsync(string resource, IEnumerable> parameters, CancellationToken cancellationToken = default); 24 | 25 | /// 26 | /// Sends a POST request, and handles response asynchronously. 27 | /// 28 | /// The resource. 29 | /// The parameters. 30 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 31 | /// Returns .The task object representing the asynchronous operation. 32 | /// Value cannot be null or empty - resource 33 | /// is 34 | Task PostAsync(string resource, IEnumerable> parameters, CancellationToken cancellationToken = default); 35 | 36 | /// 37 | /// Sends a POST request with form data, and handles response asynchronously. 38 | /// 39 | /// The resource. 40 | /// The parameters. 41 | /// The files. 42 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 43 | /// The response. 44 | Task PostFormAsync( 45 | string resource, 46 | IEnumerable> parameters, 47 | IEnumerable files, 48 | CancellationToken cancellationToken = default); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/Activity.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents activity. 7 | /// 8 | public class Activity 9 | { 10 | [JsonConstructor] 11 | internal Activity() 12 | { 13 | } 14 | 15 | /// 16 | /// Gets the count. 17 | /// 18 | /// 19 | /// The count. 20 | /// 21 | [JsonPropertyName("count")] 22 | public long Count { get; internal set; } 23 | 24 | /// 25 | /// Gets the events. 26 | /// 27 | /// 28 | /// The events. 29 | /// 30 | [JsonPropertyName("events")] 31 | public LogEntry[] Events { get; internal set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ActivityLog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents a Todoist log entry. 8 | /// 9 | public class LogEntry 10 | { 11 | /// 12 | /// Gets the event date. 13 | /// 14 | /// The event date. 15 | [JsonPropertyName("event_date")] 16 | public DateTime EventDate { get; internal set; } 17 | 18 | /// 19 | /// Gets the type of the event. 20 | /// 21 | /// The type of the event. 22 | [JsonPropertyName("event_type")] 23 | public string EventType { get; internal set; } 24 | 25 | /// 26 | /// Gets the extra data. 27 | /// 28 | /// The extra data. 29 | [JsonPropertyName("extra_data")] 30 | public LogExtraData ExtraData { get; internal set; } 31 | 32 | /// 33 | /// Gets the identifier. 34 | /// 35 | /// The identifier. 36 | [JsonPropertyName("id")] 37 | public long Id { get; internal set; } 38 | 39 | /// 40 | /// Gets the initiator identifier. 41 | /// 42 | /// The initiator identifier. 43 | [JsonPropertyName("initiator_id")] 44 | public long? InitiatorId { get; internal set; } 45 | 46 | /// 47 | /// Gets the object identifier. 48 | /// 49 | /// The object identifier. 50 | [JsonPropertyName("object_id")] 51 | public long ObjectId { get; internal set; } 52 | 53 | /// 54 | /// Gets the type of the object. 55 | /// 56 | /// The type of the object. 57 | [JsonPropertyName("object_type")] 58 | public string ObjectType { get; internal set; } 59 | 60 | /// 61 | /// Gets the parent item identifier. 62 | /// 63 | /// The parent item identifier. 64 | [JsonPropertyName("parent_item_id")] 65 | public long? ParentItemId { get; internal set; } 66 | 67 | /// 68 | /// Gets the parent project identifier. 69 | /// 70 | /// The parent project identifier. 71 | [JsonPropertyName("parent_project_id")] 72 | public long? ParentProjectId { get; internal set; } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/Backup.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents a Todoist backup. 7 | /// 8 | public class Backup 9 | { 10 | /// 11 | /// Gets the URL. 12 | /// 13 | /// The URL. 14 | [JsonPropertyName("url")] 15 | public string Url { get; internal set; } 16 | 17 | /// 18 | /// Gets the version. 19 | /// 20 | /// The version. 21 | [JsonPropertyName("version")] 22 | public string Version { get; internal set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/BaseEntity.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents a base entity. 7 | /// 8 | public class BaseEntity : ICommandArgument 9 | { 10 | internal BaseEntity(ComplexId id) 11 | { 12 | Id = id; 13 | } 14 | 15 | [JsonConstructor] 16 | internal BaseEntity() 17 | { 18 | } 19 | 20 | /// 21 | /// Gets or sets the identifier. 22 | /// 23 | /// 24 | /// The identifier. 25 | /// 26 | [JsonPropertyName("id")] 27 | [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] 28 | public ComplexId Id { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/BaseInvitation.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents a base invitation. 7 | /// 8 | internal class BaseInvitation : ICommandArgument 9 | { 10 | [JsonConstructor] 11 | internal BaseInvitation(long id) 12 | { 13 | Id = id; 14 | } 15 | 16 | /// 17 | /// Gets or sets the identifier. 18 | /// 19 | /// 20 | /// The identifier. 21 | /// 22 | [JsonPropertyName("invitation_id")] 23 | public long Id { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/BaseUnsetEntity.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace Todoist.Net.Models 6 | { 7 | /// 8 | /// Represents a base entity that implements . 9 | /// 10 | /// 11 | public abstract class BaseUnsetEntity : BaseEntity, IUnsettableProperties 12 | { 13 | HashSet IUnsettableProperties.UnsetProperties { get; } = new HashSet(); 14 | 15 | private protected BaseUnsetEntity(ComplexId id) 16 | : base(id) 17 | { 18 | } 19 | 20 | [JsonConstructor] 21 | private protected BaseUnsetEntity() 22 | { 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/Collaborator.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents a Todoist collaborator. 7 | /// 8 | public class Collaborator 9 | { 10 | [JsonConstructor] 11 | internal Collaborator() 12 | { 13 | } 14 | 15 | /// 16 | /// Gets the collaborator id. 17 | /// 18 | /// The collaborator id. 19 | [JsonPropertyName("id")] 20 | public string Id { get; internal set; } 21 | 22 | /// 23 | /// Gets the email. 24 | /// 25 | /// The email. 26 | [JsonPropertyName("email")] 27 | public string Email { get; internal set; } 28 | 29 | /// 30 | /// Gets the full name. 31 | /// 32 | /// The full name. 33 | [JsonPropertyName("full_name")] 34 | public string FullName { get; internal set; } 35 | 36 | /// 37 | /// Gets the time zone. 38 | /// 39 | /// The time zone. 40 | [JsonPropertyName("timezone")] 41 | public string TimeZone { get; internal set; } 42 | 43 | /// 44 | /// Gets the image id. 45 | /// 46 | /// The image id. 47 | [JsonPropertyName("image_id")] 48 | public string ImageId { get; internal set; } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/CollaboratorState.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents a Todoist collaborator state. 7 | /// 8 | public class CollaboratorState 9 | { 10 | [JsonConstructor] 11 | internal CollaboratorState() 12 | { 13 | } 14 | 15 | /// 16 | /// Gets the user id of the collaborator. 17 | /// 18 | /// The user id. 19 | [JsonPropertyName("user_id")] 20 | public string UserId { get; internal set; } 21 | 22 | /// 23 | /// Gets the shared project id. 24 | /// 25 | /// The project id. 26 | [JsonPropertyName("project_id")] 27 | public string ProjectId { get; internal set; } 28 | 29 | /// 30 | /// Gets the collaborator status. 31 | /// 32 | /// The status. 33 | [JsonPropertyName("state")] 34 | public CollaboratorStatus State { get; internal set; } 35 | 36 | /// 37 | /// Gets a value indicating whether this collaborator is deleted. 38 | /// 39 | /// true if this collaborator is deleted; otherwise, false. 40 | [JsonPropertyName("is_deleted")] 41 | public bool IsDeleted { get; internal set; } 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/CollaboratorStatus.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Represents the status of a collaborator. 5 | /// 6 | /// 7 | public class CollaboratorStatus : StringEnum 8 | { 9 | /// 10 | /// Initializes a new instance of the class. 11 | /// 12 | /// The value. 13 | private CollaboratorStatus(string value) 14 | : base(value) 15 | { 16 | } 17 | 18 | /// 19 | /// Gets the active status. 20 | /// 21 | /// The active status. 22 | public static CollaboratorStatus Active { get; } = new CollaboratorStatus("active"); 23 | 24 | /// 25 | /// Gets the invited status. 26 | /// 27 | /// The invited status. 28 | public static CollaboratorStatus Invited { get; } = new CollaboratorStatus("invited"); 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/Command.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | internal class Command 7 | { 8 | [JsonConstructor] 9 | internal Command(CommandType commandType, ICommandArgument argument, Guid? tempId) 10 | { 11 | CommandType = commandType; 12 | Argument = argument; 13 | TempId = tempId; 14 | Uid = Guid.NewGuid(); 15 | } 16 | 17 | internal Command(CommandType commandType, ICommandArgument argument) 18 | 19 | // ReSharper disable once IntroduceOptionalParameters.Global 20 | : this(commandType, argument, null) 21 | { 22 | } 23 | 24 | [JsonPropertyName("args")] 25 | public ICommandArgument Argument { get; } 26 | 27 | [JsonPropertyName("type")] 28 | public CommandType CommandType { get; } 29 | 30 | [JsonPropertyName("temp_id")] 31 | public Guid? TempId { get; } 32 | 33 | [JsonPropertyName("uuid")] 34 | public Guid Uid { get; } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/CommandError.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents a command execution error returned by the Todoist API. 7 | /// 8 | public class CommandError 9 | { 10 | /// 11 | /// Gets or sets the error code. 12 | /// 13 | [JsonPropertyName("error_code")] 14 | public int ErrorCode { get; set; } 15 | 16 | /// 17 | /// Gets or sets the error summary. 18 | /// 19 | [JsonPropertyName("error")] 20 | public string Error { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/CommandResult.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | internal class CommandResult 4 | { 5 | internal const string SuccessValue = "ok"; 6 | 7 | 8 | private CommandResult() 9 | { } 10 | 11 | public CommandError CommandError { get; private set; } 12 | 13 | 14 | public bool IsSuccess => CommandError == null; 15 | 16 | public static CommandResult Success { get; } = new CommandResult(); 17 | public static CommandResult Fail(CommandError error) => new CommandResult 18 | { 19 | CommandError = error 20 | }; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/CompleteItemArgument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents a complete item argument. 8 | /// 9 | /// 10 | public class CompleteItemArgument : ICommandArgument 11 | { 12 | /// 13 | /// Initializes a new instance of the class. 14 | /// 15 | /// The identifier. 16 | /// 17 | /// The date completed. If not set, the server will set the value to the current timestamp. 18 | /// 19 | public CompleteItemArgument(ComplexId id, DateTime? completedAt = null) 20 | { 21 | Id = id; 22 | CompletedAt = completedAt; 23 | } 24 | 25 | /// 26 | /// Gets the date completed. 27 | /// 28 | /// 29 | /// The date completed. 30 | /// 31 | [JsonPropertyName("completed_at")] 32 | public DateTime? CompletedAt { get; } 33 | 34 | /// 35 | /// Gets the identifier. 36 | /// 37 | /// 38 | /// The identifier. 39 | /// 40 | [JsonPropertyName("id")] 41 | public ComplexId Id { get; } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/CompleteRecurringItemArgument.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents complete item argument. 7 | /// 8 | /// 9 | public class CompleteRecurringItemArgument : ICommandArgument 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The identifier. 15 | /// The due date. 16 | public CompleteRecurringItemArgument(ComplexId id, DueDate dueDate = null) 17 | { 18 | DueDate = dueDate; 19 | Id = id; 20 | } 21 | 22 | /// 23 | /// Gets the due date. 24 | /// 25 | /// 26 | /// The due date. 27 | /// 28 | [JsonPropertyName("due")] 29 | public DueDate DueDate { get; } 30 | 31 | /// 32 | /// Gets the identifier. 33 | /// 34 | /// 35 | /// The identifier. 36 | /// 37 | [JsonPropertyName("id")] 38 | public ComplexId Id { get; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/CompletedItemsInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents information about completed tasks. 8 | /// 9 | public class CompletedItemsInfo 10 | { 11 | /// 12 | /// Gets the items. 13 | /// 14 | /// 15 | /// The items. 16 | /// 17 | [JsonPropertyName("items")] 18 | public IReadOnlyCollection Items { get; internal set; } 19 | 20 | /// 21 | /// Gets the projects. 22 | /// 23 | /// 24 | /// The projects. 25 | /// 26 | [JsonPropertyName("projects")] 27 | public IReadOnlyDictionary Projects { get; internal set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/DateFormat.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Represents date formats. 5 | /// 6 | public enum DateFormat : byte 7 | { 8 | /// 9 | /// DD-MM-YYYY date format. 10 | /// 11 | DdMmYyyy = 0, 12 | 13 | /// 14 | /// MM-DD-YYYY date format. 15 | /// 16 | MmDdYyyy = 1 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/DayOfWeek.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Represents the days of the week. 5 | /// 6 | public enum DayOfWeek : byte 7 | { 8 | /// 9 | /// The monday 10 | /// 11 | Monday = 1, 12 | 13 | /// 14 | /// The tuesday 15 | /// 16 | Tuesday = 2, 17 | 18 | /// 19 | /// The wednesday 20 | /// 21 | Wednesday = 3, 22 | 23 | /// 24 | /// The thursday 25 | /// 26 | Thursday = 4, 27 | 28 | /// 29 | /// The friday 30 | /// 31 | Friday = 5, 32 | 33 | /// 34 | /// The saturday 35 | /// 36 | Saturday = 6, 37 | 38 | /// 39 | /// The sunday 40 | /// 41 | Sunday = 7 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/Deadline.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | using Todoist.Net.Serialization.Converters; 5 | 6 | namespace Todoist.Net.Models 7 | { 8 | /// 9 | /// Represents a deadline for a task. 10 | /// 11 | public class Deadline 12 | { 13 | [JsonConstructor] 14 | internal Deadline() 15 | { 16 | 17 | } 18 | 19 | /// 20 | /// Initializes a new instance of the class with the specified date. 21 | /// 22 | /// The date of the deadline. 23 | public Deadline(DateTime date) 24 | { 25 | Date = date; 26 | } 27 | 28 | /// 29 | /// Gets the date of the deadline. 30 | /// 31 | [JsonPropertyName("date")] 32 | [JsonConverter(typeof(DateOnlyConverter))] 33 | public DateTime Date { get; internal set; } 34 | 35 | [JsonInclude] 36 | [JsonPropertyName("lang")] 37 | internal string Lang { get; } = "en"; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/Duration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents durations for tasks. 8 | /// 9 | public class Duration 10 | { 11 | 12 | private int _amount; 13 | private DurationUnit _unit; 14 | 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | /// The time amount. 19 | /// The time unit. 20 | public Duration(int amount, DurationUnit unit) 21 | { 22 | Amount = amount; 23 | Unit = unit; 24 | } 25 | 26 | [JsonConstructor] 27 | internal Duration() 28 | { 29 | } 30 | 31 | /// 32 | /// Gets or sets the duration time amount. 33 | /// 34 | /// 35 | /// Must be a positive integer (greater than zero). 36 | /// 37 | /// 38 | /// The time amount. 39 | /// 40 | /// Duration amount must be greater than zero." 41 | [JsonPropertyName("amount")] 42 | public int Amount 43 | { 44 | get => _amount; 45 | set => _amount = value > 0 46 | ? value 47 | : throw new ArgumentOutOfRangeException(nameof(Amount), "Duration amount must be greater than zero."); 48 | } 49 | 50 | /// 51 | /// Gets or sets the duration time unit. 52 | /// 53 | /// 54 | /// Either minute or day. 55 | /// 56 | /// 57 | /// The duration unit. 58 | /// 59 | /// Unit 60 | [JsonPropertyName("unit")] 61 | public DurationUnit Unit 62 | { 63 | get => _unit; 64 | set => _unit = value ?? throw new ArgumentNullException(nameof(Unit)); 65 | } 66 | 67 | 68 | /// 69 | /// Gets the value of the duration as a object. 70 | /// 71 | /// 72 | /// The value of the duration. 73 | /// 74 | [JsonIgnore] 75 | public TimeSpan TimeValue 76 | { 77 | get 78 | { 79 | switch (Unit) 80 | { 81 | case var _ when Unit == DurationUnit.Minute: 82 | return TimeSpan.FromMinutes(Amount); 83 | case var _ when Unit == DurationUnit.Day: 84 | return TimeSpan.FromDays(Amount); 85 | default: 86 | return TimeSpan.Zero; // In case 'Unit' is unset, there's no duration. 87 | } 88 | } 89 | } 90 | 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/DurationUnit.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Represents a duration unit. 5 | /// 6 | /// 7 | public class DurationUnit : StringEnum 8 | { 9 | /// 10 | /// Initializes a new instance of the class. 11 | /// 12 | /// The value. 13 | private DurationUnit(string value) 14 | : base(value) 15 | { 16 | } 17 | 18 | /// 19 | /// Gets the minute unit. 20 | /// 21 | /// The minute unit. 22 | public static DurationUnit Minute { get; } = new DurationUnit("minute"); 23 | 24 | /// 25 | /// Gets the day unit. 26 | /// 27 | /// The day unit. 28 | public static DurationUnit Day { get; } = new DurationUnit("day"); 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/EmailInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents an information about a Todoist email. 7 | /// 8 | public class EmailInfo 9 | { 10 | [JsonConstructor] 11 | internal EmailInfo() 12 | { 13 | } 14 | 15 | /// 16 | /// Gets the email. 17 | /// 18 | /// 19 | /// The email. 20 | /// 21 | [JsonPropertyName("email")] 22 | public string Email { get; internal set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/EmptyCommand.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | internal class EmptyCommand : ICommandArgument 4 | { 5 | private EmptyCommand() 6 | { 7 | } 8 | 9 | public static EmptyCommand Instance { get; } = new EmptyCommand(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/FileAttachment.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents an attachment. 7 | /// 8 | public class FileAttachment : FileBase 9 | { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// Name of the file. 14 | public FileAttachment(string fileName) 15 | : base(fileName) 16 | { 17 | } 18 | 19 | /// 20 | /// Initializes a new instance of the class. 21 | /// 22 | /// Name of the file. 23 | /// The file URL. 24 | public FileAttachment(string fileName, string fileUrl) 25 | : base(fileName, fileUrl) 26 | { 27 | } 28 | 29 | [JsonConstructor] 30 | internal FileAttachment() 31 | { 32 | } 33 | 34 | /// 35 | /// Gets the size of the file. 36 | /// 37 | /// 38 | /// The size of the file. 39 | /// 40 | [JsonPropertyName("file_size")] 41 | public int FileSize { get; internal set; } 42 | 43 | /// 44 | /// Gets the type of the file. 45 | /// 46 | /// 47 | /// The type of the file. 48 | /// 49 | [JsonPropertyName("file_type")] 50 | public string FileType { get; internal set; } 51 | 52 | /// 53 | /// Gets the state of the upload. 54 | /// 55 | /// 56 | /// The state of the upload. 57 | /// 58 | [JsonPropertyName("upload_state")] 59 | public string UploadState { get; internal set; } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/FileBase.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents a base file. 7 | /// 8 | public class FileBase 9 | { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// Name of the file. 14 | public FileBase(string fileName) 15 | { 16 | FileName = fileName; 17 | } 18 | 19 | /// 20 | /// Initializes a new instance of the class. 21 | /// 22 | /// Name of the file. 23 | /// The file URL. 24 | public FileBase(string fileName, string fileUrl) 25 | { 26 | FileName = fileName; 27 | FileUrl = fileUrl; 28 | } 29 | 30 | [JsonConstructor] 31 | internal FileBase() 32 | { 33 | } 34 | 35 | /// 36 | /// Gets or sets the name of the file. 37 | /// 38 | /// 39 | /// The name of the file. 40 | /// 41 | [JsonPropertyName("file_name")] 42 | public string FileName { get; set; } 43 | 44 | /// 45 | /// Gets or sets the file URL. 46 | /// 47 | /// 48 | /// The file URL. 49 | /// 50 | [JsonPropertyName("file_url")] 51 | public string FileUrl { get; set; } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/FilterInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents an information about a Todoist filter. 7 | /// 8 | public class FilterInfo 9 | { 10 | /// 11 | /// Gets the filter. 12 | /// 13 | /// The filter. 14 | [JsonPropertyName("filter")] 15 | public Filter Filter { get; internal set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ICommandArgument.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | internal interface ICommandArgument 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/IUnsettableProperties.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Reflection; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace Todoist.Net.Models 6 | { 7 | /// 8 | /// Represents an entity that could have its properties unset. 9 | /// 10 | /// 11 | /// Unset properties are meant to be properties that are included 12 | /// in the outgoing requests although not being set to any value (). 13 | /// 14 | public interface IUnsettableProperties 15 | { 16 | /// 17 | /// Gets a collection of information about properties that are not set to any value () 18 | /// but still should be included in the outgoing requests. 19 | /// 20 | [JsonIgnore] 21 | HashSet UnsetProperties { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/IWithRelationsArgument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | internal interface IWithRelationsArgument 7 | { 8 | void UpdateRelatedTempIds(IDictionary map); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/IdToOrderArgument.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | internal class IdToOrderArgument : ICommandArgument 7 | { 8 | public IdToOrderArgument(IEnumerable orderEntries) 9 | { 10 | Ids = new Dictionary(); 11 | foreach (var entry in orderEntries) 12 | { 13 | Ids.Add(entry.Id, entry.Order); 14 | } 15 | } 16 | 17 | [JsonPropertyName("ids_to_orders")] 18 | public IDictionary Ids { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/IdToOrderMappingArgument.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | internal class IdToOrderMappingArgument : ICommandArgument 7 | { 8 | public IdToOrderMappingArgument(IEnumerable orderEntries) 9 | { 10 | Ids = new Dictionary(); 11 | foreach (var entry in orderEntries) 12 | { 13 | Ids.Add(entry.Id, entry.Order); 14 | } 15 | } 16 | 17 | [JsonPropertyName("id_order_mapping")] 18 | public IDictionary Ids { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/IdsArgument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace Todoist.Net.Models 6 | { 7 | internal class IdsArgument : ICommandArgument 8 | { 9 | public IdsArgument() 10 | { 11 | Ids = new List(); 12 | } 13 | 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | /// The temporary ids. 18 | /// is 19 | public IdsArgument(IEnumerable tempIds) 20 | { 21 | Ids = tempIds ?? throw new ArgumentNullException(nameof(tempIds)); 22 | } 23 | 24 | [JsonPropertyName("ids")] 25 | public IEnumerable Ids { get; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/Invitation.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | internal class Invitation : BaseInvitation 6 | { 7 | [JsonConstructor] 8 | internal Invitation(long id, string secret) 9 | : base(id) 10 | { 11 | Secret = secret; 12 | } 13 | 14 | [JsonPropertyName("invitation_secret")] 15 | public string Secret { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ItemInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents an information about a Todoist task. 8 | /// 9 | public class ItemInfo 10 | { 11 | /// 12 | /// Gets the item. 13 | /// 14 | /// The item. 15 | [JsonPropertyName("item")] 16 | public Item Item { get; internal set; } 17 | 18 | /// 19 | /// Gets the notes. 20 | /// 21 | /// The notes. 22 | [JsonPropertyName("notes")] 23 | public IReadOnlyCollection Notes { get; internal set; } 24 | 25 | /// 26 | /// Gets the project. 27 | /// 28 | /// The project. 29 | [JsonPropertyName("project")] 30 | public Project Project { get; internal set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ItemMoveArgument.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents a item move argument. 7 | /// 8 | /// 9 | public class ItemMoveArgument : BaseEntity 10 | { 11 | [JsonConstructor] 12 | internal ItemMoveArgument() 13 | { 14 | } 15 | 16 | /// 17 | /// Gets the project identifier. 18 | /// 19 | /// 20 | /// The project identifier. 21 | /// 22 | [JsonPropertyName("project_id")] 23 | public ComplexId? ProjectId { get; internal set; } 24 | 25 | /// 26 | /// Gets the section identifier. 27 | /// 28 | /// 29 | /// The section identifier. 30 | /// 31 | [JsonPropertyName("section_id")] 32 | public ComplexId? SectionId { get; internal set; } 33 | 34 | /// Gets the parent entity identifier. 35 | /// The parent entity identifier. 36 | [JsonPropertyName("parent_id")] 37 | public ComplexId? ParentId { get; internal set; } 38 | 39 | /// 40 | /// Creates the move to project argument. 41 | /// 42 | /// The item identifier. 43 | /// Id of the destination parent task. The task becomes the last child task of the parent task. 44 | /// 45 | /// Instance of 46 | /// 47 | public static ItemMoveArgument CreateMoveToParent(ComplexId itemId, ComplexId parentItemId) 48 | { 49 | return new ItemMoveArgument { Id = itemId, ParentId = parentItemId }; 50 | } 51 | 52 | /// 53 | /// Creates the move to project argument. 54 | /// 55 | /// The item identifier. 56 | /// Id of the destination project. The task becomes the last root task of the project. 57 | /// Instance of 58 | public static ItemMoveArgument CreateMoveToProject(ComplexId itemId, ComplexId projectId) 59 | { 60 | return new ItemMoveArgument { Id = itemId, ProjectId = projectId }; 61 | } 62 | 63 | /// 64 | /// Creates the move to project argument. 65 | /// 66 | /// The item identifier. 67 | /// Id of the destination section. The task becomes the last root task of the section. 68 | /// Instance of 69 | public static ItemMoveArgument CreateMoveToSection(ComplexId itemId, ComplexId sectionId) 70 | { 71 | return new ItemMoveArgument { Id = itemId, SectionId = sectionId }; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/KarmaGoals.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | using Todoist.Net.Serialization.Converters; 5 | 6 | namespace Todoist.Net.Models 7 | { 8 | /// 9 | /// Represents karma settings. 10 | /// 11 | public class KarmaGoals : ICommandArgument 12 | { 13 | /// 14 | /// Initializes a new instance of the class. 15 | /// 16 | public KarmaGoals() 17 | { 18 | IgnoreDays = new HashSet(); 19 | } 20 | 21 | /// 22 | /// Gets or sets the daily goal. 23 | /// 24 | /// The daily goal. 25 | [JsonPropertyName("daily_goal")] 26 | public int? DailyGoal { get; set; } 27 | 28 | /// 29 | /// Gets the ignore days. 30 | /// 31 | /// The ignore days. 32 | [JsonPropertyName("ignore_days")] 33 | public ICollection IgnoreDays { get; internal set; } 34 | 35 | /// 36 | /// Gets or sets a value indicating whether [karma disabled]. 37 | /// 38 | /// true if [karma disabled]; otherwise, false. 39 | [JsonConverter(typeof(BoolConverter))] 40 | [JsonPropertyName("karma_disabled")] 41 | public bool KarmaDisabled { get; set; } 42 | 43 | /// 44 | /// Gets or sets a value indicating whether [vacation mode]. 45 | /// 46 | /// true if [vacation mode]; otherwise, false. 47 | [JsonConverter(typeof(BoolConverter))] 48 | [JsonPropertyName("vacation_mode")] 49 | public bool VacationMode { get; set; } 50 | 51 | /// 52 | /// Gets or sets the weekly goal. 53 | /// 54 | /// The weekly goal. 55 | [JsonPropertyName("weekly_goal")] 56 | public int? WeeklyGoal { get; set; } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/Label.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents a Todoist label. 8 | /// 9 | /// 10 | public class Label : BaseEntity 11 | { 12 | /// 13 | /// Initializes a new instance of the class. 14 | /// 15 | /// The name. 16 | /// Value cannot be null or empty - name 17 | public Label(string name) 18 | { 19 | if (string.IsNullOrEmpty(name)) 20 | { 21 | throw new ArgumentException("Value cannot be null or empty.", nameof(name)); 22 | } 23 | 24 | Name = name; 25 | } 26 | 27 | /// 28 | /// Gets or sets the color. 29 | /// 30 | /// The color. 31 | [JsonPropertyName("color")] 32 | public string Color { get; set; } 33 | 34 | /// 35 | /// Gets a value indicating whether this instance is deleted. 36 | /// 37 | /// true if this instance is deleted; otherwise, false. 38 | [JsonPropertyName("is_deleted")] 39 | public bool IsDeleted { get; internal set; } 40 | 41 | /// 42 | /// Gets a value indicating whether this instance is favorite. 43 | /// 44 | /// 45 | /// true if this instance is favorite; otherwise, false. 46 | /// 47 | [JsonPropertyName("is_favorite")] 48 | public bool IsFavorite { get; internal set; } 49 | 50 | /// 51 | /// Gets or sets the item order. 52 | /// 53 | /// The item order. 54 | [JsonPropertyName("item_order")] 55 | public int ItemOrder { get; set; } 56 | 57 | /// 58 | /// Gets or sets the name. 59 | /// 60 | /// The name. 61 | [JsonPropertyName("name")] 62 | public string Name { get; set; } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/LocationTrigger.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Represents a location trigger. 5 | /// 6 | /// 7 | public class LocationTrigger : StringEnum 8 | { 9 | /// 10 | /// Initializes a new instance of the class. 11 | /// 12 | /// The value. 13 | private LocationTrigger(string value) 14 | : base(value) 15 | { 16 | } 17 | 18 | /// 19 | /// Gets the on enter. 20 | /// 21 | /// The on enter. 22 | /// For entering the location. 23 | public static LocationTrigger OnEnter { get; } = new LocationTrigger("on_enter"); 24 | 25 | /// 26 | /// Gets the on leave. 27 | /// 28 | /// The on leave. 29 | /// For leaving the location. 30 | public static LocationTrigger OnLeave { get; } = new LocationTrigger("on_leave"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/LogExtraData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents extra data of a Todoist log entry. 8 | /// 9 | public class LogExtraData 10 | { 11 | /// 12 | /// Gets the client. 13 | /// 14 | /// 15 | /// The client. 16 | /// 17 | [JsonPropertyName("client")] 18 | public string Client { get; internal set; } 19 | 20 | /// 21 | /// Gets the content. 22 | /// 23 | /// The content. 24 | [JsonPropertyName("content")] 25 | public string Content { get; internal set; } 26 | 27 | /// 28 | /// Gets the due date. 29 | /// 30 | /// The due date. 31 | [JsonPropertyName("due_date")] 32 | public DateTime? DueDate { get; internal set; } 33 | 34 | /// 35 | /// Gets the last due date. 36 | /// 37 | /// The last due date. 38 | [JsonPropertyName("last_due_date")] 39 | public DateTime? LastDueDate { get; internal set; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/MoveArgument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents a move argument. 8 | /// 9 | public class MoveArgument : BaseEntity 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The identifier of moved entity. 15 | /// The parent entity identifier. 16 | /// Entity ID is required for the operation 17 | public MoveArgument(ComplexId id, ComplexId parentId) 18 | : base(id) 19 | { 20 | if (id.IsEmpty) 21 | { 22 | throw new ArgumentException("Entity ID is required for the move operation", nameof(id)); 23 | } 24 | 25 | if (parentId.IsEmpty) 26 | { 27 | throw new ArgumentException("Parent ID is required for the move operation", nameof(parentId)); 28 | } 29 | 30 | ParentId = parentId; 31 | } 32 | 33 | [JsonConstructor] 34 | internal MoveArgument() 35 | { 36 | } 37 | 38 | /// Gets the parent entity identifier. 39 | /// The parent entity identifier. 40 | [JsonPropertyName("parent_id")] 41 | public ComplexId ParentId { get; internal set; } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/NotesInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents collections of item and project notes. 7 | /// 8 | public class NotesInfo 9 | { 10 | /// 11 | /// Gets the item notes. 12 | /// 13 | /// 14 | /// The item notes. 15 | /// 16 | public IReadOnlyCollection ItemNotes { get; internal set; } 17 | 18 | /// 19 | /// Gets the project notes. 20 | /// 21 | /// 22 | /// The project notes. 23 | /// 24 | public IReadOnlyCollection ProjectNotes { get; internal set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/NotificationService.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Represents a reminder type. 5 | /// 6 | /// 7 | public class NotificationService : StringEnum 8 | { 9 | /// 10 | /// Initializes a new instance of the class. 11 | /// 12 | /// The value. 13 | private NotificationService(string value) 14 | : base(value) 15 | { 16 | } 17 | 18 | /// 19 | /// Gets the email. 20 | /// 21 | /// The email. 22 | public static NotificationService Email { get; } = new NotificationService("email"); 23 | 24 | /// 25 | /// Gets the push. 26 | /// 27 | /// The push. 28 | public static NotificationService Push { get; } = new NotificationService("push"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/NotificationSetting.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents a notification setting. 7 | /// 8 | public class NotificationSetting 9 | { 10 | /// 11 | /// Gets a value indicating whether [notify email]. 12 | /// 13 | /// true if [notify email]; otherwise, false. 14 | [JsonPropertyName("notify_email")] 15 | public bool NotifyEmail { get; internal set; } 16 | 17 | /// 18 | /// Gets a value indicating whether [notify push]. 19 | /// 20 | /// true if [notify push]; otherwise, false. 21 | [JsonPropertyName("notify_push")] 22 | public bool NotifyPush { get; internal set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ObjectEventTypes.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Class ObjectEventTypes. 5 | /// 6 | public class ObjectEventTypes 7 | { 8 | /// 9 | /// Gets or sets the type of the event. 10 | /// 11 | /// The type of the event. 12 | public string EventType { get; set; } 13 | 14 | /// 15 | /// Gets or sets the type of the object. 16 | /// 17 | /// The type of the object. 18 | public string ObjectType { get; set; } 19 | 20 | /// 21 | /// Returns a that represents this instance. 22 | /// 23 | /// A that represents this instance. 24 | public override string ToString() 25 | { 26 | return $"\"{ObjectType}:{EventType}\""; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ObjectType.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents a Todoist object type. 7 | /// 8 | /// 9 | public class ObjectType : StringEnum 10 | { 11 | [JsonConstructor] 12 | internal ObjectType(string value) 13 | : base(value) 14 | { 15 | } 16 | 17 | /// 18 | /// Gets the item type. 19 | /// 20 | /// 21 | /// The item type. 22 | /// 23 | public static ObjectType Item { get; } = new ObjectType("item"); 24 | 25 | /// 26 | /// Gets the project type. 27 | /// 28 | /// 29 | /// The project type. 30 | /// 31 | public static ObjectType Project { get; } = new ObjectType("project"); 32 | 33 | /// 34 | /// Gets the project comments type. 35 | /// 36 | /// 37 | /// The project comments type. 38 | /// 39 | public static ObjectType ProjectComments { get; } = new ObjectType("project_comments"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/OrderEntry.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Represents an order entry which can be used to specify order of a Todoist entity. 5 | /// 6 | public class OrderEntry 7 | { 8 | /// 9 | /// Initializes a new instance of the class. 10 | /// 11 | /// The identifier. 12 | /// The order. 13 | public OrderEntry(ComplexId id, int order) 14 | { 15 | Id = id; 16 | Order = order; 17 | } 18 | 19 | /// 20 | /// Gets the identifier. 21 | /// 22 | /// The identifier. 23 | public ComplexId Id { get; } 24 | 25 | /// 26 | /// Gets the order. 27 | /// 28 | /// The order. 29 | public int Order { get; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/OrderType.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Represents sorting options. 5 | /// 6 | public enum OrderType : byte 7 | { 8 | /// 9 | /// The oldest first. 10 | /// 11 | OldestFirst = 0, 12 | 13 | /// 14 | /// The oldest last. 15 | /// 16 | OldestLast = 1 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/Priority.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Priority of a task. 5 | /// 6 | /// 7 | /// The priority of the task (a number between 1 and 4, 4 for very urgent and 1 for natural). 8 | /// Note: Keep in mind that very urgent is the priority 1 on clients. So, p1 will return 4 in the API. 9 | /// 10 | public enum Priority : byte 11 | { 12 | /// 13 | /// The priority1 14 | /// 15 | Priority1 = 4, 16 | 17 | /// 18 | /// The priority2 19 | /// 20 | Priority2 = 3, 21 | 22 | /// 23 | /// The priority3 24 | /// 25 | Priority3 = 2, 26 | 27 | /// 28 | /// The priority4 29 | /// 30 | Priority4 = 1 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ProjectData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents a Todoist project and its uncompleted tasks. 8 | /// 9 | public class ProjectData 10 | { 11 | /// 12 | /// Gets the items. 13 | /// 14 | /// 15 | /// The items. 16 | /// 17 | [JsonPropertyName("items")] 18 | public IReadOnlyCollection Items { get; internal set; } 19 | 20 | /// 21 | /// Gets the project. 22 | /// 23 | /// The project. 24 | [JsonPropertyName("project")] 25 | public Project Project { get; internal set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ProjectInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents an information about a Todoist project. 8 | /// 9 | public class ProjectInfo 10 | { 11 | /// 12 | /// Gets the notes. 13 | /// 14 | /// The notes. 15 | [JsonPropertyName("notes")] 16 | public IReadOnlyCollection Notes { get; internal set; } 17 | 18 | /// 19 | /// Gets the project. 20 | /// 21 | /// The project. 22 | [JsonPropertyName("project")] 23 | public Project Project { get; internal set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ProjectReorderArgument.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | internal class ProjectReorderArgument : ICommandArgument 7 | { 8 | public ProjectReorderArgument(IEnumerable reorderEntries) 9 | { 10 | ReorderEntries = reorderEntries; 11 | } 12 | 13 | [JsonPropertyName("projects")] 14 | public IEnumerable ReorderEntries { get; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/QuickAddItem.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents a quick add task. 7 | /// 8 | public class QuickAddItem 9 | { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// The text of the task that is parsed. It can include a due date in free form text, a project name starting with the # character, a label starting with the @ character, and an assignee starting with the + character. 14 | public QuickAddItem(string text) 15 | { 16 | Text = text; 17 | } 18 | 19 | /// 20 | /// Gets or sets the content of the note. 21 | /// 22 | /// 23 | /// The content of the note. 24 | /// 25 | public string Note { get; set; } 26 | 27 | /// 28 | /// Gets or sets the reminder. The date of the reminder, added in free form text. 29 | /// 30 | /// 31 | /// The reminder. 32 | /// 33 | public string Reminder { get; set; } 34 | 35 | /// 36 | /// Gets the text of the task that is parsed. 37 | /// It can include a due date in free form text, a project name starting with the # character, a label starting with the @ character, and an assignee starting with the + character. 38 | /// 39 | /// 40 | /// The text. 41 | /// 42 | /// Example: Task1 @Label1 #Project1 +ExampleUser 43 | public string Text { get; } 44 | 45 | internal ICollection> ToParameters() 46 | { 47 | var parameters = new LinkedList>(); 48 | 49 | parameters.AddLast(new KeyValuePair("text", Text)); 50 | 51 | if (string.IsNullOrEmpty(Note)) 52 | { 53 | parameters.AddLast(new KeyValuePair("note", Note)); 54 | } 55 | 56 | if (string.IsNullOrEmpty(Text)) 57 | { 58 | parameters.AddLast(new KeyValuePair("reminder", Reminder)); 59 | } 60 | 61 | return parameters; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/Reminder.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Class Reminder. 7 | /// 8 | /// 9 | public class Reminder : BaseUnsetEntity 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// An ID of a task. 15 | public Reminder(ComplexId itemId) 16 | { 17 | ItemId = itemId; 18 | } 19 | 20 | /// 21 | /// Initializes a new instance of the class. 22 | /// 23 | [JsonConstructor] 24 | internal Reminder() 25 | { 26 | } 27 | 28 | /// 29 | /// Gets or sets the due date. 30 | /// 31 | /// 32 | /// The due date. 33 | /// 34 | [JsonPropertyName("due")] 35 | public DueDate DueDate { get; set; } 36 | 37 | /// 38 | /// Gets a value indicating whether this instance is deleted. 39 | /// 40 | /// true if this instance is deleted; otherwise, false. 41 | [JsonPropertyName("is_deleted")] 42 | public bool? IsDeleted { get; internal set; } 43 | 44 | /// 45 | /// Gets or sets the item identifier. 46 | /// 47 | /// The item identifier. 48 | [JsonPropertyName("item_id")] 49 | public ComplexId ItemId { get; set; } 50 | 51 | /// 52 | /// Gets or sets the location trigger. 53 | /// 54 | /// The location trigger. 55 | [JsonPropertyName("loc_trigger")] 56 | public LocationTrigger LocationTrigger { get; set; } 57 | 58 | /// 59 | /// Gets or sets the mm offset. 60 | /// 61 | /// The mm offset. 62 | /// The relative time in minutes before the due date of the item, in which the reminder should be triggered. 63 | /// Note, that the item should have a due date set in order to add a relative reminder. 64 | [JsonPropertyName("minute_offset")] 65 | public long? MinuteOffset { get; set; } 66 | 67 | /// 68 | /// Gets or sets the notify uid. 69 | /// 70 | /// The notify uid. 71 | [JsonPropertyName("notify_uid")] 72 | public string NotifyUid { get; set; } 73 | 74 | /// 75 | /// Gets or sets the type. 76 | /// 77 | /// The type. 78 | [JsonPropertyName("type")] 79 | public ReminderType Type { get; set; } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ReminderInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents an information about a Todoist reminder. 7 | /// 8 | public class ReminderInfo 9 | { 10 | /// 11 | /// Gets the reminder. 12 | /// 13 | /// The reminder. 14 | [JsonPropertyName("reminder")] 15 | public Reminder Reminder { get; internal set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ReminderService.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Represents a reminder type. 5 | /// 6 | /// 7 | public class ReminderService : StringEnum 8 | { 9 | /// 10 | /// Initializes a new instance of the class. 11 | /// 12 | /// The value. 13 | private ReminderService(string value) 14 | : base(value) 15 | { 16 | } 17 | 18 | /// 19 | /// Gets the email. 20 | /// 21 | /// The email. 22 | public static ReminderService Email { get; } = new ReminderService("email"); 23 | 24 | /// 25 | /// Gets the mobile. 26 | /// 27 | /// The mobile. 28 | public static ReminderService Mobile { get; } = new ReminderService("mobile"); 29 | 30 | /// 31 | /// Gets the push. 32 | /// 33 | /// The push. 34 | public static ReminderService Push { get; } = new ReminderService("push"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ReminderType.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Represents a reminder type. 5 | /// 6 | /// 7 | public class ReminderType : StringEnum 8 | { 9 | /// 10 | /// Initializes a new instance of the class. 11 | /// 12 | /// The value. 13 | private ReminderType(string value) 14 | : base(value) 15 | { 16 | } 17 | 18 | /// 19 | /// Gets the absolute. 20 | /// 21 | /// The absolute. 22 | /// For a time-based reminder with a specific time and date in the future. 23 | public static ReminderType Absolute { get; } = new ReminderType("absolute"); 24 | 25 | /// 26 | /// Gets the location. 27 | /// 28 | /// The location. 29 | /// For a location-based reminder. 30 | public static ReminderType Location { get; } = new ReminderType("location"); 31 | 32 | /// 33 | /// Gets the relative. 34 | /// 35 | /// The relative. 36 | /// For a time-based reminder specified in minutes from now. 37 | public static ReminderType Relative { get; } = new ReminderType("relative"); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ReorderArgument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents a reorder entry. 8 | /// 9 | public class ReorderEntry 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The identifier of moved entity. 15 | /// The new order. 16 | /// Entity ID is required for reorder operation 17 | public ReorderEntry(ComplexId id, int childOrder) 18 | { 19 | if (id.IsEmpty) 20 | { 21 | throw new ArgumentException("Entity ID is required for reorder operation", nameof(id)); 22 | } 23 | 24 | Id = id; 25 | ChildOrder = childOrder; 26 | } 27 | 28 | /// 29 | /// Gets the order. 30 | /// 31 | /// 32 | /// The order. 33 | /// 34 | [JsonPropertyName("child_order")] 35 | public int ChildOrder { get; } 36 | 37 | /// 38 | /// Gets the identifier. 39 | /// 40 | /// 41 | /// The identifier. 42 | /// 43 | [JsonPropertyName("id")] 44 | public ComplexId Id { get; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ReorderItemsArgument.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | internal class ReorderItemsArgument : ICommandArgument 7 | { 8 | public ReorderItemsArgument(IEnumerable reorderArguments) 9 | { 10 | ReorderArguments = reorderArguments; 11 | } 12 | 13 | [JsonPropertyName("items")] 14 | public IEnumerable ReorderArguments { get; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ReorderProjectArgument.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | internal class ReorderProjectsArgument : ICommandArgument 7 | { 8 | public ReorderProjectsArgument(IEnumerable reorderArguments) 9 | { 10 | ReorderArguments = reorderArguments; 11 | } 12 | 13 | [JsonPropertyName("projects")] 14 | public IEnumerable ReorderArguments { get; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ReorderSectionArgument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace Todoist.Net.Models 6 | { 7 | internal class ReorderSectionArgument : ICommandArgument 8 | { 9 | public ReorderSectionArgument(ICollection orderEntries) 10 | { 11 | OrderEntries = orderEntries ?? throw new ArgumentNullException(nameof(orderEntries)); 12 | } 13 | 14 | [JsonPropertyName("sections")] 15 | public ICollection OrderEntries { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ResourceType.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Contains Todoist resource types. 5 | /// 6 | public class ResourceType : StringEnum 7 | { 8 | /// 9 | /// Initializes a new instance of the class. 10 | /// 11 | /// The resource. 12 | private ResourceType(string value) 13 | : base(value) 14 | { 15 | } 16 | 17 | /// 18 | /// Gets the filters. 19 | /// 20 | /// The filters. 21 | public static ResourceType Filters { get; } = new ResourceType("filters"); 22 | 23 | /// 24 | /// Gets the items. 25 | /// 26 | /// The items. 27 | public static ResourceType Items { get; } = new ResourceType("items"); 28 | 29 | /// 30 | /// Gets the labels. 31 | /// 32 | /// The labels. 33 | public static ResourceType Labels { get; } = new ResourceType("labels"); 34 | 35 | /// 36 | /// Gets the locations. 37 | /// 38 | /// The locations. 39 | public static ResourceType Locations { get; } = new ResourceType("locations"); 40 | 41 | /// 42 | /// Gets the notes. 43 | /// 44 | /// The notes. 45 | public static ResourceType Notes { get; } = new ResourceType("notes"); 46 | 47 | /// 48 | /// Gets the live notifications. 49 | /// 50 | /// The live notifications. 51 | public static ResourceType Notifications { get; } = new ResourceType("live_notifications"); 52 | 53 | /// 54 | /// Gets the projects. 55 | /// 56 | /// The projects. 57 | public static ResourceType Projects { get; } = new ResourceType("projects"); 58 | 59 | /// 60 | /// Gets the sections. 61 | /// 62 | /// The sections. 63 | public static ResourceType Sections { get; } = new ResourceType("sections"); 64 | 65 | /// 66 | /// Gets the collaborators. 67 | /// 68 | /// The collaborators. 69 | public static ResourceType Collaborators { get; } = new ResourceType("collaborators"); 70 | 71 | /// 72 | /// Gets the reminders. 73 | /// 74 | /// The reminders. 75 | public static ResourceType Reminders { get; } = new ResourceType("reminders"); 76 | 77 | /// 78 | /// Gets the user. 79 | /// 80 | /// The user. 81 | public static ResourceType User { get; } = new ResourceType("user"); 82 | 83 | /// 84 | /// Gets all. 85 | /// 86 | /// All resources. 87 | internal static ResourceType All { get; } = new ResourceType("all"); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/SectionMoveArgument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents a section move argument. 8 | /// 9 | public class SectionMoveArgument : BaseEntity 10 | { 11 | /// 12 | /// Initializes a new instance of the class. 13 | /// 14 | /// The identifier of moved entity. 15 | /// Id of the destination project. 16 | /// Entity ID is required for the operation 17 | public SectionMoveArgument(ComplexId id, ComplexId? projectId) 18 | : base(id) 19 | { 20 | if (id.IsEmpty) 21 | { 22 | throw new ArgumentException("Entity ID is required for the move operation", nameof(id)); 23 | } 24 | 25 | ProjectId = projectId; 26 | } 27 | 28 | [JsonConstructor] 29 | internal SectionMoveArgument() 30 | { 31 | } 32 | 33 | /// Gets the parent entity identifier. 34 | /// The parent entity identifier. 35 | [JsonPropertyName("project_id")] 36 | public ComplexId? ProjectId { get; internal set; } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/SectionOrderEntry.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Represents an section order entry which can be used to specify order of a Todoist section. 7 | /// 8 | public class SectionOrderEntry 9 | { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// The identifier. 14 | /// The order. 15 | public SectionOrderEntry(ComplexId id, int order) 16 | { 17 | Id = id; 18 | Order = order; 19 | } 20 | 21 | /// 22 | /// Gets the identifier. 23 | /// 24 | /// The identifier. 25 | [JsonPropertyName("id")] 26 | public ComplexId Id { get; } 27 | 28 | /// 29 | /// Gets the order. 30 | /// 31 | /// The order. 32 | [JsonPropertyName("section_order")] 33 | public int Order { get; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/ShareCommandArgument.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | internal class ShareProjectArgument : ICommandArgument 6 | { 7 | /// 8 | /// Initializes a new instance of the class. 9 | /// 10 | /// The identifier. 11 | /// The email. 12 | [JsonConstructor] 13 | internal ShareProjectArgument(ComplexId id, string email) 14 | { 15 | Id = id; 16 | Email = email; 17 | } 18 | 19 | [JsonPropertyName("email")] 20 | public string Email { get; set; } 21 | 22 | [JsonPropertyName("project_id")] 23 | public ComplexId Id { get; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/SyncResponse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace Todoist.Net.Models 6 | { 7 | internal class SyncResponse 8 | { 9 | [JsonPropertyName("sync_status")] 10 | public Dictionary SyncStatus { get; set; } 11 | 12 | [JsonPropertyName("temp_id_mapping")] 13 | public Dictionary TempIdMappings { get; set; } 14 | 15 | [JsonPropertyName("sync_token")] 16 | public string SyncToken { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/TimeFormat.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Represents time formats. 5 | /// 6 | public enum TimeFormat : byte 7 | { 8 | /// 9 | /// The hour24 10 | /// 11 | /// 24h format such as 13:00. 12 | Hour24 = 0, 13 | 14 | /// 15 | /// The hour12 16 | /// 17 | /// 12h format such as 1:00pm. 18 | Hour12 = 1 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/TimeZoneInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace Todoist.Net.Models 4 | { 5 | /// 6 | /// Class TimeZoneInfo. 7 | /// 8 | public class TimeZoneInfo 9 | { 10 | /// 11 | /// Gets the GMT string. 12 | /// 13 | /// The GMT string. 14 | [JsonPropertyName("gmt_string")] 15 | public string GmtString { get; internal set; } 16 | 17 | /// 18 | /// Gets the hours. 19 | /// 20 | /// The hours. 21 | [JsonPropertyName("hours")] 22 | public int Hours { get; internal set; } 23 | 24 | /// 25 | /// Gets the is DST. 26 | /// 27 | /// The is DST. 28 | [JsonPropertyName("is_dst")] 29 | public int IsDst { get; internal set; } 30 | 31 | /// 32 | /// Gets the minutes. 33 | /// 34 | /// The minutes. 35 | [JsonPropertyName("minutes")] 36 | public int Minutes { get; internal set; } 37 | 38 | /// 39 | /// Gets the timezone. 40 | /// 41 | /// The timezone. 42 | [JsonPropertyName("timezone")] 43 | public string Timezone { get; internal set; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/UpdateItem.cs: -------------------------------------------------------------------------------- 1 | namespace Todoist.Net.Models 2 | { 3 | /// 4 | /// Represents a Todoist task. 5 | /// 6 | public class UpdateItem : BaseItem 7 | { 8 | /// 9 | /// Initializes a new instance of the class. 10 | /// 11 | /// The id of the item to update. 12 | public UpdateItem(ComplexId id) 13 | : base(id) 14 | { 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Todoist.Net/Models/Upload.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace Todoist.Net.Models 5 | { 6 | /// 7 | /// Represents a Todoist upload. 8 | /// 9 | public class Upload 10 | { 11 | /// 12 | /// Gets the name of the file. 13 | /// 14 | /// The name of the file. 15 | [JsonPropertyName("filename")] 16 | public string FileName { get; internal set; } 17 | 18 | /// 19 | /// Gets the size of the file. 20 | /// 21 | /// The size of the file. 22 | [JsonPropertyName("file_size")] 23 | public long FileSize { get; internal set; } 24 | 25 | /// 26 | /// Gets the type of the file. 27 | /// 28 | /// The type of the file. 29 | [JsonPropertyName("file_type")] 30 | public string FileType { get; internal set; } 31 | 32 | /// 33 | /// Gets the file URL. 34 | /// 35 | /// The file URL. 36 | [JsonPropertyName("file_url")] 37 | public string FileUrl { get; internal set; } 38 | 39 | /// 40 | /// Gets the identifier. 41 | /// 42 | /// The identifier. 43 | [JsonPropertyName("id")] 44 | public long Id { get; internal set; } 45 | 46 | /// 47 | /// Gets the ip. 48 | /// 49 | /// The ip. 50 | [JsonPropertyName("ip")] 51 | public string Ip { get; internal set; } 52 | 53 | /// 54 | /// Gets the item identifier. 55 | /// 56 | /// The item identifier. 57 | [JsonPropertyName("item_id")] 58 | public long? ItemId { get; internal set; } 59 | 60 | /// 61 | /// Gets the note identifier. 62 | /// 63 | /// The note identifier. 64 | [JsonPropertyName("note_id")] 65 | public long? NoteId { get; internal set; } 66 | 67 | /// 68 | /// Gets the project identifier. 69 | /// 70 | /// The project identifier. 71 | [JsonPropertyName("project_id")] 72 | public long? ProjectId { get; internal set; } 73 | 74 | /// 75 | /// Gets the uploaded. 76 | /// 77 | /// The uploaded. 78 | [JsonPropertyName("uploaded")] 79 | public DateTime Uploaded { get; internal set; } 80 | 81 | /// 82 | /// Gets the user identifier. 83 | /// 84 | /// The user identifier. 85 | [JsonPropertyName("user_id")] 86 | public long UserId { get; internal set; } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/Todoist.Net/Serialization/Converters/BoolConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace Todoist.Net.Serialization.Converters 6 | { 7 | internal sealed class BoolConverter : JsonConverter 8 | { 9 | public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 10 | { 11 | switch (reader.TokenType) 12 | { 13 | case JsonTokenType.String: 14 | return reader.GetString() == "1"; 15 | 16 | case JsonTokenType.Number: 17 | return reader.GetInt32() == 1; 18 | 19 | case JsonTokenType.True: 20 | return true; 21 | 22 | case JsonTokenType.False: 23 | return false; 24 | 25 | default: 26 | throw new JsonException($"Token type not supported for boolean properties. Token: {reader.TokenType}"); 27 | } 28 | } 29 | 30 | public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options) 31 | { 32 | writer.WriteNumberValue(value ? 1 : 0); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Todoist.Net/Serialization/Converters/CommandArgumentConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using System.Text.Json.Serialization; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Serialization.Converters 8 | { 9 | internal class CommandArgumentConverter : JsonConverter 10 | { 11 | public override ICommandArgument Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 12 | { 13 | // Skip deserialization. 14 | return null; 15 | } 16 | 17 | public override void Write(Utf8JsonWriter writer, ICommandArgument value, JsonSerializerOptions options) 18 | { 19 | // Use type of the implementing class. 20 | JsonSerializer.Serialize(writer, value, value.GetType(), options); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Todoist.Net/Serialization/Converters/CommandResultConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using System.Text.Json.Serialization; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Serialization.Converters 8 | { 9 | internal sealed class CommandResultConverter : JsonConverter 10 | { 11 | public override CommandResult Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 12 | { 13 | if (reader.TokenType == JsonTokenType.String) 14 | { 15 | var stringValue = reader.GetString(); 16 | if (!string.Equals(stringValue, CommandResult.SuccessValue, StringComparison.OrdinalIgnoreCase)) 17 | { 18 | throw new JsonException($"Unable to parse the value '{stringValue}' to a {nameof(CommandResult)} object."); 19 | } 20 | return CommandResult.Success; 21 | } 22 | var error = JsonSerializer.Deserialize(ref reader, options); 23 | 24 | return CommandResult.Fail(error); 25 | } 26 | 27 | public override void Write(Utf8JsonWriter writer, CommandResult value, JsonSerializerOptions options) 28 | { 29 | throw new NotImplementedException(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Todoist.Net/Serialization/Converters/DateOnlyConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Text.Json; 4 | using System.Text.Json.Serialization; 5 | 6 | namespace Todoist.Net.Serialization.Converters 7 | { 8 | internal sealed class DateOnlyConverter : JsonConverter 9 | { 10 | private const string CustomDateFormat = "yyyy-MM-dd"; 11 | 12 | public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 13 | { 14 | return DateTime.Parse(reader.GetString(), CultureInfo.InvariantCulture, DateTimeStyles.None); 15 | } 16 | 17 | public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) 18 | { 19 | writer.WriteStringValue(value.ToString(CustomDateFormat)); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Todoist.Net/Serialization/Converters/StringEnumTypeConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.Json; 3 | using System.Text.Json.Serialization; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Serialization.Converters 8 | { 9 | internal sealed class StringEnumTypeConverter : JsonConverterFactory 10 | { 11 | public override bool CanConvert(Type typeToConvert) 12 | { 13 | return typeToConvert.IsSubclassOf(typeof(StringEnum)); 14 | } 15 | 16 | public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) 17 | { 18 | return (JsonConverter)Activator.CreateInstance(typeof(StringEnumTypeConverterInner<>).MakeGenericType(typeToConvert)); 19 | } 20 | 21 | 22 | private sealed class StringEnumTypeConverterInner : JsonConverter where T : StringEnum 23 | { 24 | public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) 25 | { 26 | if (StringEnum.TryParse(reader.GetString(), out T stringEnum)) 27 | { 28 | return stringEnum; 29 | } 30 | 31 | return null; 32 | } 33 | 34 | public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) 35 | { 36 | writer.WriteStringValue(value.Value); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/ActivityService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | /// 10 | /// Contains operations for Todoist log management. 11 | /// 12 | internal class ActivityService : IActivityService 13 | { 14 | private readonly IAdvancedTodoistClient _todoistClient; 15 | 16 | internal ActivityService(IAdvancedTodoistClient todoistClient) 17 | { 18 | _todoistClient = todoistClient; 19 | } 20 | 21 | /// 22 | public Task GetAsync(LogFilter filter = null, CancellationToken cancellationToken = default) 23 | { 24 | var parameters = filter != null ? filter.ToParameters() : new List>(); 25 | 26 | return _todoistClient.GetAsync("activity/get", parameters, cancellationToken); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/BackupService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | /// 10 | /// Contains operations for Todoist backups management. 11 | /// 12 | internal class BackupService : IBackupService 13 | { 14 | private readonly IAdvancedTodoistClient _todoistClient; 15 | 16 | internal BackupService(IAdvancedTodoistClient todoistClient) 17 | { 18 | _todoistClient = todoistClient; 19 | } 20 | 21 | /// 22 | public Task> GetAsync(CancellationToken cancellationToken = default) 23 | { 24 | return _todoistClient.GetAsync>( 25 | "backups/get", 26 | new List>(), 27 | cancellationToken); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/CommandServiceBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | using Todoist.Net.Models; 8 | 9 | namespace Todoist.Net.Services 10 | { 11 | internal abstract class CommandServiceBase 12 | { 13 | private readonly ICollection _queue; 14 | 15 | protected CommandServiceBase(IAdvancedTodoistClient todoistClient) 16 | { 17 | TodoistClient = todoistClient; 18 | } 19 | 20 | protected CommandServiceBase(ICollection queue) 21 | { 22 | _queue = queue; 23 | } 24 | 25 | internal IAdvancedTodoistClient TodoistClient { get; } 26 | 27 | internal Command CreateAddCommand(CommandType commandType, T entity) where T : BaseEntity 28 | { 29 | var tempId = entity.Id.TempId; 30 | if (tempId == Guid.Empty) 31 | { 32 | tempId = Guid.NewGuid(); 33 | } 34 | entity.Id = tempId; 35 | 36 | return new Command(commandType, entity, tempId); 37 | } 38 | 39 | internal Command CreateEntityCommand(CommandType commandType, ComplexId id) 40 | { 41 | return new Command(commandType, new BaseEntity(id)); 42 | } 43 | 44 | /// 45 | /// Executes the command asynchronous. 46 | /// 47 | /// The command. 48 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 49 | /// Returns .The task object representing the asynchronous operation. 50 | /// API exception. 51 | /// Command execution exception. 52 | internal async Task ExecuteCommandAsync(Command command, CancellationToken cancellationToken = default) 53 | { 54 | if (_queue == null) 55 | { 56 | await TodoistClient.ExecuteCommandsAsync(cancellationToken, command).ConfigureAwait(false); 57 | return; 58 | } 59 | 60 | _queue.Add(command); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/EmailService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for Todoist email management. 12 | /// 13 | /// 14 | public class EmailService : IEmailService 15 | { 16 | private readonly IAdvancedTodoistClient _todoistClient; 17 | 18 | internal EmailService(IAdvancedTodoistClient todoistClient) 19 | { 20 | _todoistClient = todoistClient; 21 | } 22 | 23 | /// 24 | public Task DisableAsync(ObjectType objectType, ComplexId objectId, CancellationToken cancellationToken = default) 25 | { 26 | var parameters = CreateParameters(objectType, objectId); 27 | 28 | return _todoistClient.PostRawAsync("emails/disable", parameters, cancellationToken); 29 | } 30 | 31 | /// 32 | public Task GetOrCreateAsync(ObjectType objectType, ComplexId objectId, CancellationToken cancellationToken = default) 33 | { 34 | var parameters = CreateParameters(objectType, objectId); 35 | 36 | return _todoistClient.PostAsync("emails/get_or_create", parameters, cancellationToken); 37 | } 38 | 39 | private static List> CreateParameters(ObjectType objectType, ComplexId objectId) 40 | { 41 | if (objectType == null) 42 | { 43 | throw new ArgumentNullException(nameof(objectType)); 44 | } 45 | 46 | var parameters = 47 | new List> 48 | { 49 | new KeyValuePair( 50 | "obj_type", 51 | objectType.ToString()), 52 | new KeyValuePair( 53 | "obj_id", 54 | objectId.ToString()) 55 | }; 56 | return parameters; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/FiltersCommandService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | internal class FiltersCommandService : CommandServiceBase, IFiltersCommandService 11 | { 12 | internal FiltersCommandService(IAdvancedTodoistClient todoistClient) 13 | : base(todoistClient) 14 | { 15 | } 16 | 17 | internal FiltersCommandService(ICollection queue) 18 | : base(queue) 19 | { 20 | } 21 | 22 | /// 23 | public async Task AddAsync(Filter filter, CancellationToken cancellationToken = default) 24 | { 25 | if (filter == null) 26 | { 27 | throw new ArgumentNullException(nameof(filter)); 28 | } 29 | 30 | var command = CreateAddCommand(CommandType.AddFilter, filter); 31 | await ExecuteCommandAsync(command, cancellationToken).ConfigureAwait(false); 32 | 33 | return filter.Id; 34 | } 35 | 36 | /// 37 | public Task DeleteAsync(ComplexId id, CancellationToken cancellationToken = default) 38 | { 39 | var command = CreateEntityCommand(CommandType.DeleteFilter, id); 40 | return ExecuteCommandAsync(command, cancellationToken); 41 | } 42 | 43 | /// 44 | public Task UpdateAsync(Filter filter, CancellationToken cancellationToken = default) 45 | { 46 | if (filter == null) 47 | { 48 | throw new ArgumentNullException(nameof(filter)); 49 | } 50 | 51 | var command = new Command(CommandType.UpdateFilter, filter); 52 | return ExecuteCommandAsync(command, cancellationToken); 53 | } 54 | 55 | /// 56 | public Task UpdateOrderAsync(params OrderEntry[] orderEntries) => UpdateOrderAsync(CancellationToken.None, orderEntries); 57 | 58 | /// 59 | public Task UpdateOrderAsync(CancellationToken cancellationToken, params OrderEntry[] orderEntries) 60 | { 61 | if (orderEntries == null) 62 | { 63 | throw new ArgumentNullException(nameof(orderEntries)); 64 | } 65 | 66 | var command = new Command(CommandType.UpdateOrderFilter, new IdToOrderMappingArgument(orderEntries)); 67 | return ExecuteCommandAsync(command, cancellationToken); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/FiltersService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | /// 10 | /// Contains operations for filters management. 11 | /// 12 | internal class FiltersService : FiltersCommandService, IFiltersService 13 | { 14 | internal FiltersService(IAdvancedTodoistClient todoistClient) 15 | : base(todoistClient) 16 | { 17 | } 18 | 19 | /// 20 | public async Task> GetAsync(CancellationToken cancellationToken = default) 21 | { 22 | var response = await TodoistClient.GetResourcesAsync(cancellationToken, ResourceType.Filters).ConfigureAwait(false); 23 | 24 | return response.Filters; 25 | } 26 | 27 | /// 28 | public Task GetAsync(ComplexId id, CancellationToken cancellationToken = default) 29 | { 30 | return TodoistClient.PostAsync( 31 | "filters/get", 32 | new List> 33 | { 34 | new KeyValuePair("filter_id", id.ToString()) 35 | }, 36 | cancellationToken); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/IActivityService.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | /// 10 | /// Contains operations for Todoist log management. 11 | /// 12 | public interface IActivityService 13 | { 14 | /// 15 | /// Gets list of activity logs. 16 | /// 17 | /// The filter. 18 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 19 | /// The activity log entries. 20 | /// API exception. 21 | /// The activity log is only available for Todoist Premium. 22 | Task GetAsync(LogFilter filter = null, CancellationToken cancellationToken = default); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/IBackupService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for Todoist backups management. 12 | /// 13 | public interface IBackupService 14 | { 15 | /// 16 | /// Gets list of recent backup archives asynchronous. 17 | /// 18 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 19 | /// The backups information. 20 | /// Todoist creates a backup archive of users' data on a daily basis. Backup archives can also be accessed from the web app (Todoist Settings -> Backups). 21 | /// API exception. 22 | Task> GetAsync(CancellationToken cancellationToken = default); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/IEmailService.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | /// 10 | /// Contains operations for Todoist email management. 11 | /// 12 | public interface IEmailService 13 | { 14 | /// 15 | /// Disables an email address for an object. 16 | /// 17 | /// Type of the object. 18 | /// The object identifier. 19 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 20 | /// Returns .The task object representing the asynchronous operation. 21 | /// API exception. 22 | Task DisableAsync(ObjectType objectType, ComplexId objectId, CancellationToken cancellationToken = default); 23 | 24 | /// 25 | /// Creates a new email address for an object, or gets an existing email. 26 | /// 27 | /// Type of the object. 28 | /// The object identifier. 29 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 30 | /// 31 | /// The email information. 32 | /// 33 | /// API exception. 34 | Task GetOrCreateAsync(ObjectType objectType, ComplexId objectId, CancellationToken cancellationToken = default); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/IFiltersService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for filters management. 12 | /// 13 | /// Filters are only available for Todoist Premium users. 14 | public interface IFiltersService : IFiltersCommandService 15 | { 16 | /// 17 | /// Gets all filters. 18 | /// 19 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 20 | /// The filters. 21 | /// API exception. 22 | Task> GetAsync(CancellationToken cancellationToken = default); 23 | 24 | /// 25 | /// Gets a filter info by ID. 26 | /// 27 | /// The ID of the filter. 28 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 29 | /// 30 | /// The filter info. 31 | /// 32 | /// API exception. 33 | Task GetAsync(ComplexId id, CancellationToken cancellationToken = default); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/IItemsService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | using Todoist.Net.Models; 8 | 9 | namespace Todoist.Net.Services 10 | { 11 | /// 12 | /// Contains methods for Todoist tasks management. 13 | /// 14 | /// 15 | public interface IItemsService : IItemsCommandService 16 | { 17 | /// 18 | /// Gets all items. 19 | /// 20 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 21 | /// The items. 22 | /// API exception. 23 | Task> GetAsync(CancellationToken cancellationToken = default); 24 | 25 | /// 26 | /// Gets an item by ID. 27 | /// 28 | /// The ID of the item. 29 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 30 | /// 31 | /// The item. 32 | /// 33 | /// API exception. 34 | Task GetAsync(ComplexId id, CancellationToken cancellationToken = default); 35 | 36 | /// 37 | /// Gets all the user’s completed items (tasks). 38 | /// 39 | /// The filter. 40 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 41 | /// 42 | /// The completed items. 43 | /// 44 | /// API exception. 45 | /// Only available for Todoist Premium users. 46 | Task GetCompletedAsync(ItemFilter filter = null, CancellationToken cancellationToken = default); 47 | 48 | /// 49 | /// Add a task. Implementation of the Quick Add Task available in the official clients. 50 | /// 51 | /// The quick add item. 52 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 53 | /// The created task. 54 | /// is 55 | Task QuickAddAsync(QuickAddItem quickAddItem, CancellationToken cancellationToken = default); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/ILabelsService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for labels management. 12 | /// 13 | /// 14 | public interface ILabelsService : ILabelsCommandService 15 | { 16 | /// 17 | /// Gets all labels. 18 | /// 19 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 20 | /// The labels. 21 | /// API exception. 22 | Task> GetAsync(CancellationToken cancellationToken = default); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/INotesServices.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | /// 10 | /// Contains operations for notes management. 11 | /// 12 | /// 13 | public interface INotesServices : INotesCommandServices 14 | { 15 | /// 16 | /// Gets all notes. 17 | /// 18 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 19 | /// The notes. 20 | /// API exception. 21 | Task GetAsync(CancellationToken cancellationToken = default); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/INotificationsCommandService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for Todoist notification management which can be executes in a transaction. 12 | /// 13 | public interface INotificationsCommandService 14 | { 15 | /// 16 | /// Marks the last read live notification. 17 | /// 18 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 19 | /// Returns .The task object representing the asynchronous operation. 20 | /// Command execution exception. 21 | /// API exception. 22 | Task MarkAllReadAsync(CancellationToken cancellationToken = default); 23 | 24 | /// 25 | /// Marks the last read live notification. 26 | /// 27 | /// The ID of the last read notification. 28 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 29 | /// Returns .The task object representing the asynchronous operation. 30 | /// Command execution exception. 31 | /// API exception. 32 | Task MarkLastReadAsync(ComplexId id, CancellationToken cancellationToken = default); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/INotificationsService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for Todoist notification management. 12 | /// 13 | public interface INotificationsService : INotificationsCommandService 14 | { 15 | /// 16 | /// Gets all live notifications. 17 | /// 18 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 19 | /// List of the notifications. 20 | /// API exception. 21 | Task> GetAsync(CancellationToken cancellationToken = default); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/IProjectsService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains methods for projects management. 12 | /// 13 | /// 14 | public interface IProjectsService : IProjectCommandService 15 | { 16 | /// 17 | /// Gets archived projects. 18 | /// 19 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 20 | /// 21 | /// The archived projects. 22 | /// 23 | /// API exception. 24 | Task> GetArchivedAsync(CancellationToken cancellationToken = default); 25 | 26 | /// 27 | /// Gets all projects. 28 | /// 29 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 30 | /// The projects. 31 | /// API exception. 32 | Task> GetAsync(CancellationToken cancellationToken = default); 33 | 34 | /// 35 | /// Gets project by ID. 36 | /// 37 | /// The ID of the project. 38 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 39 | /// 40 | /// The project. 41 | /// 42 | /// API exception. 43 | Task GetAsync(ComplexId id, CancellationToken cancellationToken = default); 44 | 45 | /// 46 | /// Gets a project’s uncompleted items. 47 | /// 48 | /// The ID of the project. 49 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 50 | /// 51 | /// The project data. 52 | /// 53 | /// API exception. 54 | Task GetDataAsync(ComplexId id, CancellationToken cancellationToken = default); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/IReminersService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for reminders management. 12 | /// 13 | public interface IRemindersService : IRemindersCommandService 14 | { 15 | /// 16 | /// Gets all reminders. 17 | /// 18 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 19 | /// The filters. 20 | /// API exception. 21 | Task> GetAsync(CancellationToken cancellationToken = default); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/ISectionService.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | /// 10 | /// Contains methods for sections management. 11 | /// 12 | /// 13 | public interface ISectionService : ISectionsCommandService 14 | { 15 | /// 16 | /// Gets a section by ID. 17 | /// 18 | /// The ID of the section. 19 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 20 | /// 21 | /// The section. 22 | /// 23 | /// API exception. 24 | Task
GetAsync(ComplexId id, CancellationToken cancellationToken = default); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/ISharingService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains methods for sharing management. 12 | /// 13 | public interface ISharingService : ISharingCommandService 14 | { 15 | /// 16 | /// Gets all collaborators. 17 | /// 18 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 19 | /// The collaborators. 20 | /// API exception. 21 | Task> GetCollaboratorsAsync(CancellationToken cancellationToken = default); 22 | 23 | /// 24 | /// Gets all collaborator states. 25 | /// 26 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 27 | /// The collaborator states. 28 | /// API exception. 29 | Task> GetCollaboratorStatesAsync(CancellationToken cancellationToken = default); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/ITemplateService.cs: -------------------------------------------------------------------------------- 1 | using System.Net.Http; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | /// 10 | /// Contains operations for templates management. 11 | /// 12 | /// Templates are only available for Todoist Premium users. 13 | public interface ITemplateService 14 | { 15 | /// 16 | /// Gets a template for the project as a file asynchronous. 17 | /// 18 | /// The project identifier. 19 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 20 | /// The CSV template is returned. 21 | /// API exception. 22 | Task ExportAsFileAsync(ComplexId projectId, CancellationToken cancellationToken = default); 23 | 24 | /// 25 | /// Gets a template for the project as a shareable URL asynchronous. 26 | /// 27 | /// The project identifier. 28 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 29 | /// The file object of the template. 30 | /// API exception. 31 | Task ExportAsShareableUrlAsync(ComplexId projectId, CancellationToken cancellationToken = default); 32 | 33 | /// 34 | /// Imports a template into a project asynchronous. 35 | /// 36 | /// The project identifier. 37 | /// Content of the template. 38 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 39 | /// Returns .The task object representing the asynchronous operation. 40 | /// API exception. 41 | Task ImportIntoProjectAsync(ComplexId projectId, byte[] fileContent, CancellationToken cancellationToken = default); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/ITransaction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | namespace Todoist.Net.Services 7 | { 8 | /// 9 | /// Represents a Transaction 10 | /// 11 | public interface ITransaction 12 | { 13 | /// 14 | /// Gets or sets the filters. 15 | /// 16 | /// The filters. 17 | /// Filters are only available for Todoist Premium users. 18 | IFiltersCommandService Filters { get; set; } 19 | 20 | /// 21 | /// Gets the items service. 22 | /// 23 | /// The items service. 24 | IItemsCommandService Items { get; } 25 | 26 | /// 27 | /// Gets the labels service. 28 | /// 29 | /// The labels service. 30 | ILabelsCommandService Labels { get; } 31 | 32 | /// 33 | /// Gets the notes service. 34 | /// 35 | /// The notes service. 36 | INotesCommandServices Notes { get; } 37 | 38 | /// 39 | /// Gets the notifications service. 40 | /// 41 | /// The notifications service. 42 | INotificationsCommandService Notifications { get; } 43 | 44 | /// 45 | /// Gets the project. 46 | /// 47 | /// The project. 48 | IProjectCommandService Project { get; } 49 | 50 | /// 51 | /// Gets the reminders. 52 | /// 53 | /// The reminders. 54 | /// Reminders are only available for Todoist Premium users. 55 | IRemindersCommandService Reminders { get; } 56 | 57 | /// 58 | /// Gets the sharing. 59 | /// 60 | /// 61 | /// The sharing. 62 | /// 63 | ISharingCommandService Sharing { get; } 64 | 65 | /// 66 | /// Gets the users. 67 | /// 68 | /// The users. 69 | IUsersCommandService Users { get; } 70 | 71 | /// 72 | /// Commits the transaction asynchronous. 73 | /// 74 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 75 | /// 76 | /// Returns . The task object representing the asynchronous operation 77 | /// that at completion returns the transaction sync_token. 78 | /// 79 | /// Command execution exception. 80 | /// API exception. 81 | Task CommitAsync(CancellationToken cancellationToken = default); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/IUploadService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for file attachments management. 12 | /// 13 | public interface IUploadService 14 | { 15 | /// 16 | /// Deletes a file asynchronous. 17 | /// 18 | /// The file URL. 19 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 20 | /// Returns .The task object representing the asynchronous operation. 21 | /// API exception. 22 | Task DeleteAsync(string fileUrl, CancellationToken cancellationToken = default); 23 | 24 | /// 25 | /// Gets all uploads. 26 | /// 27 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 28 | /// 29 | /// The uploads. 30 | /// 31 | /// API exception. 32 | Task> GetAsync(CancellationToken cancellationToken = default); 33 | 34 | /// 35 | /// Uploads a file asynchronous. 36 | /// 37 | /// Name of the file. 38 | /// Content of the file. 39 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 40 | /// The uploaded file. 41 | /// API exception. 42 | Task UploadAsync(string fileName, byte[] fileContent, CancellationToken cancellationToken = default); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/IUsersCommandService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for users management which can be executed in a transaction. 12 | /// 13 | public interface IUsersCommandService 14 | { 15 | /// 16 | /// Gets the current user info. 17 | /// 18 | /// The user. 19 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 20 | /// The current user info. 21 | /// API exception. 22 | /// is 23 | /// Command execution exception. 24 | Task UpdateAsync(User user, CancellationToken cancellationToken = default); 25 | 26 | /// 27 | /// Gets the current user info. 28 | /// 29 | /// The karma goals. 30 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 31 | /// The current user info. 32 | /// API exception. 33 | /// Command execution exception. 34 | /// is 35 | Task UpdateKarmaGoalsAsync(KarmaGoals karmaGoals, CancellationToken cancellationToken = default); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/IUsersService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for users management. 12 | /// 13 | public interface IUsersService : IUsersCommandService 14 | { 15 | /// 16 | /// Deletes the current user. 17 | /// 18 | /// The user password. 19 | /// The reason. 20 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 21 | /// The label info. 22 | /// API exception. 23 | /// API exception. 24 | Task DeleteAsync(string userPassword, string reason = null, CancellationToken cancellationToken = default); 25 | 26 | /// 27 | /// Gets the current user info. 28 | /// 29 | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. 30 | /// The current user info. 31 | /// API exception. 32 | Task GetCurrentAsync(CancellationToken cancellationToken = default); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/ItemsService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains methods for Todoist tasks management. 12 | /// 13 | /// 14 | /// 15 | internal class ItemsService : ItemsCommandService, IItemsService 16 | { 17 | /// 18 | /// Initializes a new instance of the class. 19 | /// 20 | /// The todoist client. 21 | internal ItemsService(IAdvancedTodoistClient todoistClient) 22 | : base(todoistClient) 23 | { 24 | } 25 | 26 | /// 27 | public async Task> GetAsync(CancellationToken cancellationToken = default) 28 | { 29 | var response = await TodoistClient.GetResourcesAsync(cancellationToken, ResourceType.Items).ConfigureAwait(false); 30 | 31 | return response.Items; 32 | } 33 | 34 | /// 35 | public Task GetAsync(ComplexId id, CancellationToken cancellationToken = default) 36 | { 37 | return TodoistClient.PostAsync( 38 | "items/get", 39 | new List> 40 | { 41 | new KeyValuePair( 42 | "item_id", 43 | id.ToString()) 44 | }, 45 | cancellationToken); 46 | } 47 | 48 | /// 49 | public Task GetCompletedAsync(ItemFilter filter = null, CancellationToken cancellationToken = default) 50 | { 51 | var parameters = filter == null ? new List>() : filter.ToParameters(); 52 | 53 | return TodoistClient.GetAsync("completed/get_all", parameters, cancellationToken); 54 | } 55 | 56 | /// 57 | public Task QuickAddAsync(QuickAddItem quickAddItem, CancellationToken cancellationToken = default) 58 | { 59 | if (quickAddItem == null) 60 | { 61 | throw new ArgumentNullException(nameof(quickAddItem)); 62 | } 63 | 64 | return TodoistClient.PostAsync("quick/add", quickAddItem.ToParameters(), cancellationToken); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/LabelsCommandService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for labels management which can be executes in a transaction. 12 | /// 13 | /// 14 | /// 15 | internal class LabelsCommandService : CommandServiceBase, ILabelsCommandService 16 | { 17 | internal LabelsCommandService(IAdvancedTodoistClient todoistClient) 18 | : base(todoistClient) 19 | { 20 | } 21 | 22 | internal LabelsCommandService(ICollection queue) 23 | : base(queue) 24 | { 25 | } 26 | 27 | /// 28 | public async Task AddAsync(Label label, CancellationToken cancellationToken = default) 29 | { 30 | if (label == null) 31 | { 32 | throw new ArgumentNullException(nameof(label)); 33 | } 34 | 35 | var command = CreateAddCommand(CommandType.AddLabel, label); 36 | await ExecuteCommandAsync(command, cancellationToken).ConfigureAwait(false); 37 | 38 | return label.Id; 39 | } 40 | 41 | /// 42 | public Task DeleteAsync(ComplexId id, CancellationToken cancellationToken = default) 43 | { 44 | var command = CreateEntityCommand(CommandType.DeleteLabel, id); 45 | return ExecuteCommandAsync(command, cancellationToken); 46 | } 47 | 48 | /// 49 | public Task UpdateAsync(Label label, CancellationToken cancellationToken = default) 50 | { 51 | if (label == null) 52 | { 53 | throw new ArgumentNullException(nameof(label)); 54 | } 55 | 56 | var command = new Command(CommandType.UpdateLabel, label); 57 | return ExecuteCommandAsync(command, cancellationToken); 58 | } 59 | 60 | /// 61 | public Task UpdateOrderAsync(params OrderEntry[] orderEntries) => UpdateOrderAsync(CancellationToken.None, orderEntries); 62 | 63 | /// 64 | public Task UpdateOrderAsync(CancellationToken cancellationToken, params OrderEntry[] orderEntries) 65 | { 66 | if (orderEntries == null) 67 | { 68 | throw new ArgumentNullException(nameof(orderEntries)); 69 | } 70 | 71 | var command = new Command(CommandType.UpdateOrderLabel, new IdToOrderMappingArgument(orderEntries)); 72 | return ExecuteCommandAsync(command, cancellationToken); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/LabelsService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | /// 10 | /// Contains operations for labels management. 11 | /// 12 | /// 13 | /// 14 | internal class LabelsService : LabelsCommandService, ILabelsService 15 | { 16 | internal LabelsService(IAdvancedTodoistClient todoistClient) 17 | : base(todoistClient) 18 | { 19 | } 20 | 21 | /// 22 | public async Task> GetAsync(CancellationToken cancellationToken = default) 23 | { 24 | var response = await TodoistClient.GetResourcesAsync(cancellationToken, ResourceType.Labels).ConfigureAwait(false); 25 | 26 | return response.Labels; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/NotesCommandService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for notes management which can be executes in a transaction. 12 | /// 13 | /// 14 | /// 15 | internal class NotesCommandService : CommandServiceBase, INotesCommandServices 16 | { 17 | internal NotesCommandService(IAdvancedTodoistClient todoistClient) 18 | : base(todoistClient) 19 | { 20 | } 21 | 22 | internal NotesCommandService(ICollection queue) 23 | : base(queue) 24 | { 25 | } 26 | 27 | /// 28 | public async Task AddToItemAsync(Note note, ComplexId itemId, CancellationToken cancellationToken = default) 29 | { 30 | if (note == null) 31 | { 32 | throw new ArgumentNullException(nameof(note)); 33 | } 34 | 35 | note.ItemId = itemId; 36 | 37 | var command = CreateAddCommand(CommandType.AddNote, note); 38 | await ExecuteCommandAsync(command, cancellationToken).ConfigureAwait(false); 39 | 40 | return note.Id; 41 | } 42 | 43 | /// 44 | public async Task AddToProjectAsync(Note note, ComplexId projectId, CancellationToken cancellationToken = default) 45 | { 46 | if (note == null) 47 | { 48 | throw new ArgumentNullException(nameof(note)); 49 | } 50 | 51 | note.ProjectId = projectId; 52 | 53 | var command = CreateAddCommand(CommandType.AddNote, note); 54 | await ExecuteCommandAsync(command, cancellationToken).ConfigureAwait(false); 55 | 56 | return note.Id; 57 | } 58 | 59 | /// 60 | public Task DeleteAsync(ComplexId id, CancellationToken cancellationToken = default) 61 | { 62 | var command = CreateEntityCommand(CommandType.DeleteNote, id); 63 | return ExecuteCommandAsync(command, cancellationToken); 64 | } 65 | 66 | /// 67 | public Task UpdateAsync(Note note, CancellationToken cancellationToken = default) 68 | { 69 | if (note == null) 70 | { 71 | throw new ArgumentNullException(nameof(note)); 72 | } 73 | 74 | var command = new Command(CommandType.UpdateNote, note); 75 | return ExecuteCommandAsync(command, cancellationToken); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/NotesService.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | 4 | using Todoist.Net.Models; 5 | 6 | namespace Todoist.Net.Services 7 | { 8 | /// 9 | /// Contains operations for notes management. 10 | /// 11 | /// 12 | /// 13 | internal class NotesService : NotesCommandService, INotesServices 14 | { 15 | internal NotesService(IAdvancedTodoistClient todoistClient) 16 | : base(todoistClient) 17 | { 18 | } 19 | 20 | /// 21 | public async Task GetAsync(CancellationToken cancellationToken = default) 22 | { 23 | var response = await TodoistClient.GetResourcesAsync(cancellationToken, ResourceType.Notes).ConfigureAwait(false); 24 | 25 | return new NotesInfo 26 | { 27 | ItemNotes = response.Notes, 28 | ProjectNotes = response.ProjectNotes 29 | }; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/NotificationsCommandService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | internal class NotificationsCommandService : CommandServiceBase, INotificationsCommandService 10 | { 11 | internal NotificationsCommandService(IAdvancedTodoistClient todoistClient) 12 | : base(todoistClient) 13 | { 14 | } 15 | 16 | internal NotificationsCommandService(ICollection queue) 17 | : base(queue) 18 | { 19 | } 20 | 21 | /// 22 | public Task MarkAllReadAsync(CancellationToken cancellationToken = default) 23 | { 24 | var command = CreateEntityCommand(CommandType.SetLastReadNotification, null); 25 | return ExecuteCommandAsync(command, cancellationToken); 26 | } 27 | 28 | /// 29 | public Task MarkLastReadAsync(ComplexId id, CancellationToken cancellationToken = default) 30 | { 31 | var command = CreateEntityCommand(CommandType.SetLastReadNotification, id); 32 | return ExecuteCommandAsync(command, cancellationToken); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/NotificationsService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | internal class NotificationsService : NotificationsCommandService, INotificationsService 10 | { 11 | public NotificationsService(IAdvancedTodoistClient todoistClient) 12 | : base(todoistClient) 13 | { 14 | } 15 | 16 | public NotificationsService(ICollection queue) 17 | : base(queue) 18 | { 19 | } 20 | 21 | /// 22 | public async Task> GetAsync(CancellationToken cancellationToken = default) 23 | { 24 | var response = await TodoistClient.GetResourcesAsync(cancellationToken, ResourceType.Notifications).ConfigureAwait(false); 25 | 26 | return response.Notifications; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/ProjectsService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | /// 10 | /// Contains methods for projects management. 11 | /// 12 | /// 13 | /// 14 | internal class ProjectsService : ProjectsCommandService, IProjectsService 15 | { 16 | internal ProjectsService(IAdvancedTodoistClient todoistClient) 17 | : base(todoistClient) 18 | { 19 | } 20 | 21 | /// 22 | public Task> GetArchivedAsync(CancellationToken cancellationToken = default) 23 | { 24 | return TodoistClient.GetAsync>( 25 | "projects/get_archived", 26 | new List>(), 27 | cancellationToken); 28 | } 29 | 30 | /// 31 | public async Task> GetAsync(CancellationToken cancellationToken = default) 32 | { 33 | var response = await TodoistClient.GetResourcesAsync(cancellationToken, ResourceType.Projects).ConfigureAwait(false); 34 | 35 | return response.Projects; 36 | } 37 | 38 | /// 39 | public Task GetAsync(ComplexId id, CancellationToken cancellationToken = default) 40 | { 41 | return TodoistClient.PostAsync( 42 | "projects/get", 43 | new List> 44 | { 45 | new KeyValuePair("project_id", id.ToString()) 46 | }, 47 | cancellationToken); 48 | } 49 | 50 | /// 51 | public Task GetDataAsync(ComplexId id, CancellationToken cancellationToken = default) 52 | { 53 | return TodoistClient.PostAsync( 54 | "projects/get_data", 55 | new List> 56 | { 57 | new KeyValuePair("project_id", id.ToString()) 58 | }, 59 | cancellationToken); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/ReminersCommandService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | internal class RemindersCommandService : CommandServiceBase, IRemindersCommandService 11 | { 12 | internal RemindersCommandService(IAdvancedTodoistClient todoistClient) 13 | : base(todoistClient) 14 | { 15 | } 16 | 17 | internal RemindersCommandService(ICollection queue) 18 | : base(queue) 19 | { 20 | } 21 | 22 | /// 23 | public async Task AddAsync(Reminder reminder, CancellationToken cancellationToken = default) 24 | { 25 | if (reminder == null) 26 | { 27 | throw new ArgumentNullException(nameof(reminder)); 28 | } 29 | 30 | var command = CreateAddCommand(CommandType.AddReminder, reminder); 31 | await ExecuteCommandAsync(command, cancellationToken).ConfigureAwait(false); 32 | 33 | return reminder.Id; 34 | } 35 | 36 | /// 37 | public Task ClearLocationsAsync(CancellationToken cancellationToken = default) 38 | { 39 | var command = new Command(CommandType.ClearLocations, EmptyCommand.Instance); 40 | return ExecuteCommandAsync(command, cancellationToken); 41 | } 42 | 43 | /// 44 | public Task DeleteAsync(ComplexId id, CancellationToken cancellationToken = default) 45 | { 46 | var command = CreateEntityCommand(CommandType.DeleteReminder, id); 47 | return ExecuteCommandAsync(command,cancellationToken); 48 | } 49 | 50 | /// 51 | public Task UpdateAsync(Reminder reminder, CancellationToken cancellationToken = default) 52 | { 53 | if (reminder == null) 54 | { 55 | throw new ArgumentNullException(nameof(reminder)); 56 | } 57 | 58 | var command = new Command(CommandType.UpdateReminder, reminder); 59 | return ExecuteCommandAsync(command, cancellationToken); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/ReminersService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | /// 10 | /// Contains operations for reminders management. 11 | /// 12 | internal class RemindersService : RemindersCommandService, IRemindersService 13 | { 14 | internal RemindersService(IAdvancedTodoistClient todoistClient) 15 | : base(todoistClient) 16 | { 17 | } 18 | 19 | /// 20 | public async Task> GetAsync(CancellationToken cancellationToken = default) 21 | { 22 | var response = await TodoistClient.GetResourcesAsync(cancellationToken, ResourceType.Reminders).ConfigureAwait(false); 23 | 24 | return response.Reminders; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/SectionService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | 5 | using Todoist.Net.Models; 6 | 7 | namespace Todoist.Net.Services 8 | { 9 | /// 10 | /// Contains methods for sections management. 11 | /// 12 | /// 13 | /// 14 | internal class SectionService : SectionsCommandService, ISectionService 15 | { 16 | internal SectionService(IAdvancedTodoistClient todoistClient) 17 | : base(todoistClient) 18 | { 19 | } 20 | 21 | /// 22 | public Task
GetAsync(ComplexId id, CancellationToken cancellationToken = default) 23 | { 24 | return TodoistClient.PostAsync
( 25 | "sections/get", 26 | new List> 27 | { 28 | new KeyValuePair("section_id", id.ToString()) 29 | }, 30 | cancellationToken); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/SharingService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | using System.Threading; 4 | using Todoist.Net.Models; 5 | 6 | namespace Todoist.Net.Services 7 | { 8 | /// 9 | /// Contains methods for sharing management. 10 | /// 11 | /// 12 | internal class SharingService : SharingCommandService, ISharingService 13 | { 14 | public SharingService(IAdvancedTodoistClient todoistClient) 15 | : base(todoistClient) 16 | { 17 | } 18 | 19 | /// 20 | public async Task> GetCollaboratorsAsync(CancellationToken cancellationToken = default) 21 | { 22 | var response = await TodoistClient.GetResourcesAsync(cancellationToken, ResourceType.Collaborators).ConfigureAwait(false); 23 | 24 | return response.Collaborators; 25 | } 26 | 27 | /// 28 | public async Task> GetCollaboratorStatesAsync(CancellationToken cancellationToken = default) 29 | { 30 | var response = await TodoistClient.GetResourcesAsync(cancellationToken, ResourceType.Collaborators).ConfigureAwait(false); 31 | 32 | return response.CollaboratorStates; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/TemplateService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | internal class TemplateService : ITemplateService 11 | { 12 | private readonly IAdvancedTodoistClient _todoistClient; 13 | 14 | public TemplateService(IAdvancedTodoistClient todoistClient) 15 | { 16 | _todoistClient = todoistClient; 17 | } 18 | 19 | /// 20 | public Task ExportAsFileAsync(ComplexId projectId, CancellationToken cancellationToken = default) 21 | { 22 | var parameters = new List> 23 | { 24 | new KeyValuePair("project_id", projectId.ToString()) 25 | }; 26 | return _todoistClient.PostRawAsync("templates/export_as_file", parameters, cancellationToken); 27 | } 28 | 29 | /// 30 | public Task ExportAsShareableUrlAsync(ComplexId projectId, CancellationToken cancellationToken = default) 31 | { 32 | var parameters = new List> 33 | { 34 | new KeyValuePair("project_id", projectId.ToString()) 35 | }; 36 | return _todoistClient.PostAsync("templates/export_as_url", parameters, cancellationToken); 37 | } 38 | 39 | /// 40 | public Task ImportIntoProjectAsync(ComplexId projectId, byte[] fileContent, CancellationToken cancellationToken = default) 41 | { 42 | var parameters = new List> 43 | { 44 | new KeyValuePair("project_id", projectId.ToString()) 45 | }; 46 | var files = new[] { new ByteArrayContent(fileContent) }; 47 | 48 | return _todoistClient.PostFormAsync("templates/import_into_project", parameters, files, cancellationToken); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/Transaction.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Represents a Transaction 12 | /// 13 | /// 14 | internal class Transaction : ITransaction 15 | { 16 | private readonly LinkedList _commands; 17 | 18 | private readonly IAdvancedTodoistClient _todoistClient; 19 | 20 | /// 21 | /// Initializes a new instance of the class. 22 | /// 23 | /// The client. 24 | internal Transaction(IAdvancedTodoistClient todoistClient) 25 | { 26 | _todoistClient = todoistClient; 27 | _commands = new LinkedList(); 28 | 29 | Project = new ProjectsCommandService(_commands); 30 | Notes = new NotesCommandService(_commands); 31 | Items = new ItemsCommandService(_commands); 32 | Labels = new LabelsCommandService(_commands); 33 | Notifications = new NotificationsCommandService(_commands); 34 | Filters = new FiltersCommandService(_commands); 35 | Reminders = new RemindersCommandService(_commands); 36 | Users = new UsersCommandService(_commands); 37 | Sharing = new SharingCommandService(_commands); 38 | } 39 | 40 | public IFiltersCommandService Filters { get; set; } 41 | 42 | public IItemsCommandService Items { get; } 43 | 44 | public ILabelsCommandService Labels { get; } 45 | 46 | public INotesCommandServices Notes { get; } 47 | 48 | public INotificationsCommandService Notifications { get; } 49 | 50 | public IProjectCommandService Project { get; } 51 | 52 | public IRemindersCommandService Reminders { get; } 53 | 54 | public ISharingCommandService Sharing { get; } 55 | 56 | public IUsersCommandService Users { get; } 57 | 58 | /// 59 | public async Task CommitAsync(CancellationToken cancellationToken = default) 60 | { 61 | try 62 | { 63 | return await _todoistClient.ExecuteCommandsAsync(cancellationToken, _commands.ToArray()).ConfigureAwait(false); 64 | } 65 | finally 66 | { 67 | _commands.Clear(); 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/UploadService.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Net.Http; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for file attachments management. 12 | /// 13 | /// 14 | internal class UploadService : IUploadService 15 | { 16 | private readonly IAdvancedTodoistClient _todoistClient; 17 | 18 | internal UploadService(IAdvancedTodoistClient todoistClient) 19 | { 20 | _todoistClient = todoistClient; 21 | } 22 | 23 | /// 24 | public Task DeleteAsync(string fileUrl, CancellationToken cancellationToken = default) 25 | { 26 | var parameters = new List> 27 | { 28 | new KeyValuePair("file_url", fileUrl) 29 | }; 30 | return _todoistClient.PostRawAsync("uploads/delete", parameters, cancellationToken); 31 | } 32 | 33 | /// 34 | public Task> GetAsync(CancellationToken cancellationToken = default) 35 | { 36 | return _todoistClient.GetAsync>( 37 | "uploads/get", 38 | new List>(), 39 | cancellationToken); 40 | } 41 | 42 | /// 43 | public Task UploadAsync(string fileName, byte[] fileContent, CancellationToken cancellationToken = default) 44 | { 45 | var parameters = new List> 46 | { 47 | new KeyValuePair("file_name", fileName) 48 | }; 49 | var files = new[] { new ByteArrayContent(fileContent) }; 50 | 51 | return _todoistClient.PostFormAsync("uploads/add", parameters, files, cancellationToken); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/UsersCommandService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | internal class UsersCommandService : CommandServiceBase, IUsersCommandService 11 | { 12 | internal UsersCommandService(IAdvancedTodoistClient todoistClient) 13 | : base(todoistClient) 14 | { 15 | } 16 | 17 | internal UsersCommandService(ICollection queue) 18 | : base(queue) 19 | { 20 | } 21 | 22 | /// 23 | public Task UpdateAsync(User user, CancellationToken cancellationToken = default) 24 | { 25 | if (user == null) 26 | { 27 | throw new ArgumentNullException(nameof(user)); 28 | } 29 | 30 | var command = new Command(CommandType.UpdateUser, user); 31 | 32 | return ExecuteCommandAsync(command, cancellationToken); 33 | } 34 | 35 | /// 36 | public Task UpdateKarmaGoalsAsync(KarmaGoals karmaGoals, CancellationToken cancellationToken = default) 37 | { 38 | if (karmaGoals == null) 39 | { 40 | throw new ArgumentNullException(nameof(karmaGoals)); 41 | } 42 | 43 | var command = new Command(CommandType.UpdateKarmaGoals, karmaGoals); 44 | 45 | return ExecuteCommandAsync(command, cancellationToken); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Todoist.Net/Services/UsersService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | 6 | using Todoist.Net.Models; 7 | 8 | namespace Todoist.Net.Services 9 | { 10 | /// 11 | /// Contains operations for users management. 12 | /// 13 | /// 14 | /// 15 | internal class UsersService : UsersCommandService, IUsersService 16 | { 17 | internal UsersService(IAdvancedTodoistClient todoistClient) 18 | : base(todoistClient) 19 | { 20 | } 21 | 22 | /// 23 | public Task DeleteAsync(string userPassword, string reason = null, CancellationToken cancellationToken = default) 24 | { 25 | if (userPassword == null) 26 | { 27 | throw new ArgumentNullException(nameof(userPassword)); 28 | } 29 | 30 | var parameters = new LinkedList>(); 31 | parameters.AddLast(new KeyValuePair("current_password", userPassword)); 32 | 33 | if (!string.IsNullOrEmpty(reason)) 34 | { 35 | parameters.AddLast(new KeyValuePair("reason_for_delete", reason)); 36 | } 37 | 38 | return TodoistClient.PostRawAsync("user/delete", parameters, cancellationToken); 39 | } 40 | 41 | /// 42 | public async Task GetCurrentAsync(CancellationToken cancellationToken = default) 43 | { 44 | var response = await TodoistClient.GetResourcesAsync(cancellationToken, ResourceType.User).ConfigureAwait(false); 45 | 46 | return response.UserInfo; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Todoist.Net/Todoist.Net.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | A Todoist API client for .NET 5 | 9.0.0 6 | Oleg Shevchenko, Ahmed Zaki 7 | netstandard2.0;net462 8 | true 9 | Todoist.Net 10 | 11 | Todoist.Net 12 | todoist 13 | https://github.com/olsh/todoist-net/releases 14 | https://github.com/olsh/todoist-net 15 | MIT 16 | git 17 | https://github.com/olsh/todoist-net 18 | todoist-net-nuget.png 19 | README.md 20 | 21 | $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb 22 | 23 | true 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | <_Parameter1>Todoist.Net.Tests 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /src/Todoist.Net/TodoistClientFactory.cs: -------------------------------------------------------------------------------- 1 | #if NETSTANDARD2_0 2 | 3 | using System.Net.Http; 4 | 5 | namespace Todoist.Net 6 | { 7 | internal sealed class TodoistClientFactory : ITodoistClientFactory 8 | { 9 | private readonly IHttpClientFactory _httpClientFactory; 10 | 11 | public TodoistClientFactory(IHttpClientFactory httpClientFactory) 12 | { 13 | _httpClientFactory = httpClientFactory; 14 | } 15 | 16 | /// 17 | public TodoistClient CreateClient(string token) 18 | { 19 | var httpClient = _httpClientFactory.CreateClient(); 20 | var todoistRestClient = new TodoistRestClient(token, httpClient); 21 | 22 | return new TodoistClient(todoistRestClient); 23 | } 24 | } 25 | } 26 | 27 | #endif 28 | --------------------------------------------------------------------------------