topical media & game development

talk show tell print

mashup-amazon-10-10-02-Wishlist-App-Code-amazonUtility.cs / cs



  
Author: Francis A. Shanahan

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 // }
<summary> Simple helper function to parse out values from the querystring </summary> <param name="myQueryString"></param> <param name="strKey"></param> <param name="strDefault"></param> <returns></returns> 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 ""; }

  
<summary> Takes the Querystring and builds a valid Amazon REST url from it. </summary> <param name="myRequest">The page request object<returns></returns> 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", "");
          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", "");
          string strListType = CheckNull(myQueryString, "ListType", "");
          string strName = CheckNull(myQueryString, "Name", "");
          string strFirstName = CheckNull(myQueryString, "FirstName", "");
          string strLastName = CheckNull(myQueryString, "LastName", "");
          string strEmail = CheckNull(myQueryString, "Email", "");
          string strListId = CheckNull(myQueryString, "ListId", "");
          string strItem1ASIN = CheckNull(myQueryString, "Item.1.ASIN", "");
          string strItem1Quantity = CheckNull(myQueryString, "Item.1.Quantity", "");
          string strMergeCart = CheckNull(myQueryString, "MergeCart", "");
          string strCartID = CheckNull(myQueryString, "CartId", "");
          string strItem1CartItemId = CheckNull(myQueryString, "Item.1.CartItemId", "");
          string strHMAC = CheckNull(myQueryString, "HMAC", "");
          
          // Return the concatenated URI
          strURI = strRoot + strAccessKeyId +
              strOperation + strResponseGroup +
              strItemId + strKeywords +
              strSearchIndex + strDirector +
              strAuthor + strArtist + 
              strActor + strListType + 
              strName + strFirstName + 
              strLastName + strEmail + strListId +
              strItem1ASIN + strItem1Quantity + 
              strMergeCart + strCartID + 
              strHMAC + strItem1CartItemId;    
          
          return strURI;
      }
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.