Exemplo n.º 1
0
 private static string GetOutputString(Product targetProduct, AmazonWSHelper helper, AWSECommerceService ecs, Item item)
 {
     using (StringWriter writer = new StringWriter()) {
         foreach (Offer o in item.Offers.Offer) {
             string[] listPrices, salePrices;
             string[] prices = GetPrices(item, o, helper, ecs, out listPrices, out salePrices);
             writer.WriteLine(GetOfferString(item, o, listPrices, salePrices));
             writer.WriteLine("");
         }
         return writer.ToString();
     }
 }
 public ItemLookupResponse GetItemLookupResponse(AWSECommerceService ecs, string[] itemASINs)
 {
     ItemLookup lookup = new ItemLookup();
     lookup.AssociateTag = AssociateTag;
     lookup.AWSAccessKeyId = AWSAccessKeyId;
     //lookup.Version = "2008-08-19";
     ItemLookupRequest request = new ItemLookupRequest();
     request.ItemId = itemASINs;
     request.MerchantId = "Featured";
     request.ResponseGroup = new string[] {"Medium", "OfferFull", "ShippingCharges"};
     lookup.Request = new ItemLookupRequest[] {request};
     ItemLookupResponse response = ecs.ItemLookup(lookup);
     CheckRequestError(response.OperationRequest);
     return response;
 }
Exemplo n.º 3
0
 private static string GetMerchantAndPriceSpecificOutputString(Product targetProduct, AmazonWSHelper helper, AWSECommerceService ecs, Item item)
 {
     using (StringWriter writer = new StringWriter()) {
         foreach (Offer o in item.Offers.Offer) {
             if (targetProduct.MerchantId == o.Merchant.MerchantId) {
                 string[] listPrices, salePrices;
                 string[] prices = GetPrices(item, o, helper, ecs, out listPrices, out salePrices);
                 if (Int64.Parse(targetProduct.Price) > Int64.Parse(prices[0])) {
                     writer.WriteLine(GetOfferString(item, o, listPrices, salePrices));
                 }
                 writer.WriteLine("");
             }
         }
         return writer.ToString();
     }
 }
 public string[] GetPriceTupleFromCart(AWSECommerceService ecs, Item item, OfferListing offerListing)
 {
     Cart cart = null;
     string cartInfo = ReadCartInfo();
     if (string.IsNullOrEmpty(cartInfo)) {
         CartCreateResponse response = ecs.CartCreate(GetCartCreate(item, offerListing));
         CheckRequestError(response.OperationRequest);
         cart = response.Cart[0];
         WriteCartInfo(cart);
     } else {
         CartAddResponse response = ecs.CartAdd(GetCartAdd(cartInfo, item, offerListing));
         CheckRequestError(response.OperationRequest);
         cart = response.Cart[0];
     }
     string[] prices = new string[2];
     prices[0] = cart.SubTotal.Amount;
     prices[1] = cart.SubTotal.FormattedPrice;
     CartClearResponse clearResponse = ecs.CartClear(GetCartClear(cart));
     CheckRequestError(clearResponse.OperationRequest);
     return prices;
 }
Exemplo n.º 5
0
 private static string[] GetPrices(Item item, Offer o, AmazonWSHelper helper, AWSECommerceService ecs, out string[] listPrices, out string[] salePrices)
 {
     string[] prices = o.OfferListing[0].Price.FormattedPrice == "Too low to display"
                       	?
                       		helper.GetPriceTupleFromCart(ecs, item, o.OfferListing[0])
                       	:
                       		new string[] {o.OfferListing[0].Price.Amount, o.OfferListing[0].Price.FormattedPrice};
     listPrices = new string[2];
     salePrices = null;
     prices.CopyTo(listPrices, 0);
     if (o.OfferListing[0].SalePrice != null) {
         salePrices = new string[2];
         prices = o.OfferListing[0].SalePrice.FormattedPrice == "Too low to display"
                  	?
                  		helper.GetPriceTupleFromCart(ecs, item, o.OfferListing[0])
                  	:
                  		new string[] {o.OfferListing[0].SalePrice.Amount, o.OfferListing[0].SalePrice.FormattedPrice};
         prices.CopyTo(salePrices, 0);
     }
     return prices;
 }
Exemplo n.º 6
0
        private static void ProcessAlert(AlertTarget target)
        {
            Console.WriteLine(target.Email);
            Console.WriteLine("");
            AWSECommerceService ecs = new AWSECommerceService();

            AmazonWSHelper helper = new AmazonWSHelper();
            try {
                ItemLookupResponse response = helper.GetItemLookupResponse(ecs, target.GetProductASINs());
                using (StringWriter writer = new StringWriter()) {
                    foreach (Items i in response.Items) {
                        foreach (Item item in i.Item) {
                            writer.WriteLine("Product: " + item.ItemAttributes.Title);
                            writer.WriteLine("Product Url: " + item.DetailPageURL);
                            writer.WriteLine("");
                            Product targetProduct = target.ProductList[item.ASIN];
                            if (!string.IsNullOrEmpty(targetProduct.MerchantId) && !string.IsNullOrEmpty(targetProduct.Price)) {
                                //List offer that's below specific price for a specific merchant
                                writer.WriteLine(GetMerchantAndPriceSpecificOutputString(targetProduct, helper, ecs, item));
                            } else if (!string.IsNullOrEmpty(targetProduct.MerchantId)) {
                                //List all the offers for a specific merchant
                                writer.WriteLine(GetMerchantSpecificOutputString(targetProduct, helper, ecs, item));
                            } else if (!string.IsNullOrEmpty(targetProduct.Price)) {
                                //List all the offers below a specific price
                                writer.WriteLine(GetPriceSpecificOutputString(targetProduct, helper, ecs, item));
                            } else {
                                //List all the available prices
                                writer.WriteLine(GetOutputString(targetProduct, helper, ecs, item));
                            }
                        }
                    }
                    Console.WriteLine(writer.ToString());
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.ToString());
            }
        }
 public string GetPriceFromCart(AWSECommerceService ecs, Item item, OfferListing offerListing)
 {
     string[] prices = GetPriceTupleFromCart(ecs, item, offerListing);
     return prices[0];
 }