Пример #1
0
        async void Handle_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            if (e.Item == null)
            {
                return;
            }

            var action = await DisplayActionSheet("Action", "Cancel", null, new[] { "Done", "Edit" });

            ((ListView)sender).SelectedItem = null;

            if (action == "Done")
            {
                using (var client = new TodoistClient(ProjectBrowsePage.AuthKey))
                {
                    await client.Items.CompleteAsync(true, ((Item)e.Item).Id);

                    Items.Remove((Item)e.Item);
                }
            }
            else if (action == "Edit")
            {
                await DisplayAlert(":(", "Not implemented yet :(", "Ok");
            }
        }
Пример #2
0
        /// <summary>
        /// Builds client according to parameter.
        /// </summary>
        /// <param name="service">API service enum.</param>
        /// <returns>Client instance.</returns>
        public static IClient GetClient(ApisEnum service)
        {
            IClient client;

            switch (service)
            {
            case ApisEnum.Pivotal:
                client = PivotalClient.GetInstance();
                break;

            case ApisEnum.Trello:
                client = TrelloClient.GetInstance();
                break;

            case ApisEnum.Todoist:
                client = TodoistClient.GetInstance();
                break;

            case ApisEnum.Salesforce:
                client = SalesforceClient.GetInstance();
                break;

            default:
                client = PivotalClient.GetInstance();
                break;
            }

            return(client);
        }
Пример #3
0
        public void RegisterUpdateSettingsAndDeleteUser_Success()
        {
            var userBase = new UserBase(Guid.NewGuid().ToString("N") + "@example.com", "test user", "Pa$$W@rd");
            var userInfo = TodoistClient.RegisterUserAsync(userBase).Result;

            Assert.NotNull(userInfo);

#pragma warning disable CS0618 // Type or member is obsolete
            var todoistClient = TodoistClient.LoginAsync(userBase.Email, userBase.Password).Result;
#pragma warning restore CS0618 // Type or member is obsolete

            todoistClient.Users.UpdateNotificationSettingsAsync(
                NotificationType.ItemCompleted,
                NotificationService.Email,
                true);
            todoistClient.Users.UpdateKarmaGoalsAsync(new KarmaGoals()
            {
                KarmaDisabled = true
            })
            .Wait();
            todoistClient.Users.UpdateAsync(userInfo)
            .Wait();

            todoistClient.Users.DeleteAsync(userBase.Password, "test");

            todoistClient.Dispose();
        }
Пример #4
0
        /// <summary>
        /// Gets the current user info.
        /// </summary>
        /// <param name="notificationType">Type of the notification.</param>
        /// <param name="service">The service.</param>
        /// <param name="notify">The notify.</param>
        /// <returns>The current user info.</returns>
        /// <exception cref="HttpRequestException">API exception.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="notificationType" /> or <paramref name="service" /> is <see langword="null" /></exception>
        public async Task <NotificationSettings> UpdateNotificationSettingsAsync(
            NotificationType notificationType,
            NotificationService service,
            bool notify)
        {
            if (notificationType == null)
            {
                throw new ArgumentNullException(nameof(notificationType));
            }

            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            var parameters = new LinkedList <KeyValuePair <string, string> >();

            parameters.AddLast(new KeyValuePair <string, string>("notification_type", notificationType.Value));
            parameters.AddLast(new KeyValuePair <string, string>("service", service.Value));
            parameters.AddLast(new KeyValuePair <string, string>("dont_notify", notify ? "1" : "0"));

            return
                (await
                 TodoistClient.PostAsync <NotificationSettings>("notification_settings/update", parameters)
                 .ConfigureAwait(false));
        }
Пример #5
0
        private async Task Run(ProgramArgs args)
        {
            using var todoistClient = new TodoistClient(args.TodoistApiToken);
            var jira = Jira.CreateRestClient(args.JiraServer, args.JiraLogin, args.JiraPassword);

            foreach (var num in args.TaskKeyNumbers)
            {
                Issue? issue   = null;
                string taskKey = $"{args.JiraProject}-{num}";
                try
                {
                    issue = await jira.Issues.GetIssueAsync(taskKey);
                }
                catch
                {
                    await Console.Error.WriteLineAsync($"Failed to fetch {taskKey}");
                }

                if (issue == null)
                {
                    continue;
                }

                try
                {
                    await todoistClient.Items.AddAsync(new Item($"{issue.Key} {issue.Summary}"));
                }
                catch
                {
                    await Console.Error.WriteLineAsync($"Failed to create item {issue.Key}");
                }
            }
        }
