public IList <ICatalogueExtendedInfo> SearchAmazon(string searchTerms)
        {
            var searchArray = searchTerms.Split(',');
            IDictionary <string, string>   searchParams = AmazonHelper.GetBaseSearchParams(SearchType.ArtistSearch);
            IList <ICatalogueExtendedInfo> returnArray  = new List <ICatalogueExtendedInfo>();

            foreach (var searchItem in searchArray)
            {
                SignedRequestHelper urlHelper = new SignedRequestHelper(this._accessID, this._secretKey, this._requestEndpoint, this._associateTag);
                searchParams["Artist"] = searchItem.Trim();
                var restUrl = urlHelper.Sign(searchParams);

                XmlDocument xmlDoc = new XmlDocument();

                try
                {
                    xmlDoc.Load(restUrl);
                }
                catch (WebException ex)
                {
                    //Log here
                    throw;
                }

                var items = xmlDoc["ItemSearchResponse"]["Items"];

                foreach (XmlNode item in items)
                {
                    if (item.Name == "Item")
                    {
                        var newItem = AmazonHelper.GetNewCatalogueObjectFromXmlNode(item);

                        if (newItem.Artist.ToLower() == searchItem.Trim())
                        {
                            returnArray.Add(newItem);
                        }
                    }
                }

                if (returnArray.Count == 0)
                {
                    ICatalogueExtendedInfo newItem = new CatalogueExtendedInfo
                    {
                        Artist      = "None",
                        Title       = "None",
                        PicUrl      = "None available",
                        ASIN        = "",
                        ReleaseDate = "",
                        Price       = 0,
                        Url         = "http://my-cue.co.uk"
                    };
                }
            }
            return(returnArray);
        }
Example #2
0
        public ICatalogueExtendedInfo LookupSearchString(string searchString, SearchIndex searchIndex)
        {
            string searchIndexString;
            var    searchStringEncoded = HttpUtility.UrlEncode(searchString);
            IDictionary <string, string> searchParams = AmazonHelper.GetBaseSearchParams(SearchType.SearchTerm);
            ICatalogueExtendedInfo       returnItem   = new CatalogueExtendedInfo();

            switch (searchIndex)
            {
            case SearchIndex.MP3:
                searchIndexString = "MP3Downloads";
                break;

            case SearchIndex.CD:
                searchIndexString = "Music";
                break;

            default:
                searchIndexString = "All";
                break;
            }

            SignedRequestHelper urlHelper = new SignedRequestHelper(this._accessID, this._secretKey, this._requestEndpoint, this._associateTag);

            searchParams["Keywords"]    = searchStringEncoded;
            searchParams["SearchIndex"] = searchIndexString;

            var restUrl = urlHelper.Sign(searchParams);

            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(restUrl);
            }
            catch (WebException ex)
            {
                //Log here
                throw;
            }

            var items = xmlDoc["ItemSearchResponse"]["Items"];

            foreach (XmlNode item in items)
            {
                if (item.Name == "Item")
                {
                    returnItem = AmazonHelper.GetNewCatalogueObjectFromXmlNode(item);
                    break;
                }
            }
            return(returnItem);
        }
Example #3
0
        public ICatalogueExtendedInfo LookupASIN(string ASINNumber)
        {
            var itemNumber = HttpUtility.UrlEncode(ASINNumber);
            IDictionary <string, string> searchParams = AmazonHelper.GetBaseSearchParams(SearchType.ASIN);
            ICatalogueExtendedInfo       returnItem   = new CatalogueExtendedInfo();

            SignedRequestHelper urlHelper = new SignedRequestHelper(this._accessID, this._secretKey, this._requestEndpoint, this._associateTag);

            searchParams["ItemId"] = ASINNumber;

            var restUrl = urlHelper.Sign(searchParams);

            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(restUrl);
            }
            catch (WebException ex)
            {
                //Log here
                throw;
            }

            var items = xmlDoc["ItemLookupResponse"]["Items"];

            foreach (XmlNode item in items)
            {
                if (item.Name == "Item")
                {
                    returnItem = AmazonHelper.GetNewCatalogueObjectFromXmlNode(item);
                    break;
                }
            }

            return(returnItem);
        }