public async Task <Product> GetProductAsync(ResourceUri productUri)
        {
            using (var log = RequestLogger.Current.BeginJungoLog(this))
            {
                try
                {
                    var uri             = Billboard.ResolveExpandAll(productUri.Uri);
                    var productResponse = await Client.GetCacheableAsync <ProductResponse>(uri).ConfigureAwait(false);

                    if (productResponse == null)
                    {
                        return(null);
                    }

                    var prod = productResponse.Product;
                    await SupplyRecentInventoryStatusAsync(new[] { prod }).ConfigureAwait(false);

                    return(prod);
                }
                catch (Exception exc)
                {
                    throw log.LogException(exc);
                }
            }
        }
Exemple #2
0
        public async Task <Offers> GetOffersForCartAsync(string popName)
        {
            using (var log = RequestLogger.Current.BeginJungoLog(this))
            {
                OffersResponse offersResponse;

                try
                {
                    var billboard = await Billboard.GetAsync(Client).ConfigureAwait(false);

                    var cartPopOffersUri = Billboard.ResolveTemplate(billboard.Cart,
                                                                     Billboard.Templates.PopOffersSegment,
                                                                     new { pop = popName });
                    // hitting cart resource for offers returns baby offers, even if use expand=all
                    offersResponse =
                        (await Client.GetCacheableAsync <OffersResponse>(cartPopOffersUri).ConfigureAwait(false));
                    if (offersResponse == null || offersResponse.Offers == null || offersResponse.Offers.Offer == null)
                    {
                        return(null);
                    }
                }
                catch (Exception exc)
                {
                    throw log.LogException(exc);
                }

                var offers = offersResponse.Offers;
                // expand each baby offer to papa offer in parallel
                var offerGet = new Task <OfferResponse> [offers.Offer.Length];
                for (var idx = 0; idx < offers.Offer.Length; idx++)
                {
                    offerGet[idx] =
                        Client.GetCacheableAsync <OfferResponse>(Billboard.ResolveExpandAll(offers.Offer[idx].Uri));
                }

                var exceptions = new List <Exception>();
                // wait for all
                for (var idx = 0; idx < offerGet.Length; idx++)
                {
                    try
                    {
                        var offerResponse = await offerGet[idx].ConfigureAwait(false);
                        if (offerResponse != null)
                        {
                            offers.Offer[idx] = offerResponse.Offer;
                            await SupplyRecentInventoryStatusAsync(offers.Offer[idx]).ConfigureAwait(false);
                        }
                    }
                    catch (Exception exc)
                    {
                        exceptions.Add(exc);
                    }
                }
                if (exceptions.Any())
                {
                    throw log.LogException(new AggregateException(exceptions));
                }
                return(offers);
            }
        }
Exemple #3
0
        private async Task <Cart> InternalGetCartAsync()
        {
            var billboard = await Billboard.GetAsync(Client).ConfigureAwait(false);

            var cartUri = Billboard.ResolveExpandAll(billboard.Cart);

            return((await Client.GetAsync <CartResponse>(cartUri).ConfigureAwait(false)).Cart);
        }
Exemple #4
0
 public async Task <Offers> GetOffersAsync(ResourceUri productUri)
 {
     using (var log = RequestLogger.Current.BeginJungoLog(this))
     {
         try
         {
             var prodOffersUri =
                 Billboard.ResolveExpandAll(productUri.Uri + Billboard.Templates.ProductOffersSegment);
             return(await InternalGetOffersForOfferUri(prodOffersUri).ConfigureAwait(false));
         }
         catch (Exception exc)
         {
             throw log.LogException(exc);
         }
     }
 }
        public async Task <Category> GetCategoryAsync(ResourceUri categoryUri)
        {
            using (var log = RequestLogger.Current.BeginJungoLog(this))
            {
                try
                {
                    var uri = Billboard.ResolveExpandAll(categoryUri.Uri);
                    var categoriesResponse =
                        await Client.GetCacheableAsync <CategoriesResponse>(uri).ConfigureAwait(false);

                    return(categoriesResponse == null ? null : categoriesResponse.Category);
                }
                catch (Exception exc)
                {
                    throw log.LogException(exc);
                }
            }
        }
Exemple #6
0
        public async Task <Offers> GetOffersAsync()
        {
            using (var log = RequestLogger.Current.BeginJungoLog(this))
            {
                try
                {
                    var billboard = await Billboard.GetAsync(Client).ConfigureAwait(false);

                    var offersUri = Billboard.ResolveExpandAll(billboard.Offers);
                    var offers    = await InternalGetOffersForOfferUri(offersUri).ConfigureAwait(false);

                    return(offers);
                }
                catch (Exception exc)
                {
                    throw log.LogException(exc);
                }
            }
        }
Exemple #7
0
        public async Task <Offers> GetOffersAsync(string popName)
        {
            using (var log = RequestLogger.Current.BeginJungoLog(this))
            {
                try
                {
                    var pop = await InternalGetPointOfPromotionAsync(popName).ConfigureAwait(false);

                    if (pop == null || pop.Offers == null || String.IsNullOrEmpty(pop.Offers.Uri))
                    {
                        return(null);
                    }
                    var offersUri = Billboard.ResolveExpandAll(pop.Offers.Uri);
                    return(await InternalGetOffersForOfferUri(offersUri).ConfigureAwait(false));
                }
                catch (Exception exc)
                {
                    throw log.LogException(exc);
                }
            }
        }
        public async Task <Categories> GetCategoriesAsync()
        {
            using (var log = RequestLogger.Current.BeginJungoLog(this))
            {
                try
                {
                    //todo: recursive (and let's do it in parallel, please)
                    var billboard = await Billboard.GetAsync(Client).ConfigureAwait(false);

                    var response =
                        await
                        Client.GetCacheableAsync <Category>(Billboard.ResolveExpandAll(billboard.Categories))
                        .ConfigureAwait(false);

                    return(response.Categories);
                }
                catch (Exception exc)
                {
                    throw log.LogException(exc);
                }
            }
        }