battle_pet 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +9 -0
- data/lib/battle_pet.rb +56 -0
- data/lib/battle_pet.yml +1995 -0
- metadata +47 -0
data/README.md
ADDED
data/lib/battle_pet.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
class BattlePet
|
6
|
+
attr_accessor :id, :name, :description, :source, :type, :creature
|
7
|
+
|
8
|
+
REGION_HOSTS = { us: 'us.battle.net',
|
9
|
+
eu: 'eu.battle.net',
|
10
|
+
kr: 'kr.battle.net',
|
11
|
+
tw: 'tw.battle.net',
|
12
|
+
cn: 'www.battlenet.com.cn'}
|
13
|
+
|
14
|
+
PET_NAMES = YAML.load File.read(File.join(File.dirname(__FILE__), 'battle_pet.yml'))
|
15
|
+
|
16
|
+
PET_TYPES = { 0 => 'Humanoid',
|
17
|
+
1 => 'Dragonkin',
|
18
|
+
2 => 'Flying',
|
19
|
+
3 => 'Undead',
|
20
|
+
4 => 'Critter',
|
21
|
+
5 => 'Magical',
|
22
|
+
6 => 'Elemental',
|
23
|
+
7 => 'Beast',
|
24
|
+
8 => 'Aquatic',
|
25
|
+
9 => 'Mechanical' }
|
26
|
+
|
27
|
+
def initialize(id, locale = :us)
|
28
|
+
url = "http://#{host(locale)}/api/wow/battlePet/species/#{id.to_s}"
|
29
|
+
info = JSON.parse(open(url).read)
|
30
|
+
@id = id
|
31
|
+
@description = info["description"]
|
32
|
+
@name = find_name(locale)
|
33
|
+
@source = info["source"]
|
34
|
+
@can_battle = info["canBattle"]
|
35
|
+
@type = pet_type info["petTypeId"]
|
36
|
+
@creature = info["creatureId"]
|
37
|
+
end
|
38
|
+
|
39
|
+
def can_battle?
|
40
|
+
@can_battle
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
def host(locale)
|
46
|
+
REGION_HOSTS[locale] || REGION_HOSTS[:us]
|
47
|
+
end
|
48
|
+
|
49
|
+
def find_name(locale)
|
50
|
+
PET_NAMES[id] && PET_NAMES[id]["name"][locale.to_s]
|
51
|
+
end
|
52
|
+
|
53
|
+
def pet_type(type_id)
|
54
|
+
PET_TYPES[type_id]
|
55
|
+
end
|
56
|
+
end
|