static void CustomItemSearchRequest2(AmazonAuthentication authentication)
        {
            Console.WriteLine("Search with BrowseNode");
            Console.WriteLine("------------------------------------------");

            var wrapper         = new AmazonWrapper(authentication, AmazonEndpoint.DE);
            var customOperation = new AmazonOperationBase();

            customOperation.ParameterDictionary.Add("Operation", "ItemSearch");
            customOperation.ParameterDictionary.Add("Keywords", "tall");
            customOperation.ParameterDictionary.Add("SearchIndex", "Apparel");
            customOperation.ParameterDictionary.Add("BrowseNode", "78193031");
            customOperation.ParameterDictionary.Add("AssociateTag", "nagerat-21");


            var webResponse = wrapper.Request(customOperation);

            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("------------------------------------------");
        }
Esempio n. 2
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" });*/
        }
Esempio n. 3
0
        // 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));
        }
Esempio n. 4
0
        public AmazonSearchResult SearchForBookWithISBN13(string isbn13)
        {
            var request = new Dictionary <string, string>();

            request["Operation"]     = "ItemLookup";
            request["ResponseGroup"] = "Large";
            request["SearchIndex"]   = "Books";
            request["IdType"]        = "EAN";
            request["ItemId"]        = isbn13;
            request["AssociateTag"]  = AssociateTag;

            var response = AmazonWrapper.Request(request);

            return(new AmazonSearchResult(response)
            {
                AmazonWebServiceNameSpace = AmazonWebServiceNameSpace
            });
        }
Esempio n. 5
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));
        }
Esempio n. 6
0
        public void SearchTopSellerItems(string keywords, long searchNode, int minPrice, int maxPrice, bool searchSubNodes, Enums.SearchSort searchSort, Enums.SearchSortOrder searchSortOrder)
        {
            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 searchNodeTopSeller = wrapper.BrowseNodeLookup(searchNode, AmazonResponseGroup.BrowseNodeInfo | AmazonResponseGroup.TopSellers);

            var test33 = wrapper.ItemLookupOperation(new List <string> {
                "B00PAZYAT2", "B007SGHF3Y"
            }, AmazonResponseGroup.Small | AmazonResponseGroup.BrowseNodes | AmazonResponseGroup.SalesRank | AmazonResponseGroup.ItemAttributes);

            test33.ParameterDictionary.Add("MerchantId", "Amazon");
            var xmlResponseTT = wrapper.Request(test33);
            var parsedTT      = XmlHelper.ParseXml <ItemLookupResponse>(xmlResponseTT.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("------------------------------------------");
        }
Esempio n. 8
0
        public static List <PriceSourceItemOld> SearchItemLookupOperationOld(string term, AmazonEndpoint?endpoint)
        {
            term = term.Trim();
            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);
                var searchOperation = wrapper.ItemLookupOperation(new List <string>()
                {
                    term
                });
                ExtendedWebResponse xmlResponse = wrapper.Request(searchOperation);
                var itemLookupResponse          = XmlHelper.ParseXml <ItemLookupResponse>(xmlResponse.Content);
                if (itemLookupResponse?.Items?.Item?.FirstOrDefault() != null)
                {
                    string itemJson = JsonConvert.SerializeObject(itemLookupResponse.Items.Item.FirstOrDefault());
                }
                results.AddRange(itemLookupResponse.ToPriceSourceItemsOld());
            }
            return(results);
        }
Esempio n. 9
0
        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);
        }