<cfinclude template="config.cfm">
<cfsetting requesttimeout="60">
<cfparam name="url.iface" default="">

<cfset flickr = createobject("component", "CFlickr.Flickr")>
<cfset flickr.init(apikey, secret)>

<cfinclude template="header.cfm">

<cfscript>
// This maps CFlickr's interfaces to Flickr's apiifmap = structnew();
ifmap["flickr.activity"] = "Activity";
ifmap["flickr.auth"] = "Auth";
ifmap["flickr.blogs"] = "Blogs";
ifmap["flickr.contacts"] = "Contacts";
ifmap["flickr.favorites"] = "Favorites";
ifmap["flickr.groups"] = "Groups";
ifmap["flickr.groups.pools"] = "Pools";
ifmap["flickr.interestingness"] = "Interestingness";
ifmap["flickr.people"] = "People";
ifmap["flickr.photos"] = "photos";
ifmap["flickr.photos.comments"] = "PhotoComments";
ifmap["flickr.photos.geo"] = "Geo";
ifmap["flickr.photos.licenses"] = "Licenses";
ifmap["flickr.photos.notes"] = "Notes";
ifmap["flickr.photos.transform"] = "Transform";
ifmap["flickr.photos.upload"] = "Upload";
ifmap["flickr.photosets"] = "Photosets";
ifmap["flickr.photosets.comments"] = "PhotosetsComments";
ifmap["flickr.reflection"] = "Reflection";
ifmap["flickr.tags"] = "Tags";
ifmap["flickr.test"] = "Test";
ifmap["flickr.urls"] = "Urls";

// map CFlickr function names that don't match to Flickr'sfuncmap = structnew();
funcmap["flickr.auth.getToken"] = "getAuthToken";
</cfscript>

<style>
td { vertical-align:top; 
	 border:1px solid #CCCCCC;
}

table { border-collapse:collapse; }
</style>
<h3>Interface Introspection</h3>


<cfif len(url.iface)>

<cfset methods = flickr.getReflectionInterface().getMethods()>

<p><strong><cfoutput>#url.iface#</cfoutput></strong></p>


<table width="600px" border="0">
	<tr>
		<td> <strong>Flickr</strong></td>
		<td> <strong>CFlickr</strong></td>
	</tr>
<cfloop from="1" to="#arraylen(methods)#" index="i">
	
	<cfset method = methods[i]>
	<cfif find(url.iface, method) OR url.iface IS "All Interfaces">
		
		<cfset tmp = listdeleteat(method, listlen(method, "."), ".")>
		
		<cfset interface = ifmap[tmp]>
		<cfif structkeyexists(funcmap, method)>
			<cfset func = funcmap[method]>
		<cfelse>
			<cfset func = listlast(method, ".")>
		</cfif>
	
		<cfoutput>
	
			<tr>
				<td width="50%"><strong>#method#</strong></td>
				<td><strong>#interface#Interface.#func#()</strong></td>
			</tr>
	
			<tr>
			<cfset method_info = flickr.getReflectionInterface().getMethodInfo(method)>
			<cfset args = method_info.getArguments()>
				<td>
					<cfloop from="1" to="#arraylen(args)#" index="j">
					<cfif args[j].name NEQ "api_key">
					#args[j].name# <small>(<cfif NOT args[j].optional>Required<cfelse>Optional</cfif>)</small><br>
					</cfif>
					</cfloop>&nbsp;
				</td>
				<td>
				<cftry>
					<cfset my_if = evaluate("flickr.get#interface#Interface()")>
					<cfset my_func = getMetaData(evaluate("my_if.#func#"))>		
						<cfloop from="1" to="#arraylen(my_func.parameters)#" index="j">
						#my_func.parameters[j].name# <small>(<cfif my_func.parameters[j].required>Required<cfelse>Optional</cfif>)</small><br>
						</cfloop>&nbsp;
					<cfcatch type="any">
						<span style="color:##FF0000;"> An error occured whilst introspecting "#func#()" in the #interface# interface<br />Maybe it doesnt exist?</span>
					</cfcatch>
				</cftry>
				</td>		
			</tr>
			
	
		</cfoutput>

	<cfflush>
	</cfif>


</cfloop> 
</table>

<cfelse>

<p>Choose a CFlickr interface to introspect and compare with Flickrs API</p>
<a href="example9.cfm?iface=All Interfaces">All Interfaces</a><br />
<cfloop collection="#ifmap#" item="i">
	<cfoutput><a href="example9.cfm?iface=#i#">#i#</a></cfoutput><br />


</cfloop>


</cfif>