Exemple #1
0
        public ActionResult LookupsJson(string[] articleNumbers)
        {
            if (articleNumbers == null)
            {
                return(HttpNotFound());
            }

            var authentication = this.GetConfig();

            var wrapper = new AmazonWrapper(authentication, this._amazonEndpoint, this._associateTag);
            var result  = wrapper.Lookup(articleNumbers, AmazonResponseGroup.Images | AmazonResponseGroup.ItemAttributes);

            var items = result?.Items?.Item;

            if (items == null)
            {
                return(HttpNotFound());
            }

            var smallObjects = items.Select(o => new
            {
                Name  = o.ItemAttributes?.Title,
                Image = o.MediumImage?.URL,
                Asin  = o.ASIN
            }).Where(o => !string.IsNullOrEmpty(o.Image));

            return(Json(smallObjects, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public static List <PriceSourceItemOld> SearchLookup(string term, AmazonEndpoint?endpoint = null)
        {
            List <PriceSourceItemOld> results           = new List <PriceSourceItemOld>();
            List <Endpoint>           endpointsToSearch = new List <Endpoint>();

            if (endpoint != null)
            {
                endpointsToSearch.Add(Endpoints.Get(endpoint.Value));
            }
            else
            {
                endpointsToSearch.AddRange(Endpoints.EndpointsList);
            }

            foreach (var endpointItem in endpointsToSearch)
            {
                var authentication = new AmazonAuthentication();
                authentication.AccessKey = endpointItem.accessKey;
                authentication.SecretKey = endpointItem.secreteKey;

                endpoint = (AmazonEndpoint)Enum.Parse(typeof(AmazonEndpoint), endpointItem.endpointCode);
                var    wrapper    = new AmazonWrapper(authentication, endpoint.Value, endpointItem.merchantId);
                string searchTerm = "ASUS DUAL-RX580-O8G Radeon RX 580 8 GB GDDR5";
                //string searchTerm = //"B076GZ3JFC";
                AmazonItemResponse result = wrapper.Lookup(term);
                results.AddRange(result.ToPriceSourceItems());
            }
            return(results);
        }
Exemple #3
0
        public ActionResult Detail(string articleNumber)
        {
            if (string.IsNullOrEmpty(articleNumber))
            {
                return(RedirectPermanent("/"));
            }

            var authentication = this.GetConfig();

            var wrapper = new AmazonWrapper(authentication, this._amazonEndpoint, this._associateTag);
            var result  = wrapper.Lookup(articleNumber.Trim());

            if (result == null || result.Items == null)
            {
                return(new HttpStatusCodeResult(429));
            }

            if (result.Items.Request?.Errors != null && result.Items.Request.Errors.Any())
            {
                return(RedirectPermanent("/"));
            }

            var item = result.Items?.Item?.FirstOrDefault();

            return(View(item));
        }
Exemple #4
0
        public static AmazonItemResponse MultiItemLookup(string store, string[] asin_isbn)
        {
            var            authentication = GetAuth();
            AmazonEndpoint endpoint       = GetEndpoint(store);
            var            wrapper        = new AmazonWrapper(authentication, endpoint, AssociateTag(store));

            wrapper.XmlReceived   += (xml) => { System.Diagnostics.Debug.WriteLine(xml); };
            wrapper.ErrorReceived += (errorResonse) => { System.Diagnostics.Debug.WriteLine(errorResonse.Error.Message); };
            return(wrapper.Lookup(asin_isbn));
        }
Exemple #5
0
        public Tuple <string, List <SimilarBooks> > GetDetails(string isbn)
        {
            var accessKey    = ConfigurationManager.AppSettings["AmazonAccessKey"];
            var secretKey    = ConfigurationManager.AppSettings["AmazonSecretKey"];
            var associateTag = ConfigurationManager.AppSettings["AmazonAssociateTag"];

            var authentication = new AmazonAuthentication();

            authentication.AccessKey = accessKey;
            authentication.SecretKey = secretKey;

            var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE, associateTag);
            var result  = wrapper.Lookup(isbn);

            var item = result?.Items?.Item?.FirstOrDefault();

            var asins = item?.SimilarProducts?.Select(o => o.ASIN).ToList();

            if (asins == null)
            {
                return(new Tuple <string, List <SimilarBooks> >(item?.LargeImage?.URL, null));
            }

            var similarBooksRequest = wrapper.Lookup(asins);

            if (similarBooksRequest == null)
            {
                Thread.Sleep(1000);
                similarBooksRequest = wrapper.Lookup(asins);
            }

            var similarBooks = similarBooksRequest?.Items?.Item?.Select(o => new SimilarBooks()
            {
                Isbn      = o.ItemAttributes.EAN,
                Title     = o.ItemAttributes.Title,
                Verfasser = o.ItemAttributes.Author?.FirstOrDefault(),
                ImageUrl  = o.MediumImage?.URL,
                Url       = o.DetailPageURL
            }).ToList();

            return(new Tuple <string, List <SimilarBooks> >(item?.LargeImage?.URL, similarBooks));
        }
Exemple #6
0
        public static Item GetBookInformation(string isbn)
        {
            var wrapper      = new AmazonWrapper(GetAuthentication(), AmazonEndpoint.FR);
            var itemResponse = wrapper.Lookup(isbn, AmazonResponseGroup.Large);

            if (itemResponse != null && itemResponse.Items.Item != null)
            {
                var result = itemResponse.Items.Item.SingleOrDefault();
                return(result);
            }
            return(null);
        }
        public static void ItemLookupRequest(AmazonAuthentication authentication)
        {
            Console.WriteLine("ItemLookup");
            Console.WriteLine("------------------------------------------");

            var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE);
            var result  = wrapper.Lookup("B007KKKJYK");

            Console.WriteLine("{0}", result.Items.Item[0].ItemAttributes.Title);

            Console.WriteLine("Multi Lookup");
            Console.WriteLine("------------------------------------------");

            var result2 = wrapper.Lookup(new string[] { "B007KKKJYK", "B004MKNBJG" });

            foreach (var item in result2.Items.Item)
            {
                Console.WriteLine(item.ItemAttributes.Title);
            }

            Console.WriteLine("------------------------------------------");
        }
Exemple #8
0
        public ActionResult Lookup(string articleNumber)
        {
            if (String.IsNullOrEmpty(articleNumber))
            {
                return(View());
            }

            var authentication = this.GetConfig();

            var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE);
            var result  = wrapper.Lookup(articleNumber);

            return(View(result));
        }
