예제 #1
0
        public SearchNode GetSearchNode(long searchNodeId)
        {
            SearchNode result = new SearchNode()
            {
                Id = searchNodeId
            };

            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); };

            BrowseNodeLookupResponse nodelookup = wrapper.BrowseNodeLookup(searchNodeId, AmazonResponseGroup.BrowseNodeInfo);

            if (nodelookup.BrowseNodes.Request.IsValid == "True")
            {
                result.Name = nodelookup.BrowseNodes.BrowseNode.Name;

                foreach (var item in nodelookup.BrowseNodes.BrowseNode.Children)
                {
                    result.SearchSubNodes.Add(GetSearchNode(Convert.ToInt64(item.BrowseNodeId)));
                }
            }
            return(result);
        }
예제 #2
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));
        }
        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("------------------------------------------");
        }
예제 #4
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));
        }
예제 #5
0
        public ActionResult AddCart(string asin)
        {
            var cartId = string.Empty;
            var hmac   = string.Empty;

            var authentication = this.GetConfig();
            var wrapper        = new AmazonWrapper(authentication, this._amazonEndpoint, this._associateTag);

            AmazonCartItem item;

            if (Session["cartId"] == null)
            {
                item = new AmazonCartItem(asin);

                var cardCreateResponse = wrapper.CartCreate(new List <AmazonCartItem> {
                    item
                });

                Session["cartId"] = cardCreateResponse.Cart.CartId;
                Session["hmac"]   = cardCreateResponse.Cart.HMAC;

                return(Json(new { Successful = true, cardCreateResponse.Cart.CartId }, JsonRequestBehavior.AllowGet));
            }

            cartId = Session["cartId"] as string;
            hmac   = Session["hmac"] as string;

            item = new AmazonCartItem(asin);
            var cardAddResponse = wrapper.CartAdd(item, cartId, hmac);

            return(Json(new { Successful = true, cardAddResponse.Cart.CartId }, JsonRequestBehavior.AllowGet));
        }
예제 #6
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);
        }
예제 #7
0
        ////https://www.grosbill.com/3-disque_dur-3.5-type-informatique
        ////http://www.materiel.net/disque-dur/

        //var auth = new AmazonAuthentication();
        //auth.AccessKey = "";
        //auth.SecretKey = "";
        //var wrapper = new AmazonWrapper(auth, AmazonEndpoint.FR);
        //foreach(HDD di in lstProd2)
        //{
        //    var lstReslt = wrapper.Search(di.Nom, AmazonSearchIndex.Electronics);
        //    if (lstReslt != null && lstReslt.Items!=null && lstReslt.Items.Item!=null)
        //    {
        //        foreach (Item item in lstReslt.Items.Item)
        //        {

        //                Debug.WriteLine("modèle : " + item.ItemAttributes?.Model + " marque : " + item.ItemAttributes?.Brand + " price : " + item.ItemAttributes?.ListPrice?.FormattedPrice);

        //        }
        //    }
        //}


        public static async void AmazonExtractor(ObservableCollection <HDD> lstProdIn, ObservableCollection <HDD> LstProdOut)
        {
            var auth = new AmazonAuthentication();

            auth.AccessKey = "";
            auth.SecretKey = "";
            var wrapper = new AmazonWrapper(auth, AmazonEndpoint.FR, "");
            ObservableCollection <HDD> lstTmp = new ObservableCollection <HDD>(lstProdIn.ToList());

            foreach (HDD di in lstTmp)
            {
                var lstReslt = wrapper.Search(di.Nom, AmazonSearchIndex.Electronics);
                if (lstReslt != null && lstReslt.Items != null && lstReslt.Items.Item != null)
                {
                    foreach (Item item in lstReslt.Items.Item)
                    {
                        // Debug.WriteLine("modèle : " + item.ItemAttributes?.Model + " marque : " + item.ItemAttributes?.Brand + " price : " + item.ItemAttributes?.ListPrice?.FormattedPrice);
                        await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                        {
                            LstProdOut.Add(new HDD()
                            {
                                Nom = item.ItemAttributes?.Brand + " " + item.ItemAttributes?.Model, Prix = float.Parse(item.ItemAttributes?.ListPrice?.FormattedPrice.Replace("EUR ", ""))
                            });
                        }));
                    }
                }
            }
        }
