cf_armory : UpdateCentral phase 1 complete
For example, look up me, name: Castlereagh, realm: Bloodhoof
I'm blow away by the speed of this compared to if you were to click through each item slot on the armory character screen. This was my big chance to use
I'm modularizing, moving more stuff to cfcs. There are three functions involved, and the page to call them all. I put one layer of error checking for the CFHTTP request function
<cfargument name="url" required="true">
<cfset var strUserAgent = (
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; " &
"rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"
) />
<cfhttp
url="#arguments.url#"
method="GET"
result="armoryXML"
useragent="#strUserAgent#"
/>
<cfif left(armoryXML.statuscode,3) neq "200">
<cfthrow message="Error reaching armory"><cfabort />
</cfif>
<cfreturn armoryXML>
</cffunction>
That let's us clean up some code elsewhere. With more testing, there may be a common way to see if data was properly returned on a status 200 call... Then a function to get your character sheet.
<cfargument name="realm">
<cfargument name="charactername">
<cfargument name="baseURL" required="false" default="http://armory.worldofwarcraft.com/">
<cfset var url = arguments.baseURL
& "character-sheet.xml?r=" & arguments.realm
& "&n=" & arguments.charactername>
<cfset var charactersheet = makeHTTPCall(url)>
<cfset charactersheet = XMLParse(charactersheet.FileContent)>
<cfif charactersheet.page.characterInfo.xmlText eq "">
<cfthrow message="Error getting character data, check your spelling"><cfabort/>
</cfif>
<cfreturn charactersheet>
</cffunction>
This checks that it actually returns some data. If it returns with a status 200, but no data, you must have spelled the name or realm wrong. Or the character doesn't currently exist in Armory. I suppose if it comes back with this, it's always true that the character doesn't exist in Armory...
Now since this is run #1, the function to get upgrades is also the one that displays them. Later this will loop through, getting all the data about the items, and retun some structure to be displayed. But for now, View and Control are one and the same.
<cfargument name="realm">
<cfargument name="charactername">
<cfargument name="itemid">
<cfargument name="baseURL" required="false" default="http://armory.worldofwarcraft.com/">
<cfset var url = arguments.baseURL
& "search.xml?searchType=items&pr=" & arguments.realm
& "&pn=" & arguments.charactername
& "&pi=" & arguments.itemID>
<cfset var itemsheet = makeHTTPCall(url)>
<!--- initialize variables to be used --->
<cfset var items = "">
<cfset var i = "">
<cfset var j = "">
<cfset var isEquipped = "">
<cfif left(itemsheet.statuscode,3) neq "200">
<cfthrow message="Error reaching armory"><cfabort >
</cfif>
<cfset items = XMLParse(itemsheet.fileContent).page.armorySearch.searchResults.items>
<cfoutput>
<table>
<cfloop from="1" to="#ArrayLen(items.XMLChildren)#" index="i">
<cfset isEquipped = false>
<cfif arguments.itemID eq items.XMLChildren[i].XMLAttributes.id>
<cfset isEquipped = true>
</cfif>
<tr <cfif isEquipped>bgcolor="##999999"</cfif>>
<td>
#items.XMLChildren[i].XMLAttributes.name#
</td>
<cfloop from="1" to="#ArrayLen(items.XMLChildren[i].filter)#" index="j">
<cfif items.XMLChildren[i].filter[j].XMLAttributes.name eq "type">
<td>
#items.XMLChildren[i].filter[j].XMLAttributes.value#
</td>
</cfif>
<cfif items.XMLChildren[i].filter[j].XMLAttributes.name eq "requiredLevel">
<td>
#items.XMLChildren[i].filter[j].XMLAttributes.value#
</td>
</cfif>
<cfif items.XMLChildren[i].filter[j].XMLAttributes.name eq "source">
<td>
<cfif items.XMLChildren[i].filter[j].XMLAttributes.value eq "sourceType.creatureDrop">
#items.XMLChildren[i].filter[j].XMLAttributes.creatureName# (#items.XMLChildren[i].filter[j].XMLAttributes.areaName#<cfif items.XMLChildren[i].filter[j].XMLAttributes.difficulty eq "h"> (heroic)</cfif>)
<cfelse>
#items.XMLChildren[i].filter[j].XMLAttributes.value#
</cfif>
</td>
</cfif>
</cfloop>
</tr>
</cfloop>
</table>
</cfoutput>
</cffunction>
Variables i and j, very descriptive, yes? In the future when this returns an object of data, the isEqipped flag can be used to separate what you have on now, so it can be displayed differently.
The above three functions are all resting in armory.cfc now.
Finally the page to show to the user.
<cfparam name="form.realm" default="">
<cfform action="#cgi.SCRIPT_NAME#" method="post">
Character name: <cfinput type="text" name="charactername" value="#form.charactername#"/>
Realm: <cfinput type="text" name="realm" value="#form.realm#"/>
<cfinput type="submit" name="submit" value="Find Upgrades"/>
</cfform><br/><br/><br/>
<cfif form.charactername eq "" or form.realm eq ""><cfabort></cfif>
<cfinvoke component="armory" method="getCharacterInfoSheet" returnvariable="charactersheet">
<cfinvokeargument name="realm" value="#form.realm#">
<cfinvokeargument name="charactername" value="#form.charactername#">
</cfinvoke>
<cfset characterItems = charactersheet.page.characterInfo.characterTab.items>
<cfset itemList = ArrayNew(2)>
<cfloop from="1" to="#ArrayLen(characterItems.XMLChildren)#" index="i">
<cfset itemid = characterItems.XMLChildren[i].XMLAttributes.id>
<cfset itemslot = characterItems.XMLChildren[i].XMLAttributes.slot>
<cfinvoke component="armory" method="getArmorUpgrades" returnvariable="charactersheet">
<cfinvokeargument name="realm" value="#form.realm#">
<cfinvokeargument name="charactername" value="#form.charactername#">
<cfinvokeargument name="itemid" value="#itemid#">
</cfinvoke>
<hr/>
<cfflush/>
</cfloop>
I <3 cfflush. This boils down be really very simple. 1) Pull the character sheet 2) Loop over the character's items in the character sheet 3) Get an upgrade list of each item
Now since the display portion is in the cfc currently, you're done. Later there will need to be display stuff happening here once all the data is back.


There are no comments for this entry.
[Add Comment]