Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.Linq;
- using System.Web;
- using System.Net;
- using System.Net.Http;
- using amazon_rest;
- using System.Xml;
- public class AmazonECSWrapper : IBookSearch
- {
- public Book[] getBooks(string keywords)
- {
- String amazonAccessKey = "AKIAI35H25WR6DBFXD4Q";
- String amazonSecretKey = "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";
- String destination = "ecs.amazonaws.de";
- String associateID = "amazon015d-20";
- // Creating the Request-String
- SignedRequestHelper requestHelper = new SignedRequestHelper(amazonAccessKey, amazonSecretKey, destination, associateID);
- String amazonQueryString = "Service=AWSECommerceService"
- + "&Version=2011-08-01"
- + "&Operation=ItemSearch"
- + "&SearchIndex=Books"
- + "&ResponseGroup=Large"
- + "&Keywords=" + keywords;
- String signedAmazonQueryString = requestHelper.Sign(amazonQueryString);
- // Send Request to Amazon webservice and get the result in XML
- WebClient webClient = new WebClient();
- XmlDocument xmlDoc = new XmlDocument();
- xmlDoc.Load(webClient.OpenRead(signedAmazonQueryString));
- ArrayList bookList = new ArrayList();
- // Iterate over items
- foreach(XmlElement itemXmlElem in xmlDoc.SelectNodes("/ItemSearchResponse/Items")) {
- String bildURL = "";
- String author = "";
- String isbn = "";
- String titel = "";
- double preis = 0;
- String erscheinungsDatum = "";
- XmlNode bildURLNode = itemXmlElem.GetElementsByTagName("SmallImage/URL")[0];
- if (bildURLNode != null)
- bildURL = bildURLNode.Value;
- XmlNode authorNode = itemXmlElem.GetElementsByTagName("ItemAttributes/Author")[0];
- if (authorNode != null)
- author = authorNode.Value;
- XmlNode isbnNode = itemXmlElem.GetElementsByTagName("ItemAttributes/ISBN")[0];
- if (isbnNode != null)
- isbn = isbnNode.Value;
- XmlNode titelNode = itemXmlElem.GetElementsByTagName("ItemAttributes/Title")[0];
- if (titelNode != null)
- titel = titelNode.Value;
- XmlNode preisNode = itemXmlElem.GetElementsByTagName("ItemAttributes/Price")[0];
- if (preisNode != null)
- preis = Double.Parse(preisNode.Value);
- XmlNode erscheinungsDatumNode = itemXmlElem.GetElementsByTagName("ItemAttributes/PublicationDate")[0];
- if (erscheinungsDatumNode != null)
- erscheinungsDatum = erscheinungsDatumNode.Value;
- bookList.Add(new Book(isbn, titel, preis, author, bildURL, erscheinungsDatum));
- }
- return (Book[])bookList.ToArray(typeof(Book));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement