public async void obtainDataFromApi(string token) { // 1000 tasks for one day is enought var client = new HttpClient(); String json = ""; String resource_types = "[\"all\"]"; DateTime todayDate = DateTime.Today; // Create the HttpContent for the form to be posted. var requestContent = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("token", token), new KeyValuePair <string, string>("sync_token", "*"), new KeyValuePair <string, string>("resource_types", resource_types), }); // Get the response. HttpResponseMessage response = await client.PostAsync( "https://api.todoist.com/sync/v8/sync", requestContent); // Get the response content. HttpContent responseContent = response.Content; // Get the stream of the content. using (var reader = new System.IO.StreamReader(await responseContent.ReadAsStreamAsync())) { // Write the output. json += await reader.ReadToEndAsync(); } dynamic items = getJson(json, "items"); dynamic userInfo = getJson(json, "user"); this.userEmail = userInfo.email; this.userName = userInfo.full_name; // Make a list of tasks for today foreach (var item in items) { if (item.due != null) { DateTime itemDate = DateTime.Parse(item.due.date); if (itemDate <= todayDate) { String id = Convert.ToString(item.id); String content = Convert.ToString(item.content); DateTime date_added = DateTime.Parse(Convert.ToString(item.date_added)); DateTime due_date = DateTime.Parse(Convert.ToString(item.due.date)); TodoistItem newItem = new TodoistItem(id, content, date_added, due_date); this.todaysTasks.Add(newItem); Console.WriteLine(item.content); } } } }
public async void Add(ListBox display, TodoistItem item, object selection) { String id = item.getId(); String value = item.getContent(); SecondaryTile tile = new SecondaryTile(id, value, id, new Uri("ms-appx:///"), TileSize.Wide310x150); Color background = FromString(item.getColour()); tile.VisualElements.BackgroundColor = background; tile.VisualElements.ForegroundText = ForegroundText.Light; tile.VisualElements.ShowNameOnSquare150x150Logo = true; tile.VisualElements.ShowNameOnSquare310x310Logo = true; tile.VisualElements.ShowNameOnWide310x150Logo = true; await tile.RequestCreateAsync(); display.Items.Add(new Item { Id = tile.TileId, Content = value, Colour = new SolidColorBrush(background) }); }
async void Connect(string githubUrl, string githubToken, string todoistToken) { m_client = new Octokit.GitHubClient(new Octokit.ProductHeaderValue("github-todoist"), new Uri(githubUrl)); m_client.Credentials = new Octokit.Credentials(githubToken); m_currentUser = await m_client.User.Current(); GithubUserName.Content = String.Format("Connected: {0}", m_currentUser.Login); GithubUserName.Foreground = Brushes.Green; var allRepos = await m_client.Repository.GetAllForCurrent(); Repository.Items.Clear(); foreach (var repo in allRepos) { var repoItem = new RepositoryItem() { name = repo.FullName, id = repo.Id }; Repository.Items.Add(repoItem); } m_todoistClient = new Todoist.Net.TodoistClient(todoistToken); var projects = await m_todoistClient.Projects.GetAsync(); TodoistProjects.Items.Clear(); foreach (var project in projects) { var todoistItem = new TodoistItem() { name = project.Name, id = project.Id }; TodoistProjects.Items.Add(todoistItem); } }