Beispiel #1
4
        public void AddTask(Task newTask)
        {
            try
            {
                var addedTask = new AddedTask
                    {
                        type = newTask.Type,
                        text = newTask.Text,
                        date = newTask.Date
                    };

                var request = new RestRequest("/user/tasks", Method.POST);
                request.AddHeader("x-api-key", _apiToken);
                request.AddHeader("x-api-user", _apiUser);
                //var jsonObj = JsonConvert.SerializeObject(addedTask);            
                request.RequestFormat = DataFormat.Json;
                request.AddBody(addedTask);

                var response = _restClient.Execute(request);
                var error = response.ErrorMessage;
            }
            catch (Exception ex)
            {
                var message = ex.Message;
            }
        }
Beispiel #2
0
 public void TodoistToHabit(object source, ElapsedEventArgs e)
 {
     var startTime = e.SignalTime;
     SetText("Starting Sync");
     var hTasks = _hClient.GetTasks().Where(x => x.Type == "todo").ToList();
     var tTasks = _tClient.GetProjects().SelectMany(x => x.GetItems()).ToList();
     var newTasks = 0;
     var completedTasks = 0;
     foreach (var task in tTasks)
     {
         var existing = hTasks.FirstOrDefault(x => x.Text == task.Content);
         if (existing == null)
         {
             if (!task.Checked)
             {
                 var newItem = new Task
                     {
                         Text = task.Content,
                         Type = "todo",
                         Date = task.DueDate.HasValue ? task.DueDate.Value.ToString("o") : null
                     };
                 _hClient.AddTask(newItem);
                 newTasks++;
             }
         }
         else
         {
             if (task.Checked && (bool) (!existing.Completed))
             {
                 _hClient.ScoreTask(existing.Id, "up");
                 completedTasks++;
             }
         }
     }
     SetText(string.Format("{0} new tasks. {1} completed tasks. Next update at {2}", newTasks,
                           completedTasks, startTime.AddMinutes(15)));
 }