wowget 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/wowget.rb +4 -4
- data/lib/wowget/item.rb +231 -0
- data/lib/wowget/spell.rb +53 -0
- data/spec/item_spec.rb +85 -0
- data/spec/spell_spec.rb +52 -0
- metadata +11 -7
data/lib/wowget.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require 'wowget/item.rb'
|
2
|
+
|
3
|
+
module Wowget
|
4
|
+
# ...
|
5
5
|
end
|
data/lib/wowget/item.rb
ADDED
@@ -0,0 +1,231 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Wowget
|
6
|
+
class Item
|
7
|
+
attr_accessor :id
|
8
|
+
attr_accessor :name
|
9
|
+
attr_accessor :level
|
10
|
+
attr_accessor :quality_id
|
11
|
+
attr_accessor :item_class_id
|
12
|
+
attr_accessor :item_subclass_id
|
13
|
+
attr_accessor :icon_id
|
14
|
+
attr_accessor :icon_name
|
15
|
+
attr_accessor :required_level
|
16
|
+
attr_accessor :inventory_slot_id
|
17
|
+
attr_accessor :buy_price
|
18
|
+
attr_accessor :sell_price
|
19
|
+
attr_accessor :recipe_id
|
20
|
+
attr_accessor :error
|
21
|
+
|
22
|
+
ITEM_QUALITIES = ['Poor', 'Common', 'Uncommon', 'Rare', 'Epic', 'Legendary', 'Artifact', 'Heirloom']
|
23
|
+
ITEM_CLASSES = {
|
24
|
+
0 => 'Consumables',
|
25
|
+
1 => 'Containers',
|
26
|
+
2 => 'Weapons',
|
27
|
+
3 => 'Gems',
|
28
|
+
4 => 'Armor',
|
29
|
+
7 => 'Trade Goods',
|
30
|
+
9 => 'Recipes',
|
31
|
+
10 => 'Currency',
|
32
|
+
12 => 'Quest',
|
33
|
+
13 => 'Keys',
|
34
|
+
15 => 'Miscellaneous',
|
35
|
+
16 => 'Glyphs'
|
36
|
+
}
|
37
|
+
ITEM_SUBCLASSES = {
|
38
|
+
'Consumables' => {
|
39
|
+
0 => 'Consumables',
|
40
|
+
1 => 'Potions',
|
41
|
+
2 => 'Elixirs',
|
42
|
+
3 => 'Flasks',
|
43
|
+
4 => 'Scrolls',
|
44
|
+
5 => 'Food & Drinks',
|
45
|
+
6 => 'Item Enhancements (Permanent)',
|
46
|
+
-3 => 'Item Enhancements (Temporary)',
|
47
|
+
7 => 'Bandages',
|
48
|
+
8 => 'Other'
|
49
|
+
},
|
50
|
+
'Containers' => {
|
51
|
+
0 => 'Bags',
|
52
|
+
2 => 'Herb Bags',
|
53
|
+
3 => 'Enchanting Bags',
|
54
|
+
4 => 'Engineering Bags',
|
55
|
+
5 => 'Gem Bags',
|
56
|
+
6 => 'Mining Bags',
|
57
|
+
7 => 'Leatherworking Bags',
|
58
|
+
8 => 'Inscription Bags',
|
59
|
+
9 => 'Tackle Boxes'
|
60
|
+
},
|
61
|
+
'Weapons' => {
|
62
|
+
1 => 'Two-Handed Axes',
|
63
|
+
2 => 'Bows',
|
64
|
+
3 => 'Guns',
|
65
|
+
4 => 'One-Handed Maces',
|
66
|
+
5 => 'Two-Handed Maces',
|
67
|
+
6 => 'Polearms',
|
68
|
+
7 => 'One-Handed Swords',
|
69
|
+
8 => 'Two-Handed Swords',
|
70
|
+
10 => 'Staves',
|
71
|
+
13 => 'Fist Weapons',
|
72
|
+
14 => 'Miscellaneous',
|
73
|
+
15 => 'Daggers',
|
74
|
+
16 => 'Thrown',
|
75
|
+
18 => 'Crossbows',
|
76
|
+
19 => 'Wands',
|
77
|
+
20 => 'Fishing Poles'
|
78
|
+
},
|
79
|
+
'Gems' => {
|
80
|
+
1 => 'Blue',
|
81
|
+
2 => 'Yellow',
|
82
|
+
3 => 'Purple',
|
83
|
+
4 => 'Green',
|
84
|
+
5 => 'Orange',
|
85
|
+
6 => 'Meta',
|
86
|
+
7 => 'Simple',
|
87
|
+
8 => 'Prismatic',
|
88
|
+
9 => 'Hydraulic',
|
89
|
+
10 => 'Cogwheel'
|
90
|
+
},
|
91
|
+
'Armor' => {
|
92
|
+
-8 => 'Shirts',
|
93
|
+
-7 => 'Tabards',
|
94
|
+
-6 => 'Cloaks',
|
95
|
+
-5 => 'Off-hand Frills',
|
96
|
+
-4 => 'Trinkets',
|
97
|
+
-3 => 'Amulets',
|
98
|
+
-2 => 'Rings',
|
99
|
+
0 => 'Miscellaneous',
|
100
|
+
1 => 'Cloth Armor',
|
101
|
+
2 => 'Leather Armor',
|
102
|
+
3 => 'Mail Armor',
|
103
|
+
4 => 'Plate Armor',
|
104
|
+
6 => 'Shields',
|
105
|
+
11 => 'Relics'
|
106
|
+
},
|
107
|
+
'Trade Goods' => {
|
108
|
+
1 => 'Parts',
|
109
|
+
2 => 'Explosives',
|
110
|
+
3 => 'Devices',
|
111
|
+
4 => 'Jewelcrafting',
|
112
|
+
5 => 'Cloth',
|
113
|
+
6 => 'Leather',
|
114
|
+
7 => 'Metal & Stone',
|
115
|
+
8 => 'Meat',
|
116
|
+
9 => 'Herbs',
|
117
|
+
10 => 'Elemental',
|
118
|
+
11 => 'Other',
|
119
|
+
12 => 'Enchanting',
|
120
|
+
13 => 'Materials',
|
121
|
+
14 => 'Armor Enchantments',
|
122
|
+
15 => 'Weapon Enchantments'
|
123
|
+
},
|
124
|
+
'Recipes' => {
|
125
|
+
0 => 'Books ',
|
126
|
+
1 => 'Leatherworking Patterns',
|
127
|
+
2 => 'Tailoring Patterns',
|
128
|
+
3 => 'Engineering Schematics',
|
129
|
+
4 => 'Blacksmithing Plans',
|
130
|
+
5 => 'Cooking Recipes',
|
131
|
+
6 => 'Alchemy Recipes',
|
132
|
+
7 => 'First Aid Manuals',
|
133
|
+
8 => 'Enchanting Formulae',
|
134
|
+
9 => 'Fishing Books',
|
135
|
+
10 => 'Jewelcrafting Designs',
|
136
|
+
11 => 'Inscription Techniques'
|
137
|
+
},
|
138
|
+
'Miscellaneous' => {
|
139
|
+
-2 => 'Armor Tokens',
|
140
|
+
0 => 'Junk',
|
141
|
+
1 => 'Reagents',
|
142
|
+
2 => 'Companions',
|
143
|
+
3 => 'Holiday',
|
144
|
+
4 => 'Other',
|
145
|
+
5 => 'Mounts'
|
146
|
+
},
|
147
|
+
'Glyphs' => {
|
148
|
+
1 => 'Warrior',
|
149
|
+
2 => 'Paladin',
|
150
|
+
3 => 'Hunter',
|
151
|
+
4 => 'Rogue',
|
152
|
+
5 => 'Priest',
|
153
|
+
6 => 'Death Knight',
|
154
|
+
7 => 'Shaman',
|
155
|
+
8 => 'Mage',
|
156
|
+
9 => 'Warlock',
|
157
|
+
11 => 'Druid'
|
158
|
+
}
|
159
|
+
}
|
160
|
+
INVENTORY_SLOTS = {
|
161
|
+
16 => 'Back',
|
162
|
+
18 => 'Bag',
|
163
|
+
5 => 'Chest',
|
164
|
+
8 => 'Feet',
|
165
|
+
11 => 'Finger',
|
166
|
+
10 => 'Hands',
|
167
|
+
1 => 'Head',
|
168
|
+
23 => 'Held In Off-hand',
|
169
|
+
7 => 'Legs',
|
170
|
+
21 => 'Main Hand',
|
171
|
+
2 => 'Neck',
|
172
|
+
22 => 'Off Hand',
|
173
|
+
13 => 'One-Hand',
|
174
|
+
24 => 'Projectile',
|
175
|
+
15 => 'Ranged',
|
176
|
+
28 => 'Relic',
|
177
|
+
14 => 'Shield',
|
178
|
+
4 => 'Shirt',
|
179
|
+
3 => 'Shoulder',
|
180
|
+
19 => 'Tabard',
|
181
|
+
25 => 'Thrown',
|
182
|
+
12 => 'Trinket',
|
183
|
+
17 => 'Two-Hand',
|
184
|
+
6 => 'Waist',
|
185
|
+
9 => 'Wrist'
|
186
|
+
}
|
187
|
+
|
188
|
+
def initialize(item_id)
|
189
|
+
item_xml = Nokogiri::XML(open("http://www.wowhead.com/item=#{item_id}&xml"))
|
190
|
+
if item_xml.css('wowhead error').length == 1
|
191
|
+
self.error = {:error => "not found"}
|
192
|
+
else
|
193
|
+
item_json = JSON "{#{item_xml.css('wowhead item json').inner_text.strip.to_s}}"
|
194
|
+
item_equip_json = JSON "{#{item_xml.css('wowhead item jsonEquip').inner_text.strip.to_s}}"
|
195
|
+
self.id = item_id.to_i
|
196
|
+
self.name = item_xml.css('wowhead item name').inner_text.strip.to_s
|
197
|
+
self.level = item_xml.css('wowhead item level').inner_text.strip.to_i
|
198
|
+
self.quality_id = item_xml.css('wowhead item quality').attribute('id').content.to_i
|
199
|
+
self.item_class_id = item_xml.css('wowhead item class').attribute('id').content.to_i
|
200
|
+
self.item_subclass_id = item_xml.css('wowhead item subclass').attribute('id').content.to_i
|
201
|
+
self.icon_id = item_xml.css('wowhead item icon').attribute('displayId').content.to_i
|
202
|
+
self.icon_name = item_xml.css('wowhead item icon').inner_text.strip.to_s
|
203
|
+
self.required_level = item_json['reqlevel']
|
204
|
+
self.inventory_slot_id = item_xml.css('wowhead item inventorySlot').attribute('id').content.to_i
|
205
|
+
self.buy_price = item_equip_json['buyprice']
|
206
|
+
self.sell_price = item_equip_json['sellprice']
|
207
|
+
|
208
|
+
if item_xml.css('wowhead item createdBy').length == 1
|
209
|
+
self.recipe_id = item_xml.css('wowhead item createdBy spell').attribute('id').content.to_i
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def quality
|
215
|
+
ITEM_QUALITIES[self.quality_id]
|
216
|
+
end
|
217
|
+
|
218
|
+
def item_class
|
219
|
+
ITEM_CLASSES[self.item_class_id]
|
220
|
+
end
|
221
|
+
|
222
|
+
def item_subclass
|
223
|
+
ITEM_SUBCLASSES[self.item_class][self.item_subclass_id]
|
224
|
+
end
|
225
|
+
|
226
|
+
def inventory_slot
|
227
|
+
INVENTORY_SLOTS[self.inventory_slot_id]
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
end
|
data/lib/wowget/spell.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module Wowget
|
5
|
+
class Spell
|
6
|
+
attr_accessor :id
|
7
|
+
attr_accessor :name
|
8
|
+
attr_accessor :item_id
|
9
|
+
attr_accessor :reagents
|
10
|
+
attr_accessor :profession
|
11
|
+
attr_accessor :skill_level
|
12
|
+
attr_accessor :error
|
13
|
+
|
14
|
+
def initialize(spell_id)
|
15
|
+
begin
|
16
|
+
url = open("http://www.wowhead.com/spell=#{spell_id}")
|
17
|
+
rescue
|
18
|
+
not_found = true
|
19
|
+
end
|
20
|
+
|
21
|
+
spell_xml = Nokogiri::XML(url) unless not_found
|
22
|
+
|
23
|
+
if not_found || spell_xml.css('div#inputbox-error').length == 1
|
24
|
+
self.error = {:error => "not found"}
|
25
|
+
else
|
26
|
+
self.name = spell_xml.css('div.text h1').inner_text.strip.to_s
|
27
|
+
|
28
|
+
if spell_xml.css('table#spelldetails td span.q4 a').length == 1
|
29
|
+
self.item_id = spell_xml.css('table#spelldetails td span.q4 a').attribute('href').content.scan(/\/item=([0-9]+)/)[0][0].to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
# reagents
|
33
|
+
if spell_xml.css("h3:contains('Reagents')").length == 1
|
34
|
+
self.reagents = []
|
35
|
+
reagents = spell_xml.css("h3:contains('Reagents')+table.iconlist tr td")
|
36
|
+
reagents.each do |r|
|
37
|
+
item_id = r.css("span a").attribute('href').content.scan(/\/item=([0-9]+)/)[0][0].to_i
|
38
|
+
quantity = r.content.scan(/\(([0-9]+)\)$/)[0][0].to_i
|
39
|
+
self.reagents.push({:item => Wowget::Item.new(item_id), :quantity => quantity})
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# profession
|
44
|
+
unless self.item_id.nil?
|
45
|
+
p = spell_xml.xpath("//script[contains(., 'Markup')]").inner_text.scan(/\[ul\]\[li\](.+?)\[\/li\]/)[0][0].scan(/Requires (.+?) \(([0-9]+?)\)/)[0]
|
46
|
+
self.profession = p[0]
|
47
|
+
self.skill_level = p[1].to_i
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
data/spec/item_spec.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
require "lib/wowget/item.rb"
|
2
|
+
|
3
|
+
describe Wowget::Item do
|
4
|
+
|
5
|
+
describe "With a valid ID" do
|
6
|
+
item = Wowget::Item.new(4817)
|
7
|
+
|
8
|
+
it "should have an item name" do
|
9
|
+
item.name.should == "Blessed Claymore"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have an item level" do
|
13
|
+
item.level.should == 22
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have a quality value" do
|
17
|
+
item.quality_id.should == 2
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a quality name" do
|
21
|
+
item.quality.should == "Uncommon"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have an item class value" do
|
25
|
+
item.item_class_id.should == 2
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have an item class name" do
|
29
|
+
item.item_class.should == "Weapons"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have an item subclass value" do
|
33
|
+
item.item_subclass_id.should == 8
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have an item subclass name" do
|
37
|
+
item.item_subclass.should == "Two-Handed Swords"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have an icon value" do
|
41
|
+
item.icon_id.should == 7319
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should have an icon name" do
|
45
|
+
item.icon_name.should == "INV_Sword_13"
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should have an inventory slot value" do
|
49
|
+
item.inventory_slot_id.should == 17
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have an inventory slot name" do
|
53
|
+
item.inventory_slot.should == "Two-Hand"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should have a required minimum level" do
|
57
|
+
item.required_level.should == 17
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should have a vendor sell price" do
|
61
|
+
item.sell_price.should == 2462
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should have a vendor buy price" do
|
65
|
+
item.buy_price.should == 12311
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "With a recipe" do
|
71
|
+
item = Wowget::Item.new(45559)
|
72
|
+
|
73
|
+
it "should have a recipe spell to create this item" do
|
74
|
+
item.recipe_id.should == 63188
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "With an invalid ID" do
|
79
|
+
item = Wowget::Item.new(nil)
|
80
|
+
it "should return an error" do
|
81
|
+
item.error.should == {:error => "not found"}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
data/spec/spell_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "lib/wowget/item.rb"
|
2
|
+
require "lib/wowget/spell.rb"
|
3
|
+
|
4
|
+
describe Wowget::Spell do
|
5
|
+
|
6
|
+
describe "With a valid ID" do
|
7
|
+
spell = Wowget::Spell.new(63188)
|
8
|
+
|
9
|
+
it "should have a spell name" do
|
10
|
+
spell.name.should == "Battlelord's Plate Boots"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "With a recipe" do
|
16
|
+
spell = Wowget::Spell.new(63188)
|
17
|
+
|
18
|
+
it "should have the ID for the item it produces" do
|
19
|
+
spell.item_id.should == 45559
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have a list of reagents" do
|
23
|
+
spell.reagents.length.should == 2 and
|
24
|
+
spell.reagents.all? {|r| r[:item].class == Wowget::Item}.should == true and
|
25
|
+
spell.reagents[0][:item].name.should == 'Titansteel Bar' and
|
26
|
+
spell.reagents[0][:quantity].should == 5 and
|
27
|
+
spell.reagents[1][:item].name.should == 'Runed Orb' and
|
28
|
+
spell.reagents[1][:quantity].should == 6
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have a professional skill requirement" do
|
32
|
+
spell.profession.should == 'Blacksmithing' and
|
33
|
+
spell.skill_level.should == 450
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "Without a recipe" do
|
38
|
+
spell = Wowget::Spell.new(50842)
|
39
|
+
|
40
|
+
it "shouldn't have an ID for an item" do
|
41
|
+
spell.item_id.should == nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "With an invalid ID" do
|
46
|
+
spell = Wowget::Spell.new(nil)
|
47
|
+
it "should return an error" do
|
48
|
+
spell.error.should == {:error => "not found"}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wowget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ben Darlow
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-27 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
22
|
-
description:
|
22
|
+
description: Ruby API to wowhead.com's item and spell database.
|
23
23
|
email: ben@kapowaz.net
|
24
24
|
executables: []
|
25
25
|
|
@@ -28,7 +28,11 @@ extensions: []
|
|
28
28
|
extra_rdoc_files: []
|
29
29
|
|
30
30
|
files:
|
31
|
+
- lib/wowget/item.rb
|
32
|
+
- lib/wowget/spell.rb
|
31
33
|
- lib/wowget.rb
|
34
|
+
- spec/item_spec.rb
|
35
|
+
- spec/spell_spec.rb
|
32
36
|
has_rdoc: true
|
33
37
|
homepage: http://github.com/kapowaz/wowget
|
34
38
|
licenses: []
|
@@ -59,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
63
|
requirements: []
|
60
64
|
|
61
65
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.
|
66
|
+
rubygems_version: 1.3.7
|
63
67
|
signing_key:
|
64
68
|
specification_version: 3
|
65
69
|
summary: wowget
|