Exemple #9
0
        public ActionResult Lookups(string[] articleNumbers)
        {
            if (articleNumbers == null)
            {
                return(RedirectPermanent("/"));
            }

            var authentication = this.GetConfig();

            var wrapper = new AmazonWrapper(authentication, this._amazonEndpoint, this._associateTag);
            var result  = wrapper.Lookup(articleNumbers);

            return(View("Lookup", result));
        }
Exemple #10
0
        public ActionResult Detail(string articleNumber)
        {
            if (String.IsNullOrEmpty(articleNumber))
            {
                return(View());
            }

            var authentication = this.GetConfig();

            var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE);
            var result  = wrapper.Lookup(articleNumber);

            var item = result.Items?.Item.FirstOrDefault();

            return(View(item));
        }
Exemple #11
0
        private void buttonLookup_Click(object sender, EventArgs e)
        {
            var asin          = this.textBoxAsin.Text;
            var endpoint      = (AmazonEndpoint)this.comboBoxEndpoint.SelectedItem;
            var responseGroup = this.responseGroupControl1.GetResponseGroup();

            var wrapper = new AmazonWrapper(this._authentication, endpoint, "nagerat-21");

            wrapper.XmlReceived += XmlReceived;
            var result = wrapper.Lookup(asin, responseGroup);

            wrapper.XmlReceived -= XmlReceived;

            if (result == null)
            {
                MessageBox.Show("Request error");
                return;
            }

            this.dataGridViewResult.DataSource = result.Items.Item;
        }
Exemple #12
0
        public ActionResult Detail(string articleNumber)
        {
            if (string.IsNullOrEmpty(articleNumber))
            {
                return(View());
            }

            var authentication = this.GetConfig();

            var wrapper = new AmazonWrapper(authentication, this._amazonEndpoint, this._associateTag);
            var result  = wrapper.Lookup(articleNumber.Trim());

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

            var item = result.Items?.Item?.FirstOrDefault();

            return(View(item));
        }
Exemple #13
0
        static void Main(string[] args)
        {
            var authentication = new AmazonAuthentication
            {
                AccessKey = "your-access-key",
                SecretKey = "your-secret-key"
            };

            var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.US, "your-store-id");

            wrapper.ErrorReceived += (err) => Console.WriteLine($"Error {err.Error.Code}: {err.Error.Message}");
            wrapper.XmlReceived   += (xml) => Console.WriteLine($"Received: {xml}");

            // Search for products
            //var result = wrapper.Search("raspberry pi", AmazonSearchIndex.Electronics, AmazonResponseGroup.Small);
            //Console.WriteLine(result.Items.TotalResults);

            // Search for a specific item
            var result = wrapper.Lookup("B07BQFX4SB");

            Console.WriteLine(result.Items.Item[0].DetailPageURL);

            Console.ReadLine();
        }
