ColdFusion Video List API Sample

by headCodeWrangler 5/20/2008 12:06:00 AM
The following code relies on sosXML to make working with XML easier. You can get sosXML at http://sosxml.riaforge.org
<!--- Create an instance of the sosXml helper component --->
<cfset sosXml = createObject("component", "sosxml") />
<!--- Set the api base url --->
<cfset apiUrl = "http://demo.ensemblevideo.com/ensemble/app/simpleAPI" />
<!--- Set the video list api call --->
<cfset videoListAPI = "/video/list.xml/" />
<!--- Set the ID of the web site --->
<cfset webSiteID = "OJkxH-bafkaKYRmJo11EQA" />
<cfset httpResults = "" />
<cfset videoListXml = "" />
<cfset videoListUrl = apiUrl & videoListAPI & webSiteID />
<!--- Make the http call to the API and parse the resuling xml --->
<cfhttp url="#videoListUrl#" result="httpResults" />
<cfset videoListXml = xmlParse(httpResults.fileContent) />
<cfoutput>
<cfset videos = arrayNew(1) />
<!--- If the returned xml has data --->
<cfif sosXml.childrenExist(videoListXml.videos)>
    <!--- Loop over the "video" children elements --->
    <cfloop from="1" to="#arraylen(sosXml.childrenGet(videoListXml.videos))#" index="i">
      <!--- Get the data for the individual video --->
      <cfset videoData = sosXml.childrenGet(videoListXml.videos.video) />
    <cfset videoRecord = structnew() />
        <!--- Loop over the elements of the video --->
        <cfloop from="1" to="#arraylen(videoData)#" index="k">
        <!--- Print each element with its value --->
      <cfset videoRecord[sosXml.elementGetName(videoData[k])] = sosXml.elementGetText(videoData[k]) />
        #sosXml.elementGetName(videoData[k])#: #sosXml.elementGetText(videoData[k])#
      <br />
    </cfloop>
    <cfset arrayAppend(videos, videoRecord) />
  </cfloop>
</cfif>
<table width="100%" border="0">
<cfloop from="1" to="#arrayLen(videos)#" index="i">
<tr>
  <td width="5%">
  <img src="#videos[i].thumbnailUrl#" border="0" />
  </td>
  <td align="left" valign="top">
  <span style="font-size: 14px; font-weight: 700;">#videos[i].videoTitle#</span>
  <br />
  #videos[i].videoDuration#
  <br />
  #videos[i].videoDescription#
  </td>
</tr>
</cfloop>
</table>
<cfdump var="#videos#" />
</cfoutput>

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

11/21/2008 12:36:50 AM


Twitter Updates

    Calendar

    <<  November 2008  >>
    MoTuWeThFrSaSu
    272829303112
    3456789
    10111213141516
    17181920212223
    24252627282930
    1234567

    View posts in large calendar

    Recent posts

    Recent comments

    Don't show