topical media & game development

talk show tell print

mashup-amazon-11-11-02-RestaurantBrowser-getdata.aspx.cs / cs



  using System;
  using System.Data;
  using System.Configuration;
  using System.Collections;
  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.Xml;
  
  public partial class getdata : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          // If this page was passed any keywords, then GetResults
          GetResults();
      }
  
      void GetResults()
      {
          string strURI = "";
  
          // Is this a Youtube api call or an Amazon call? 
          switch (Request.Params["api"])
          {
              case "youtube":
                  // a YouTube request
                  strURI = "http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag&dev_id=[YOUR ID HERE]&tag=" + Request.Params["tag"];
                  break;
              case "ebay":
                  // an ebay request
                  strURI = "http://rest.api.ebay.com/restapi?CompatibilityLevel=445&CallName=GetSearchResults&RequestToken=[YOUR TOKEN HERE]&RequestUserId=[YOUR ID HERE]&Schema=1&Currency=1&TrackingProvider=1&TrackingId=1889305&SearchInDescription=1&MaxResults=10&Query=" + Request.Params["query"]; ;
                  break;
              default:
                  // Build an Amazon URI
                  strURI = amazonUtility.BuildAmazonURI(Request.QueryString);
                  break;
          }
  
          // Obtain the data
          XmlDocument myDoc = webUtility.GetUri(strURI);
  
          // If the data passed back is ok
          if (myDoc != null)
          {
              Response.Clear();
              // If a content type was specified e.g. text/html use it. 
              if (Request.Params["contentType"] != null)
              {
                  Response.ContentType = Request.Params["contentType"].ToString();
              }
              else
              {
                  // Default to an xml response
                  Response.ContentType = "text/xml";
              }
              
              // If an XSL sheet was specified use it.
              if (Request.Params["xsl"] != null)
              {
                  string strResults = webUtility.DoXSLTransformation(myDoc, Request.Params["xsl"].ToString());
                  Response.Write(strResults);
              }
              else
              {
                  Response.Write(myDoc.InnerXml);
              }
              Response.End();
          }
      }
  }
  


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