Пример #6
0
 public void DeleteProject()
 {
     foreach (string id in helper.GetIds())
     {
         var request = new TodoistRequest("projects/" + id);
         RequestManager.Delete(TodoistClient.GetInstance(), request);
     }
 }
Пример #7
0
        public void GetBackups_Success()
        {
            var client = new TodoistClient(SettingsProvider.GetToken());

            var backups = client.Backups.GetAsync().Result;

            Assert.True(backups.Count() > 0);
        }
Пример #8
0
 /// <summary>
 /// Gets archived projects.
 /// </summary>
 /// <returns>
 /// The archived projects.
 /// </returns>
 /// <exception cref="HttpRequestException">API exception.</exception>
 public async Task <IEnumerable <Project> > GetArchivedAsync()
 {
     return
         (await
          TodoistClient.PostAsync <IEnumerable <Project> >(
              "projects/get_archived",
              new List <KeyValuePair <string, string> >()).ConfigureAwait(false));
 }
Пример #9
0
        /// <summary>
        /// Gets all the user’s completed items (tasks).
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <returns>The completed items.</returns>
        /// <exception cref="HttpRequestException">API exception.</exception>
        /// <remarks>Only available for Todoist Premium users.</remarks>
        public async Task <CompletedItemsInfo> GetCompletedAsync(ItemFilter filter = null)
        {
            var parameters = filter == null ? new List <KeyValuePair <string, string> >() : filter.ToParameters();

            return
                (await
                 TodoistClient.PostAsync <CompletedItemsInfo>("completed/get_all", parameters).ConfigureAwait(false));
        }
Пример #10
0
 /// <summary>
 /// Gets a label info by ID.
 /// </summary>
 /// <param name="id">The ID of the label.</param>
 /// <returns>
 /// The label info.
 /// </returns>
 /// <exception cref="HttpRequestException">API exception.</exception>
 public Task <LabelInfo> GetAsync(ComplexId id)
 {
     return(TodoistClient.PostAsync <LabelInfo>(
                "labels/get",
                new List <KeyValuePair <string, string> > {
         new KeyValuePair <string, string>("label_id", id.ToString())
     }));
 }
Пример #11
0
        public void GetActivity_HasEntries()
        {
            var client = new TodoistClient(SettingsProvider.GetToken());

            var logEntries = client.Activity.GetAsync().Result;

            Assert.True(logEntries.Any());
        }
Пример #12
0
 /// <summary>
 /// Gets a section by ID.
 /// </summary>
 /// <param name="id">The ID of the section.</param>
 /// <returns>
 /// The section.
 /// </returns>
 /// <exception cref="HttpRequestException">API exception.</exception>
 public Task <Section> GetAsync(ComplexId id)
 {
     return(TodoistClient.PostAsync <Section>(
                "sections/get",
                new List <KeyValuePair <string, string> >
     {
         new KeyValuePair <string, string>("section_id", id.ToString())
     }));
 }
Пример #13
0
 /// <summary>
 /// Gets a project by ID.
 /// </summary>
 /// <param name="id">The ID of the project.</param>
 /// <returns>
 /// The project.
 /// </returns>
 /// <exception cref="HttpRequestException">API exception.</exception>
 public Task <ProjectInfo> GetAsync(ComplexId id)
 {
     return(TodoistClient.PostAsync <ProjectInfo>(
                "projects/get",
                new List <KeyValuePair <string, string> >
     {
         new KeyValuePair <string, string>("project_id", id.ToString())
     }));
 }
Пример #14
0
        /// <summary>
        /// Add a task. Implementation of the Quick Add Task available in the official clients.
        /// </summary>
        /// <param name="quickAddItem">The quick add item.</param>
        /// <returns>The created task.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="quickAddItem"/> is <see langword="null"/></exception>
        /// <exception cref="HttpRequestException">API exception.</exception>
        public Task <Item> QuickAddAsync(QuickAddItem quickAddItem)
        {
            if (quickAddItem == null)
            {
                throw new ArgumentNullException(nameof(quickAddItem));
            }

            return(TodoistClient.PostAsync <Item>("quick/add", quickAddItem.ToParameters()));
        }
