/// Author: Francis A. Shanahan
/// http://www.FrancisShanahan.com
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
///
/// Summary description for amazonUtility
///
public class amazonUtility
{
public amazonUtility()
{
//
// TODO: Add constructor logic here
//
}
///
/// Simple helper function to parse out values from the querystring
///
///
///
///
///
private static string CheckNull(NameValueCollection myQueryString, string strKey, string strDefault)
{
// If the desired key is present...
if (myQueryString[strKey] != null)
{
// return its value
return strKey + "=" + myQueryString[strKey] + "&";
}
else
{
// if a default was specified, return it
if (strDefault != "")
return strKey + "=" + strDefault + "&";
}
// Otherwise return the empty string
return "";
}
///
/// Takes the Querystring and builds a valid Amazon REST url from it.
///
/// The page request object
///
public static string BuildAmazonURI(NameValueCollection myQueryString)
{
string strURI = "";
string strRoot = "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&";
string strAccessKeyId = "AWSAccessKeyId=" + ConfigurationManager.AppSettings["AWSAccessKeyId"] + "&";
string strAssociateTag = "AssociateTag=" + ConfigurationManager.AppSettings["AssociateTag"] + "&";
string strOperation = CheckNull(myQueryString, "Operation", "ItemSearch");
string strResponseGroup = CheckNull(myQueryString, "ResponseGroup", "Large");
string strItemId = CheckNull(myQueryString, "ItemId", "");
string strKeywords = CheckNull(myQueryString, "Keywords", "");
string strSearchIndex = CheckNull(myQueryString, "SearchIndex", "");
string strDirector = CheckNull(myQueryString, "Director", "");
string strAuthor = CheckNull(myQueryString, "Author", "");
string strArtist = CheckNull(myQueryString, "Artist", "");
string strActor = CheckNull(myQueryString, "Actor", "");
// Return the concatenated URI
strURI = strRoot + strAccessKeyId +
strOperation + strResponseGroup +
strItemId + strKeywords +
strSearchIndex + strDirector +
strAuthor + strArtist + strActor
;
return strURI;
}
}