Exemple #1
0
        static void Main(string[] args)
        {
            //Authentication
            var authentication = new AmazonAuthentication();

            authentication.AccessKey = "amazon access key here";
            authentication.SecretKey = "amazon secret key here";

            //Search critera and result
            var wrapper         = new AmazonWrapper(authentication, AmazonEndpoint.US, "amazon associate tag here");
            var searchOperation = wrapper.ItemSearchOperation("canon eos", AmazonSearchIndex.Electronics);

            searchOperation.MaxPrice(200000); //2000 USD
            var xmlResponse = wrapper.Request(searchOperation);
            var result      = XmlHelper.ParseXml <ItemSearchResponse>(xmlResponse.Content);

            //Create cart and add items to it
            var items = new List <AmazonCartItem>();

            items.Add(new AmazonCartItem("item code here"));
            var cart = wrapper.CartCreate(items);

            //Debuging

            /*wrapper.XmlReceived += (xml) => { System.Diagnostics.Debug.WriteLine(xml); };
             * wrapper.ErrorReceived += (errorResonse) => { System.Diagnostics.Debug.WriteLine(errorResonse.Error.Message); };
             * var errors = wrapper.Lookup(new string[] { "item code here" });*/
        }
        // GET: Search
        public ActionResult Search(string keyword, string page, string currency)
        {
            //KEYS
            string amazonAccessKey = "ABC";
            string amazonSecretKey = "ABC";
            string associateTag    = "ABC";

            if (String.IsNullOrEmpty(keyword))
            {
                return(View());
            }

            //Makes sure when the user types the url out of bounds, it returns the user to page 1-6
            int pageNum = Int32.Parse(page);

            if (pageNum < 1)
            {
                pageNum = 1;
            }
            else if (pageNum > 6)
            {
                pageNum = 6;
            }

            //Send info to view
            ViewBag.Search   = keyword;
            ViewBag.Page     = pageNum;
            ViewBag.NextPage = pageNum + 1;
            ViewBag.PrevPage = pageNum - 1;
            ViewBag.Currency = currency;

            //Authentication with keys
            var authentication = new AmazonAuthentication();

            authentication.AccessKey = amazonAccessKey;
            authentication.SecretKey = amazonSecretKey;

            //API request
            var wrapper         = new AmazonWrapper(authentication, AmazonEndpoint.UK, associateTag);
            var responseGroup   = AmazonResponseGroup.ItemAttributes | AmazonResponseGroup.Images | AmazonResponseGroup.Offers | AmazonResponseGroup.OfferFull;
            var searchOperation = wrapper.ItemSearchOperation(keyword, AmazonSearchIndex.All, responseGroup);

            searchOperation.Skip(pageNum);
            var xml    = wrapper.Request(searchOperation);
            var result = XmlHelper.ParseXml <ItemSearchResponse>(xml.Content);

            return(View(result));
        }
Exemple #3
0
        public static ItemSearchResponse CustomItemSearch(string store, string categorie, string searchword, int site = 1)
        {
            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); };
            var searchOperation = wrapper.ItemSearchOperation(searchword, GetSearchIndex(categorie));

            if (categorie != "All")
            {
                searchOperation.Sort(AmazonSearchSort.Price, AmazonSearchSortOrder.Descending);
            }
            searchOperation.Skip(site);
            var xmlResponse = wrapper.Request(searchOperation);

            return(XmlHelper.ParseXml <ItemSearchResponse>(xmlResponse.Content));
        }
        static void CustomItemSearchRequest1(AmazonAuthentication authentication)
        {
            Console.WriteLine("Search with skip and sort");
            Console.WriteLine("------------------------------------------");

            var wrapper         = new AmazonWrapper(authentication, AmazonEndpoint.DE);
            var searchOperation = wrapper.ItemSearchOperation("canon eos", AmazonSearchIndex.Electronics);

            searchOperation.Sort(AmazonSearchSort.Price, AmazonSearchSortOrder.Descending);
            searchOperation.Skip(2);
            var webResponse = wrapper.Request(searchOperation);

            var result = XmlHelper.ParseXml <ItemSearchResponse>(webResponse.Content);

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

            Console.WriteLine("found {0} items", result.Items.Item.Length);

            Console.WriteLine("------------------------------------------");
        }
        public SearchResult SearchItems(string keywords, SearchIndex searchIndex, long browseNode, bool amazonMerchant, int minPrice, int maxPrice, Int16 ItemPage, Enums.SearchSort searchSort, Enums.SearchSortOrder searchSortOrder)
        {
            SearchResult result = new SearchResult();

            var authentication = new AmazonAuthentication();

            authentication.AccessKey = this._amazonAccessKey;
            authentication.SecretKey = this._amazonSecretKey;

            var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.IT, this._amazonPartnerId);

            wrapper.ErrorReceived += (errorResonse) => { _logger.LogError(errorResonse.Error.Message); };



            var searchOperation = wrapper.ItemSearchOperation(keywords, (AmazonSearchIndex)searchIndex, AmazonResponseGroup.Medium | AmazonResponseGroup.BrowseNodes | AmazonResponseGroup.SalesRank | AmazonResponseGroup.ItemAttributes);

            searchOperation.Available();
            searchOperation.Condition(ItemCondition.New);
            searchOperation.ParameterDictionary.Add("ItemPage", ItemPage.ToString());

            if (browseNode == 0)
            {
                browseNode = _shoppingHelper.GetRootIdBySearchIndex((int)searchIndex);
            }
            searchOperation.ParameterDictionary.Add("BrowseNode", browseNode.ToString());

            if (amazonMerchant)
            {
                searchOperation.ParameterDictionary.Add("MerchantId", "Amazon");
            }


            if (minPrice >= 0 && maxPrice > 0)
            {
                searchOperation.PriceBetween(maxPrice * 100, minPrice * 100);
            }
            else if (minPrice > 0)
            {
                searchOperation.MinPrice(minPrice * 100);
            }
            else
            {
                searchOperation.MaxPrice(maxPrice * 100);
            }
            if ((int)searchIndex != (int)AmazonSearchIndex.All)
            {
                searchOperation.Sort((AmazonSearchSort)searchSort, (AmazonSearchSortOrder)searchSortOrder);
            }
            // searchOperation.Skip((ItemPage - 1) * 10);
            // searchOperation.Skip(2);
            var xmlResponse = wrapper.Request(searchOperation);

            ItemSearchResponse searchResponse = XmlHelper.ParseXml <ItemSearchResponse>(xmlResponse.Content);

            if (searchResponse.Items.Request.IsValid == "True")
            {
                result.TotalItems = Convert.ToInt32(searchResponse.Items.TotalResults);
                result.TotalPages = Convert.ToInt32(searchResponse.Items.TotalPages);

                foreach (var item in searchResponse.Items.Item)
                {
                    try
                    {
                        Item itemResult = new Item()
                        {
                            ItemId        = item.ASIN,
                            Brand         = item.ItemAttributes.Brand ?? "",
                            DetailPageUrl = item.DetailPageURL ?? "",
                            ImageUrl      = item.LargeImage.URL,
                            Price         = (Convert.ToDecimal(item.ItemAttributes.ListPrice.Amount) / 100),
                            SalesRank     = Convert.ToInt32(item.SalesRank),
                            Title         = item.ItemAttributes.Title ?? ""
                        };
                        result.Items.Add(itemResult);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex.Message);
                    }
                }
            }
            return(result);
        }