Пример #15
0
        private async Task AddButton_OnClicked(object sender, EventArgs e)
        {
            using (var client = new TodoistClient(ProjectBrowsePage.AuthKey))
            {
                await client.Items.AddAsync(new Item(ContentEntry.Text, _project.Id));
            }

            await Navigation.PopAsync();
        }
Пример #16
0
 /// <summary>
 /// Gets a filter info by ID.
 /// </summary>
 /// <param name="id">The ID of the filter.</param>
 /// <returns>
 /// The filter info.
 /// </returns>
 /// <exception cref="HttpRequestException">API exception.</exception>
 public async Task <FilterInfo> GetAsync(ComplexId id)
 {
     return
         (await
          TodoistClient.PostAsync <FilterInfo>(
              "filters/get",
              new List <KeyValuePair <string, string> >
     {
         new KeyValuePair <string, string>("filter_id", id.ToString())
     }).ConfigureAwait(false));
 }
Пример #17
0
 /// <summary>
 /// Gets a reminder info by ID.
 /// </summary>
 /// <param name="id">The ID of the reminder.</param>
 /// <returns>
 /// The reminder info.
 /// </returns>
 /// <exception cref="HttpRequestException">API exception.</exception>
 public Task <ReminderInfo> GetAsync(ComplexId id)
 {
     return(TodoistClient.PostAsync <ReminderInfo>(
                "reminders/get",
                new List <KeyValuePair <string, string> >
     {
         new KeyValuePair <string, string>(
             "reminder_id",
             id.ToString())
     }));
 }
Пример #18
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            TodoistClient      client = new TodoistClient("10fe48577af27c2273c83143457ffb1b4d92f8eb");
            IEnumerable <Item> items  = await client.Items.GetAsync();

            foreach (Item item in items)
            {
                Console.WriteLine($"{item.Id}:{item.Content}");
            }

            Console.ReadLine();
        }
Пример #19
0
        private async Task LoadTasks()
        {
            Items = new ObservableCollection <Item>();
            using (var client = new TodoistClient(ProjectBrowsePage.AuthKey))
            {
                var tasks = await client.Items.GetAsync();

                foreach (var item in tasks.Where(x => x.ProjectId == _project.Id))
                {
                    Items.Add(item);
                }
            }
            MyListView.ItemsSource = Items;
        }
Пример #20
0
        private async Task LoadProjects()
        {
            Items = new ObservableCollection <Project>();
            using (var client = new TodoistClient(AuthKey))
            {
                var project = await client.Projects.GetAsync();

                foreach (var item in project)
                {
                    Items.Add(item);
                }
            }
            MyListView.ItemsSource = Items;
        }
Пример #21
0
        public void GetActivityWithEventObjectFilter_HasEntries()
        {
            var client = new TodoistClient(SettingsProvider.GetToken());

            var logFilter = new LogFilter();

            logFilter.ObjectEventTypes.Add(new ObjectEventTypes()
            {
                ObjectType = "project"
            });

            var logEntries = client.Activity.GetAsync(logFilter).Result;

            Assert.True(logEntries.Any());
        }
Пример #22
0
        public void CreateGetDeleteAsync_Success()
        {
            var client = new TodoistClient(SettingsProvider.GetToken());

            var fileName = $"{Guid.NewGuid().ToString()}.txt";
            var upload   = client.Uploads.UploadAsync(fileName, Encoding.UTF8.GetBytes("hello")).Result;

            var allUploads = client.Uploads.GetAsync().Result;

            Assert.True(allUploads.Any(u => u.FileUrl == upload.FileUrl));

            client.Uploads.DeleteAsync(upload.FileUrl).Wait();

            allUploads = client.Uploads.GetAsync().Result;
            Assert.True(allUploads.All(u => u.FileUrl != upload.FileUrl));
        }
