Exemplo n.º 1
0
        public void AProductsDetailsWithStoreInfoTest()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            KrogerClient            client   = new KrogerClient();
            ProductsDetailsResponse response = client.ProductsDetailsAsync(
                new ProductsDetailsRequest()
            {
                UPCs = new List <string>()
                {
                    "0001111087720", "0001111060828", "0001111060826"
                },
                FilterBadProducts = false,
                StoreId           = "00122",
                DivisionId        = "701"
            }
                ).Result;

            response = client.ProductsDetailsAsync(
                new ProductsDetailsRequest()
            {
                UPCs = new List <string>()
                {
                    "0001111087720", "0001111060828", "0001111060826"
                },
                FilterBadProducts = false,
                StoreId           = "00122",
                DivisionId        = "701"
            }
                ).Result;
            Assert.NotNull(response.Products);
            Assert.That(response.Products.Any());
        }
Exemplo n.º 2
0
        public void ProductsDetailsTest()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            KrogerClient            client   = new KrogerClient();
            ProductsDetailsResponse response = client.ProductsDetailsAsync(
                new ProductsDetailsRequest()
            {
                UPCs = new List <string>()
                {
                    "0001111087720", "0001111060828", "0001111060826"
                },
                FilterBadProducts = false
            }
                ).Result;

            response = client.ProductsDetailsAsync(
                new ProductsDetailsRequest()
            {
                UPCs = new List <string>()
                {
                    "0001111087720", "0001111060828", "0001111060826"
                },
                FilterBadProducts = false
            }
                ).Result;
        }
Exemplo n.º 3
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            KrogerClient krogerClient = Startup.KrogerClient;

            StoreInfoProductsDetailsRequest storesProductsRequests = JsonConvert.DeserializeObject <StoreInfoProductsDetailsRequest>(req.Content.ReadAsStringAsync().Result);

            Task <ProductsDetailsResponse>[] productsDetailsResponses = new Task <ProductsDetailsResponse> [storesProductsRequests.RequestStoreInfos.Length];
            for (int a = 0; a < storesProductsRequests.RequestStoreInfos.Length; a++)
            {
                StoreIdentifier request = storesProductsRequests.RequestStoreInfos[a];
                productsDetailsResponses[a] =
                    krogerClient.ProductsDetailsAsync(
                        new ProductsDetailsRequest()
                {
                    DivisionId        = request.DivisionId,
                    FilterBadProducts = true,
                    StoreId           = request.StoreId,
                    UPCs = storesProductsRequests.UPCs
                });
            }

            await Task.WhenAll(productsDetailsResponses);

            Dictionary <string, ProductStorePrice> productStorePrices = new Dictionary <string, ProductStorePrice>();
            List <StoreIdentifier> noProductsReturned = new List <StoreIdentifier>();

            for (int a = 0; a < productsDetailsResponses.Length; a++)
            {
                ProductsDetailsResponse result = productsDetailsResponses[a].Result;
                if (result.TotalCount == 0)
                {
                    noProductsReturned.Add(storesProductsRequests.RequestStoreInfos[a]);
                }

                foreach (ProductDetail product in result.Products)
                {
                    if (!productStorePrices.ContainsKey(product.UPC))
                    {
                        productStorePrices[product.UPC] = Startup.Mapper.Map <ProductStorePrice>(product);
                    }
                    productStorePrices[product.UPC].StorePrices.Add(Startup.Mapper.Map <StorePrice>(product));

                    StoreIdentifier si = new StoreIdentifier()
                    {
                        DivisionId = storesProductsRequests.RequestStoreInfos[a].DivisionId,
                        StoreId    = storesProductsRequests.RequestStoreInfos[a].StoreId
                    };
                    productStorePrices[product.UPC].StorePrices.Last().StoreIdentifier = si;
                }
            }

            return(req.CreateResponse(HttpStatusCode.OK, new { ProductStorePrices = productStorePrices.Values, NoProductsReturned = noProductsReturned }));
        }
Exemplo n.º 4
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            KrogerClient     krogerClient     = Startup.KrogerClient;
            SearchAllRequest searchAllRequest = JsonConvert.DeserializeObject <SearchAllRequest>(req.Content.ReadAsStringAsync().Result);

            SearchAllResponse searchAllResponse = krogerClient.SearchAll(searchAllRequest);

            ProductsDetailsResponse productsDetailsResponse = await krogerClient.ProductsDetailsAsync(new ProductsDetailsRequest()
            {
                UPCs = searchAllResponse.Upcs
            });

            return(req.CreateResponse(HttpStatusCode.OK,
                                      new { productsDetailsResponse.Products }
                                      ));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get detailed information for specified products
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <ProductsDetailsResponse> ProductsDetailsAsync(ProductsDetailsRequest request)
        {
            ProductsDetailsResponse productDetailsResponse = null;
            string payload = JsonConvert.SerializeObject(request);
            int    tries   = 3;
            bool   failed  = false;

            do
            {
                tries--;
                failed = false;
                try
                {
                    IRestRequest restRequest = new RestRequest(PRODUCTS_DETAILS_ENDPOINT, Method.POST);
                    restRequest.JsonSerializer = new NewtonsoftJsonSerializer();
                    restRequest.AddJsonBody(request);
                    restRequest.AddCookie("_", "_"); //a cookie is required by the request contract,
                                                     //restsharp requires that this not be an empty string in order for the header be set
                    if (request.StoreId != null && request.DivisionId != null)
                    {
                        restRequest.AddHeader("store-id", request.StoreId);
                        restRequest.AddHeader("division-id", request.DivisionId);
                    }


                    IRestResponse <ProductsDetailsResponse> restResponse = await _client.ExecutePostTaskAsync <ProductsDetailsResponse>(restRequest);

                    productDetailsResponse = restResponse.Data;
                }
                catch (JsonReaderException)
                {
                    failed = true;
                }
            } while (tries > 0 && failed);
            return(productDetailsResponse);
        }