1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Add your character/realm name
CHARACTER_NAME = set_your_character_name
REALM_NAME = set_your_realm_name

# Get the cookie data from the headers of a normal request after having logged into the Armory
# easy to do with firebug
COOKIE_STRING = some_cookie_string

require 'net/http'
require 'uri'
require 'rubygems'
require 'json/pure'
require 'pp'

class Rah
  def self.hash_to_param_string(hsh)
    hsh.inject([]){|res,el| res << "#{URI.escape(el[0])}=#{URI.escape(el[1])}"; res}.join("&")
  end

  def self.search(id)
    url = URI.parse('http://www.wowarmory.com/auctionhouse/search.json')

    headers = {
      'user-agent' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.3) Gecko/20100423 Ubuntu/10.04 (lucid) Firefox/3.6.3',
      'x-requested-with' => 'XMLHttpRequest',
      'keep-alive' => '120',
      'cookie' => COOKIE_STRING
    }

    params = {
      'cn' => CHARACTER_NAME,
      'r'  => REALM_NAME,
      'id'  => id,
      "sort" => "unitbuyout",
      "reverse" => "false"
    }

    param_string = hash_to_param_string(params)

    http = Net::HTTP.new(url.host)

    res = http.request_get(
      "#{url.path}?#{param_string}",
      headers
    )

    JSON.parse(res.body)['auctionSearch']['auctions']
  end
end

results = Rah.search("40113")
results.each{|r| puts r["seller"]; puts r["buy"].to_i / r["quan"].to_i}