Beispiel #1
0
        public void CreateTask(ITaskDTO taskData)
        {
            var client = new RestClient("https://api.trello.com/1");

            IRestResponse <TrelloCard> createResponse = CreateCard(taskData, client);

            if (createResponse.StatusCode == HttpStatusCode.Unauthorized)
            {
                Process.Start(
                    string.Format(
                        "https://trello.com/1/authorize?key={0}&name=CreateTask&expiration=1day&response_type=token&scope=read,write",
                        TrelloConfig.Key));

                string newToken = null;
                if (
                    InputBox.Show("Token not valid", "Allow the new token in your webbrowser and paste it in here.", ref newToken) ==
                    DialogResult.OK)
                {
                    TrelloConfig.WriteToken(newToken);
                    createResponse = CreateCard(taskData, client);
                }
                else
                {
                    MessageBox.Show("Exiting CreateTask", "Exiting", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }

            TrelloCard    card        = createResponse.Data;
            string        label       = "orange"; //Un-prioratized
            IRestResponse labelResult = AddLabelToCard(card, label, client);

            foreach (string tag in taskData.Tags)
            {
                string labelColor = TrelloLabelToColorMapper.MapColor(tag);
                AddLabelToCard(card, labelColor, client);
            }

            IRestRequest dueDateReq = new RestRequest(string.Format("{0}/{1}/due", TrelloConfig.Resourses.Cards, card.id));

            dueDateReq.Method = Method.PUT;
            SetKeyAndTokenParametersOnRequest(dueDateReq);
            dueDateReq.AddParameter(TrelloConfig.ParameterNames.Value, taskData.DueDate.ToString(CultureInfo.InvariantCulture));

            IRestResponse dueResp = client.Execute(dueDateReq);

            //TODO: Verify status else throw exception
        }
Beispiel #2
0
        public async Task <IActionResult> Get(string idQuadro)
        {
            using (HttpClient client = new HttpClient())
            {
                var response = await client.GetStringAsync(TrelloConfig.GetEndPoint())
                               .ConfigureAwait(false);

                if (response == null)
                {
                    return(BadRequest());
                }

                var result = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Quadro> >(response)
                             .Where(q => q.idQuadro == idQuadro)
                             .FirstOrDefault();
                if (result == null)
                {
                    return(NotFound());
                }

                return(Ok(result));
            }
        }
Beispiel #3
0
 public TrelloClient(HttpClient httpClient, TrelloConfig trelloConfig)
 {
     this.httpClient   = httpClient;
     this.trelloConfig = trelloConfig;
 }