Skip to content

Instantly share code, notes, and snippets.

@smb
Created October 11, 2012 10:55
Show Gist options
  • Save smb/3871618 to your computer and use it in GitHub Desktop.
Save smb/3871618 to your computer and use it in GitHub Desktop.
wow/battlenet armory pet(-name)-stalking
#!/bin/env ruby
# encoding: utf-8
require 'rubygems'
require 'json'
require 'net/http'
region = "eu"
realm = "khaz'goroth"
character = "Smb"
if ARGV[0]
character = ARGV[0]
end
if ARGV[1]
realm = ARGV[1]
end
if ARGV[2]
region = ARGV[2]
end
base_url = "http://#{region}.battle.net/api/wow/character/#{realm}/#{character}"
url = URI.escape("#{base_url}?fields=pets")
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
result = JSON.parse(data)
if result.has_key? 'Error'
raise "web service error"
end
if result['status'] == "nok"
raise "Error: #{result['reason']} for: #{region}/#{realm}/#{character}"
end
result['pets']['collected'].each { |d|
if d['name'] != d['creatureName']
print "#{d['name']} (L: #{d['stats']['level']}) => #{d['creatureName']}\n"
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment