battle_pet 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/battle_pet.rb +19 -11
- metadata +1 -1
data/lib/battle_pet.rb
CHANGED
@@ -17,17 +17,8 @@ class BattlePet
|
|
17
17
|
PET_NAMES = YAML.load File.read(File.join(File.dirname(__FILE__), 'battle_pet.yml'))
|
18
18
|
|
19
19
|
def initialize(id, locale = :us)
|
20
|
-
|
21
|
-
info
|
22
|
-
@id = id
|
23
|
-
@description = info["description"]
|
24
|
-
@name = find_name(locale)
|
25
|
-
@source = info["source"]
|
26
|
-
@can_battle = info["canBattle"]
|
27
|
-
@type = PetType.find info["petTypeId"]
|
28
|
-
@creature = info["creatureId"]
|
29
|
-
@abilities = acquire_abilities info["abilities"]
|
30
|
-
@added_in_patch = check_patch
|
20
|
+
info = get_data_from_api(id, locale)
|
21
|
+
set_attributes(info, locale)
|
31
22
|
end
|
32
23
|
|
33
24
|
def can_battle?
|
@@ -35,6 +26,23 @@ class BattlePet
|
|
35
26
|
end
|
36
27
|
|
37
28
|
protected
|
29
|
+
|
30
|
+
def get_data_from_api(id, locale)
|
31
|
+
url = "http://#{host(locale)}/api/wow/battlePet/species/#{id.to_s}"
|
32
|
+
JSON.parse(open(url).read)
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_attributes(hash, locale)
|
36
|
+
@id = hash["speciesId"]
|
37
|
+
@description = hash["description"]
|
38
|
+
@name = find_name(locale)
|
39
|
+
@source = hash["source"]
|
40
|
+
@can_battle = hash["canBattle"]
|
41
|
+
@type = PetType.find hash["petTypeId"]
|
42
|
+
@creature = hash["creatureId"]
|
43
|
+
@abilities = acquire_abilities hash["abilities"]
|
44
|
+
@added_in_patch = check_patch
|
45
|
+
end
|
38
46
|
|
39
47
|
def host(locale)
|
40
48
|
REGION_HOSTS[locale] || REGION_HOSTS[:us]
|