public TrelloCardToCreate MapToTrelloCard(Order order)
        {
            var builtToOrderDactyl = order.LineItems
                                     .Where(x => x.ProductId.HasValue)
                                     .First(x => ProductIdConstants.BuiltToOrderDactyl.Contains(x.ProductId.Value));
            var props    = builtToOrderDactyl.Properties.ToArray();
            var caseType = builtToOrderDactyl.ProductId.Value switch
            {
                ProductIdConstants.BuiltToOrderDactylFdm => CaseTypes.PETG_PLA,
                ProductIdConstants.BuiltToOrderDactylSla => CaseTypes.SLA,
                _ => CaseTypes.UNKNOWN
            };
            var trelloCardToCreate = new TrelloCardToCreate
            {
                OrderName      = order.Name,
                Switches       = GetPropertyByNameContains(props, "Switches"),
                MCU            = GetPropertyByNameEquals(props, "Micro Controller Type"),
                CaseColor      = GetPropertyByNameEquals(props, "Case Color"),
                CaseVariant    = GetPropertyByNameEquals(props, "Dactyl/Manuform Layout"),
                WristRestColor = GetPropertyByNameEquals(props, "Gel Wrist Rest Color"),
                LEDs           = GetPropertyByNameEquals(props, "LEDs (optional)"),
                IsDomestic     = order.ShippingAddress.CountryCode.Equals("US"),
                Accessories    = ExtractAccessories(order, props).ToArray(),
                PaintCaseColor = order.LineItems.FirstOrDefault(x => x.ProductId == ProductIdConstants.PaintCaseColorProductId)?.VariantTitle,
                IsBluetooth    = order.LineItems.Any(x => x.ProductId == ProductIdConstants.BluetoothUpgradeProductId),
                CaseType       = caseType,
            };

            return(trelloCardToCreate);
        }
        private async Task CreateRowInGoogleSpreadsheets(TrelloCardToCreate trelloCardInfo, CancellationToken token)
        {
            _logger.LogDebug("+CreateRowInGoogleSpreadsheets {0}", trelloCardInfo.OrderName);
            await _sheetsClient.Append(trelloCardInfo, token);

            _logger.LogDebug("-CreateRowInGoogleSpreadsheets {0}", trelloCardInfo.OrderName);
        }
        private async Task CreateCardOnTrello(TrelloCardToCreate trelloCardInfo, CancellationToken token)
        {
            _logger.LogDebug("+CreateCardOnTrello {0}", trelloCardInfo.OrderName);
            await _trelloClient.CreateCard(trelloCardInfo, token);

            _logger.LogDebug("-CreateCardOnTrello {0}", trelloCardInfo.OrderName);
        }
예제 #4
0
 private static object[] CreateRow(TrelloCardToCreate data)
 {
     return(new object[]
     {
         DateTime.UtcNow.ToString("MM\\/dd\\/yyyy"), //A
         data.OrderName.Trim('#'),                   //B
         data.CaseVariant,                           //C
         data.CaseColor,                             //D
         data.MCU,                                   //E
         data.CaseType.ToString(),
     });
 }
예제 #5
0
        public async Task <string> CreateCard(TrelloCardToCreate card, CancellationToken token)
        {
            const string dactylsToPrintList  = "5db1f059f4e70129456ec11f";
            const string orderCardTemplateId = "5db2e495e40a6877cd888aac";
            const string bluetoothLabelId    = "5f286a5fe0ec6f2206e6adbf";
            var          sb = new StringBuilder()
                              .AppendLine($"{card.CaseColor} {card.CaseVariant}")
                              .AppendLine()
                              .AppendLine($"- [Switches] {card.Switches}")
                              .AppendLine($"- [Wrist rest color] {card.WristRestColor}")
                              .AppendLine($"- [ProMicro/Elite C] {card.MCU}");

            if (string.IsNullOrEmpty(card.LEDs))
            {
                sb.AppendLine("- [LEDs?] None");
            }
            else
            {
                sb.AppendLine($"- [LEDs?] {card.LEDs}");
            }

            var country = card.IsDomestic ? "Domestic" : "International";

            sb.AppendLine($"- [Domestic/International] {country}");
            sb.AppendLine("- [Accessories (keycaps, cords, etc)]");
            foreach (var acc in card.Accessories)
            {
                sb.AppendLine($"  * {acc}");
            }
            var uri = new TrelloCreateCardUriQueryBuilder(_settings, dactylsToPrintList)
            {
                Name              = "Order " + card.OrderName,
                IdCardSource      = orderCardTemplateId,
                KeepFromSource    = "checklists",
                SetPositionBottom = true,
                Description       = sb.ToString(),
            };

            if (card.IsBluetooth)
            {
                uri.Labels = bluetoothLabelId;
            }

            var response = await _client.PostAsync(uri.ToUriString(), null, token);

            await using var stream = await response.Content.ReadAsStreamAsync();

            using var streamReader = new StreamReader(stream);
            return(streamReader.ReadToEnd());
        }
예제 #6
0
        public Task Append(TrelloCardToCreate data, CancellationToken token)
        {
            _logger.LogDebug("Sending order {0} to {1}!{2}", data.OrderName, _settings.DocumentId, _settings.SheetId);
            var service = _serviceProvider.Get();
            var range   = $"{_settings.SheetId}!A1";

            var body = new ValueRange
            {
                Values = new List <IList <object> > {
                    CreateRow(data)
                },
            };
            var request = service.Spreadsheets.Values.Append(body, _settings.DocumentId, range);

            request.ValueInputOption        = SpreadsheetsResource.ValuesResource.AppendRequest.ValueInputOptionEnum.RAW;
            request.IncludeValuesInResponse = true;

            return(request.ExecuteAsync(token));
        }