Пример #23
0
        /// <summary>
        /// Deletes the current user.
        /// </summary>
        /// <param name="userPassword">The user password.</param>
        /// <param name="reason">The reason.</param>
        /// <returns>The label info.</returns>
        /// <exception cref="ArgumentNullException">API exception.</exception>
        /// <exception cref="HttpRequestException">API exception.</exception>
        public async Task DeleteAsync(string userPassword, string reason = null)
        {
            if (userPassword == null)
            {
                throw new ArgumentNullException(nameof(userPassword));
            }

            var parameters = new LinkedList <KeyValuePair <string, string> >();

            parameters.AddLast(new KeyValuePair <string, string>("current_password", userPassword));

            if (!string.IsNullOrEmpty(reason))
            {
                parameters.AddLast(new KeyValuePair <string, string>("reason_for_delete", reason));
            }

            await TodoistClient.PostRawAsync("user/delete", parameters).ConfigureAwait(false);
        }
Пример #24
0
        private async Task AddButton_OnClicked(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(TitleEntry.Text))
            {
                await DisplayAlert("Error", "Cannot add project with empty title", "Ok");

                return;
            }

            using (var client = new TodoistClient(ProjectBrowsePage.AuthKey))
            {
                await client.Projects.AddAsync(new Project(TitleEntry.Text));
            }

            await DisplayAlert("Success", $"Project {TitleEntry.Text} successfully added", "Ok");

            await Navigation.PopAsync();
        }
Пример #25
0
        public void GetAllResources_Success()
        {
            ITodoistClient client = new TodoistClient(SettingsProvider.GetToken());

            var resources = client.GetResourcesAsync().Result;
        }
Пример #26
0
        /// <summary>
        /// Gets the current user info.
        /// </summary>
        /// <returns>The current user info.</returns>
        /// <exception cref="HttpRequestException">API exception.</exception>
        public async Task <UserInfo> GetCurrentAsync()
        {
            var response = await TodoistClient.GetResourcesAsync(ResourceType.User).ConfigureAwait(false);

            return(response.UserInfo);
        }
Пример #27
0
        /// <summary>
        /// Gets all filters.
        /// </summary>
        /// <returns>The filters.</returns>
        /// <exception cref="HttpRequestException">API exception.</exception>
        public async Task <IEnumerable <Filter> > GetAsync()
        {
            var response = await TodoistClient.GetResourcesAsync(ResourceType.Filters).ConfigureAwait(false);

            return(response.Filters);
        }
Пример #28
0
        static void Main(string[] args)
        {
            TodoistClient client = new TodoistClient("<INSERT TOKEN>");

            int page = 0;

            while (true)
            {
                var result = client.GetAllCompletedTasks(page * 30).Result;
                page++;

                if (result == null || result.Items == null || result.Items.Length == 0)
                {
                    break;
                }

                Console.WriteLine(result.Items.Length);
            }

            var cmd  = new TodoistCommand(TodoistCommands.ProjectAdd, new ProjectCommandArgument("Test project"));
            var cmd2 = new TodoistCommand(TodoistCommands.ProjectAdd, new ProjectCommandArgument("Test project 123")
            {
                Color = 11, ItemOrder = 5, Indent = 2
            });

            //System.Console.WriteLine(client.ExecuteCommands(cmd, cmd2).Result);

            var resources = client.GetAllResourcesAsync().Result;

            foreach (var project in resources.Projects.OrderBy(p => p.ItemOrder))
            {
                string projectIndent = new string('\t', project.Indent - 1);
                Console.WriteLine($"{projectIndent}# {project.Name}");

                foreach (var item in project.Items.OrderBy(i => i.ItemOrder))
                {
                    string itemIndent = projectIndent + new string('\t', item.Indent);
                    Console.WriteLine($"{itemIndent}- {item.Content}");
                }

                Console.WriteLine();
            }

            var addMainTaskCmd = new TodoistCommand(TodoistCommands.ItemAdd, new ItemCommandArgument("My main task @pbi @needSendDonePBI"));
            var addSubTaskCmd  = new TodoistCommand(TodoistCommands.ItemAdd, new ItemCommandArgument("My sub task")
            {
                Indent = 2
            });
            var addNoteCmd = new TodoistCommand(TodoistCommands.NoteAdd, NoteCommandArgument.AddNote(addSubTaskCmd.TempId, "Test note"));

            //var task = client.CreateNewItem(new ItemCommandArgument("Task test")).Result;

            System.Console.WriteLine(client.ExecuteCommands(addMainTaskCmd, addSubTaskCmd, addNoteCmd).Result);

            resources = client.GetAllResourcesAsync().Result;
            var inbox = resources.Projects.First(p => p.ItemOrder == 0);

            int a = 0;
            List <TodoistCommand> cmds = new List <TodoistCommand>();

            //foreach (var it in inbox.Items.OrderByDescending(i => i.ItemOrder).Take(2))
            //{
            //    var c = new TodoistCommand(TodoistCommand.ItemUpdate, new ItemCommandArgument(it.Id) { ItemOrder = ++a + 1, Indent = 2 });
            //    cmds.Add(c);
            //}

            //var noteCommand = new TodoistCommand(TodoistCommands.NoteAdd, NoteCommandArgument.AddProjectNote(res.Projects[0].Id, "Test note"));
            //cmds.Add(noteCommand);

            System.Console.WriteLine(client.ExecuteCommands(cmds.ToArray()).Result);

            System.Console.WriteLine("Done...");
        }