예제 #8
0
        public async Task <ProviderBookOffer> SearchOffersByIsbnAsync(string isbn)
        {
            try
            {
                var response = await AmazonWrapper.SearchAsync(isbn, AmazonSearchIndex.Books, AmazonResponseGroup.Offers);

                var item             = response.Items.Item.FirstOrDefault();
                var itemOffer        = item.Offers.Offer.FirstOrDefault();
                var itemOfferListing = itemOffer.OfferListing.FirstOrDefault();

                return(new ProviderBookOffer
                {
                    Title = item.ItemAttributes.Title,
                    Isbn = item.ItemAttributes.ISBN,
                    Provider = Name,
                    Price = decimal.Parse(itemOfferListing.Price.Amount),
                    CurrencyCode = itemOfferListing.Price.CurrencyCode,
                    Url = itemOfferListing.OfferListingId
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Amazon: Search offers failed.");
                return(new ProviderBookOffer());
            }
        }
예제 #9
0
        public async Task <IEnumerable <ProviderBookSearchItem> > SearchByTitleAsync(string title)
        {
            try
            {
                var response = await AmazonWrapper.SearchAsync(title, AmazonSearchIndex.Books, AmazonResponseGroup.Small);

                return(response.Items.Item
                       .Select(x => new ProviderBookSearchItem
                {
                    Title = x.ItemAttributes.Title,
                    Isbn = new IsbnData
                    {
                        Id10Digits = x.ItemAttributes.ISBN
                    },
                    Authors = x.ItemAttributes.Author,
                    Provider = Name
                })
                       .ToList());
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Amazon: Search books failed.");
                return(Enumerable.Empty <ProviderBookSearchItem>());
            }
        }
예제 #10
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" });*/
        }
 public AmazonProductAdvertisingService()
 {
     _requestWrapper = new AmazonWrapper(new AmazonAuthentication
     {
         AccessKey = ConfigurationManager.AppSettings["AmazonProductApiAccessKeyId"],
         SecretKey = ConfigurationManager.AppSettings["AmazonProductApiSecretKeyId"]
     }, AmazonEndpoint.US);
 }
예제 #12
0
        public AmazonApiSearcher()
        {
            var authentication = new AmazonAuthentication
            {
                AccessKey = AccessKey,
                SecretKey = SecretKey
            };

            this._apiWwrapper = new AmazonWrapper(authentication, AmazonEndpoint.CA);
        }
예제 #13
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));
        }
예제 #14
0
 static void Main3(string[] args)
 {
     var authentification = new AmazonAuthentication
     {
         AccessKey = APIKeys.AmazonAccessKey,
         SecretKey = APIKeys.AmazonSecretKey
     };
     var w = new AmazonWrapper(authentification, AmazonEndpoint.JP, "kurema-22");
     //var AmazonRequiredResponse = Nager.AmazonProductAdvertising.Model.AmazonResponseGroup.ItemAttributes | Nager.AmazonProductAdvertising.Model.AmazonResponseGroup.Images | Nager.AmazonProductAdvertising.Model.AmazonResponseGroup.OfferSummary;
     var s = w.Search("倫理 哲学", responseGroup: Nager.AmazonProductAdvertising.Model.AmazonResponseGroup.Large);
 }
예제 #15
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);
        }
예제 #16
0
        public AmazonApiInspector(AmazonSource source)
        {
            this._source = source;

            var authentication = new AmazonAuthentication
            {
                AccessKey = AccessKey,
                SecretKey = SecretKey
            };

            this._apiWwrapper = new AmazonWrapper(authentication, AmazonEndpoint.CA);
        }
예제 #17
0
        public AmazonClient(AppSettings appSettings)
        {
            AssociateTag = appSettings.AssociateTag;
            AmazonWebServiceNameSpace = appSettings.AmazonWebServiceNameSpace;

            AmazonAuthentication = new AmazonAuthentication
            {
                AccessKey = appSettings.AccessKey,
                SecretKey = appSettings.SecretKey
            };

            AmazonWrapper = new AmazonWrapper(AmazonAuthentication, AmazonEndpoint.US, appSettings.AssociateTag);
        }
예제 #18
0
        public static CartCreateResponse CreateCart(string store, string asin_isbn)
        {
            var            authentication = GetAuth();
            AmazonEndpoint endpoint       = GetEndpoint(store);
            var            items          = new List <AmazonCartItem> {
                new AmazonCartItem(asin_isbn)
            };
            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.CartCreate(items));
        }
예제 #19
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));
        }