Exemple #14
0
        /// <summary>
        /// Queries the products.
        /// This method triggures the query that returns amazon products for the specified upc
        /// </summary>
        /// <returns>The products.</returns>

        public List <IProduct> QueryProducts()
        {
            //create the list to store the amazon products
            List <IProduct> products = new List <IProduct>();

            try
            {
                AmazonAuthentication auth = new AmazonAuthentication();
                auth.AccessKey = accessKey;
                auth.SecretKey = secretKey;
                AmazonWrapper wrapper = new AmazonWrapper(auth, AmazonEndpoint.US, "wyrecorp-20");

                var response = wrapper.Lookup(itemUPC);
                //if the item array is null then there are no items to retreive and return the prodcuts list blank
                if (response.Items is null)
                {
                    return(products);
                }


                foreach (var item in response.Items.Item)
                {
                    String desc = "";
                    //ioslate any null pointer errors in the description variable
                    try
                    {
                        //parse all of the item features together to create a description for the product
                        foreach (String line in item.ItemAttributes.Feature)
                        {
                            desc = desc + line + Environment.NewLine;
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Error reading description from amazon in amazon api. Error Message" + ex.Message);
                        desc = "No description available";
                    }
                    //create the new product only if the lowest price for this version of the product is not null, because if it null that means that there is no price
                    if (!(item.OfferSummary.LowestNewPrice is null))
                    {
                        BaseProduct product = new BaseProduct()
                        {
                            Name            = item.ItemAttributes.Title ?? "No Title Available",
                            Merchant        = "Amazon",
                            Description     = desc ?? "No Description Available",
                            UPC             = item.ItemAttributes.UPC ?? "No UPC Available",
                            Condition       = "New",
                            Price           = Double.Parse(item.OfferSummary.LowestNewPrice.FormattedPrice.Substring(1)),
                            FormattedPrice  = item.OfferSummary.LowestNewPrice.FormattedPrice ?? "No Formatted Price Available",
                            CurrentCurrency = item.OfferSummary.LowestNewPrice.CurrencyCode ?? "No Currency Code Available",
                            Url             = item.DetailPageURL ?? "No Url Available"
                        };
                        products.Add(product);
                    }
                    if (!(item.OfferSummary.LowestUsedPrice is null))
                    {
                        BaseProduct productUsed = new BaseProduct()
                        {
                            Name            = item.ItemAttributes.Title ?? "No Title Available",
                            Merchant        = "Amazon",
                            Description     = desc ?? "No Description Available",
                            Condition       = "Used",
                            UPC             = item.ItemAttributes.UPC ?? "No UPC Available",
                            Price           = Double.Parse(item.OfferSummary.LowestUsedPrice.FormattedPrice.Substring(1)),
                            FormattedPrice  = item.OfferSummary.LowestUsedPrice.FormattedPrice ?? "No Formatted Price Available",
                            CurrentCurrency = item.OfferSummary.LowestUsedPrice.CurrencyCode,
                            Url             = item.DetailPageURL ?? "No Url Available"
                        };
                        products.Add(productUsed);
                    }
                    if (!(item.OfferSummary.LowestRefurbishedPrice is null))
                    {
                        BaseProduct productRefurb = new BaseProduct()
                        {
                            Name        = item.ItemAttributes.Title ?? "No Title Available",
                            Merchant    = "Amazon",
                            Description = desc ?? "No Description Available",
                            UPC         = item.ItemAttributes.UPC ?? "No UPC Available",
                            //set the conditions based on the product type
                            Condition = "Refurbished",
                            //set the prices for the products from the lowest offers section
                            Price = Double.Parse(item.OfferSummary.LowestRefurbishedPrice.FormattedPrice.Substring(1)),
                            //set the formatted price for each item
                            FormattedPrice = item.OfferSummary.LowestRefurbishedPrice.FormattedPrice ?? "No Formatted Price Available",
                            //set the currency for each price
                            CurrentCurrency = item.OfferSummary.LowestRefurbishedPrice.CurrencyCode ?? "No Currency Code Available",
                            Url             = item.DetailPageURL ?? "No Url Available"
                        };
                        //add the three products to the list
                        products.Add(productRefurb);
                    }
                }
                return(products);
            }catch (Exception ex) {
                Debug.WriteLine("Error when getting product information from the Amazon Api, please check api keys and upc and try again later. Error Message:" + ex.Message);
                return(products);
            }
        }