I haven’t been playing World of Warcraft for a bit, but I guess they did some big updates to the armory which stopped the code I had written before from running correctly. (Link to the old code, Ruby and Groovy)

After looking in to what has changed, I found out they added a new REST API for Battle.net which lets you pull data easily without the need of tricking the server to pass you XML. From the API, we get nice JSON data to work with. So here is some new code in Ruby, Groovy and CoffeeScript (running on Node.js) that can be used to get about the same output as the code I had before. (Link to gist)

Ruby

require 'rubygems'
require 'httparty'
type = {
1 => "Warrior", 2 => "Paladin", 3 => "Hunter",
4 => "Rogue", 5 => "Priest", 6 => "Death Knight",
7 => "Shaman", 8 => "Mage", 9 => "Warlock",
10 => "Monk", 11 => "Druid"
}
type.default = "unknown"
strRealm = "Staghelm"
strGuildName = "Controlled Chaos"
data = HTTParty.get("http://us.battle.net/api/wow/guild/#{URI.escape(strRealm)}/#{URI.escape(strGuildName)}?fields=members").parsed_response
puts "#{data["members"].count} Characters Found!"
puts "-" * 50
data["members"].sort{|a,b| a["character"]['name'] <=> b["character"]['name']}.each do |member|
c = member["character"]
puts "%-20s%-10s%s" %[c['name'],c['level'],type[c['class']]]
end
puts "-" * 50
view raw wowapi.rb hosted with ❤ by GitHub

Groovy

import groovy.json.*
def realm = URLEncoder.encode("Staghelm")
def guild = URLEncoder.encode("Controlled Chaos").replace("+", "%20")
def url = "http://us.battle.net/api/wow/guild/${realm}/${guild}?fields=members".toURL()
def type = [
1: "Warrior", 2: "Paladin", 3: "Hunter",
4: "Rogue", 5: "Priest", 6: "Death Knight",
7: "Shaman", 8: "Mage", 9: "Warlock",
10: "Monk", 11: "Druid"].withDefault { key -> "unknown" }
url.openConnection().with {
inputStream.withReader { reader ->
def characters = new JsonSlurper().parse(reader)
println "${characters.members.size} Characters Found!"
println "-" * 50
characters.members.character.sort{ it.name }.each { t ->
printf "%-20s%-10s%s\n", t.name, t.level, type[t.class]
}
println "-" * 50
}
}
view raw wowapi.groovy hosted with ❤ by GitHub

CoffeeScript

http = require 'http'
rest = require 'restler'
realm = escape "Staghelm"
guild = escape "Controlled Chaos"
type = {
1: "Warrior", 2: "Paladin", 3: "Hunter",
4: "Rogue", 5: "Priest", 6: "Death Knight",
7: "Shaman", 8: "Mage", 9: "Warlock",
10: "Monk", 11: "Druid"
}
rest.get("http://us.battle.net/api/wow/guild/#{realm}/#{guild}?fields=members").on('complete', (data) ->
data.members.sort( (a,b) ->
if a.character.name > b.character.name
return 1
if a.character.name < b.character.name
return -1
return 0
)
console.log "#{data.members.length} Characters Found!"
console.log "--------"
for char in data.members
console.log "#{char.character.name} #{char.character.level} #{type[char.character.class]}"
console.log "--------"
)
view raw wowapi.coffee hosted with ❤ by GitHub

For more info on the Battle.net API check out the API Documentation

If you have any questions or comments please post, also any suggestions on improving this are welcome as I’m sure there are ways to improve the code.