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 = "1111135H211111B11111";
- String amazonSecretKey = "11111UwH1111SUaH12333E9B123fAgU/B";
- String destination = "ecs.amazonaws.de";
- String associateID = "amazon0xx1-10";
- // Create the request
- 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);
- WebClient webClient = new WebClient();
- XmlDocument xmlDoc = new XmlDocument();
- // Send the request to the Amazon-Webservice and get the result in XML
- 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