예제 #20
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));
        }
        static void BrowseNodeLookupRequest2(AmazonAuthentication authentication)
        {
            Console.WriteLine("BrowseNodeLookup - BrowseNodes");
            Console.WriteLine("------------------------------------------");

            var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE);
            var result  = wrapper.BrowseNodeLookup(78193031, AmazonResponseGroup.BrowseNodeInfo);

            foreach (var item in result.BrowseNodes.BrowseNode.Children)
            {
                Console.WriteLine(item.BrowseNodeId);
            }

            Console.WriteLine("------------------------------------------");
        }
        static void CreateCart1(AmazonAuthentication authentication)
        {
            Console.WriteLine("CreateCart1");
            Console.WriteLine("------------------------------------------");

            var items = new List <AmazonCartItem>();

            items.Add(new AmazonCartItem("B00MH4QM1S"));
            items.Add(new AmazonCartItem("B01EUHFAC6"));

            var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE);
            var result  = wrapper.CartCreate(items);

            Console.WriteLine("------------------------------------------");
        }
예제 #23
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));
        }
예제 #24
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));
        }
        public void TestMethod1()
        {
            var authentication = new AmazonAuthentication();

            authentication.AccessKey = "[AccessKey]";
            authentication.SecretKey = "[SECRET]";
            var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.ES, "desincuentos-21");

            wrapper.ErrorReceived += response =>
            {
                var error = response;
            };
            var res = wrapper.BatchItemLookupOperation(new List <string> {
                "B01I4QAERA", "B07H42TBTD", "B075CK3GVJ", "B01CJYNBBY", "B01A9GM5X4", "B00ZB9QJ5K", "B005QJOQEG", "B06XXZLCD2", "B019HAOZ3G", "B01I4QAERA", "B07H42TBTD", "B075CK3GVJ", "B01CJYNBBY", "B01A9GM5X4", "B00ZB9QJ5K", "B005QJOQEG", "B06XXZLCD2", "B019HAOZ3G", "B019HAOZ3G", "B019HAOZ3G"
            });
        }
        static void ItemSearchRequest(AmazonAuthentication authentication)
        {
            Console.WriteLine("ItemSearch");
            Console.WriteLine("------------------------------------------");

            var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE);
            var result  = wrapper.Search("canon eos", AmazonSearchIndex.Electronics, AmazonResponseGroup.Large);

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

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

            Console.WriteLine("------------------------------------------");
        }
        static void ItemSearchRequest2(AmazonAuthentication authentication)
        {
            Console.WriteLine("ItemSearch");
            Console.WriteLine("------------------------------------------");

            var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE);
            var result  = wrapper.Search("canon eos", AmazonSearchIndex.Electronics, AmazonResponseGroup.Images | AmazonResponseGroup.Similarities);

            foreach (var item in result.Items.Item)
            {
                Console.WriteLine($"ASIN:{item.ASIN}, SimilarCount:{item.SimilarProducts.Length}");
            }

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

            Console.WriteLine("------------------------------------------");
        }
예제 #28
0
        public ActionResult ClearCart()
        {
            var cartId         = string.Empty;
            var authentication = this.GetConfig();
            var wrapper        = new AmazonWrapper(authentication, this._amazonEndpoint, this._associateTag);

            if (Session["cartId"] == null)
            {
                return(Json(new { Successful = false }));
            }

            cartId = Session["cartId"] as string;
            var result = wrapper.CartClear(cartId, null);

            Session["cartId"] = null;

            return(Json(new { Successful = true, result.Cart.CartId }));
        }
예제 #29
0
        public ActionResult Search(string search)
        {
            if (string.IsNullOrEmpty(search))
            {
                return(RedirectPermanent("/"));
            }

            ViewBag.Search = search.Trim();

            var authentication = this.GetConfig();

            var wrapper       = new AmazonWrapper(authentication, this._amazonEndpoint, this._associateTag);
            var responseGroup = AmazonResponseGroup.ItemAttributes | AmazonResponseGroup.Images | AmazonResponseGroup.OfferSummary;

            var result = wrapper.Search(search.Trim(), AmazonSearchIndex.All, responseGroup);

            return(View(result));
        }
예제 #30
0
        static void BrowseNodeLookupRequest(AmazonAuthentication authentication)
        {
            //http://docs.aws.amazon.com/AWSECommerceService/latest/DG/localevalues.html

            Console.WriteLine("BrowseNodeLookup");
            Console.WriteLine("------------------------------------------");

            var wrapper = new AmazonWrapper(authentication, AmazonEndpoint.DE);
            var result  = wrapper.BrowseNodeLookup(569604, AmazonResponseGroup.Large);

            foreach (var item in result.BrowseNodes.BrowseNode.Children)
            {
                Console.WriteLine(item.BrowseNodeId);
            }

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

            Console.WriteLine("------------------------------------------");
        }