Пример #29
0
        static void Main(string[] args)
        {
            TodoistClient client = new TodoistClient("<INSERT TOKEN>");

            int page = 0;
            while (true)
            {
                var result = client.GetAllCompletedTasks(page * 30).Result;
                page++;

                if (result == null || result.Items == null || result.Items.Length == 0)
                {
                    break;
                }

                Console.WriteLine(result.Items.Length);
            }

            var cmd = new TodoistCommand(TodoistCommands.ProjectAdd, new ProjectCommandArgument("Test project"));
            var cmd2 = new TodoistCommand(TodoistCommands.ProjectAdd, new ProjectCommandArgument("Test project 123") { Color = 11, ItemOrder = 5, Indent = 2 });

            //System.Console.WriteLine(client.ExecuteCommands(cmd, cmd2).Result);

            var resources = client.GetAllResourcesAsync().Result;

            foreach (var project in resources.Projects.OrderBy(p => p.ItemOrder))
            {
                string projectIndent = new string('\t', project.Indent - 1);
                Console.WriteLine($"{projectIndent}# {project.Name}");

                foreach (var item in project.Items.OrderBy(i => i.ItemOrder))
                {
                    string itemIndent = projectIndent + new string('\t', item.Indent);
                    Console.WriteLine($"{itemIndent}- {item.Content}");
                }

                Console.WriteLine();
            }

            var addMainTaskCmd = new TodoistCommand(TodoistCommands.ItemAdd, new ItemCommandArgument("My main task @pbi @needSendDonePBI"));
            var addSubTaskCmd = new TodoistCommand(TodoistCommands.ItemAdd, new ItemCommandArgument("My sub task") { Indent = 2 });
            var addNoteCmd = new TodoistCommand(TodoistCommands.NoteAdd, NoteCommandArgument.AddNote(addSubTaskCmd.TempId, "Test note"));

            //var task = client.CreateNewItem(new ItemCommandArgument("Task test")).Result;

            System.Console.WriteLine(client.ExecuteCommands(addMainTaskCmd, addSubTaskCmd, addNoteCmd).Result);

            resources = client.GetAllResourcesAsync().Result;
            var inbox = resources.Projects.First(p => p.ItemOrder == 0);

            int a = 0;
            List<TodoistCommand> cmds = new List<TodoistCommand>();
            //foreach (var it in inbox.Items.OrderByDescending(i => i.ItemOrder).Take(2))
            //{
            //    var c = new TodoistCommand(TodoistCommand.ItemUpdate, new ItemCommandArgument(it.Id) { ItemOrder = ++a + 1, Indent = 2 });
            //    cmds.Add(c);
            //}

            //var noteCommand = new TodoistCommand(TodoistCommands.NoteAdd, NoteCommandArgument.AddProjectNote(res.Projects[0].Id, "Test note"));
            //cmds.Add(noteCommand);

            System.Console.WriteLine(client.ExecuteCommands(cmds.ToArray()).Result);

            System.Console.WriteLine("Done...");
        }
        private static ITodoistClient CreateClient()
        {
            var client = new TodoistClient(SettingsProvider.GetToken());

            return(client);
        }
Пример #31
0
 /// <summary>
 /// Gets archived projects.
 /// </summary>
 /// <returns>
 /// The archived projects.
 /// </returns>
 /// <exception cref="HttpRequestException">API exception.</exception>
 public Task <IEnumerable <Project> > GetArchivedAsync()
 {
     return(TodoistClient.PostAsync <IEnumerable <Project> >(
                "projects/get_archived",
                new List <KeyValuePair <string, string> >()));
 }