topical media & game development

talk show tell print

mashup-amazon-09-09-01-MovieMogul-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", "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;
      }
  }
  


(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.