コード例 #1
0
        public async Task GetAvailableProducts()
        {
            LOGGER.log.INFO("ProductInventory", "UpdateProductInformation");
            this.client = new InSkillProductsClient(this.input);

            try
            {
                this.productsResponse = await client.GetProducts();
            }
            catch (Exception e)
            {
                LOGGER.log.WARN("ProductInventory", "UpdateProductInformation", "EXCEPTION: " + e.Message);
            }
        }
コード例 #2
0
        public async Task <bool> HasPointsPersistence(SkillRequest skillRequest)
        {
            if (!this.skillRequestValidator.IsValid(skillRequest))
            {
                throw new ArgumentNullException("skillRequest");
            }

            this.logger.LogTrace("BEGIN HasPointsPersistence. RequestId: {0}, UserId: {1}.", skillRequest.Request.RequestId, skillRequest.Context.System.User.UserId);

            bool hasPointsPersistence = false;

            InSkillProduct[] userProducts = null;

            // If unable to talk to InSkillProductClient, then set the HasPointsPersistence value to false and log the error.
            try
            {
                ISkillProductsClient    client   = this.skillProductsClientAdapter.GetClient(skillRequest);
                InSkillProductsResponse response = await client.GetProducts();

                if (response == null || response.Products == null)
                {
                    return(false);
                }

                userProducts         = response.Products;
                hasPointsPersistence = userProducts.Any(x =>
                {
                    return(x.ProductId == RequestBusinessLogic.POINTS_PERSISTENCE_PRODUCT_ID &&
                           x.Entitled == Entitlement.Entitled);
                });
            }
            catch (Exception e)
            {
                this.logger.LogError(e, "Unable to determine HasPointsPersistence. Setting value to false. RequestId: {0}, UserId: {1}.", skillRequest.Request.RequestId, skillRequest.Context.System.User.UserId);
            }

            this.logger.LogTrace("END HasPointsPersistence. RequestId: {0}, UserId: {1}, Products: {2}.", skillRequest.Request.RequestId, skillRequest.Context.System.User.UserId, userProducts == null ? "UNKNOWN" : JsonConvert.SerializeObject(userProducts));

            return(hasPointsPersistence);
        }
        public void InSkillProductsResponseSerializesCorrectly()
        {
            var expected = new InSkillProductsResponse
            {
                IsTruncated = true,
                NextToken   = "abcdef",
                Products    = new[]
                {
                    new InSkillProduct
                    {
                        Name        = ProductName,
                        Type        = ProductType.Subscription,
                        ProductId   = ProductId,
                        Summary     = ProductSummary,
                        Entitled    = Entitlement.NotEntitled,
                        Purchasable = PurchaseState.Purchasable
                    }
                }
            };

            Utility.CompareJson(expected, "InSkillProductsResponse.json");
        }