Skip to content
Browse files

support for optional Character fields

  • Loading branch information...
1 parent 5707422 commit 715490ddc3a2fe7d612896d6088cb0031475fc12 @defeated committed Jul 19, 2011
View
5 lib/wow_community_api/character.rb
@@ -1,7 +1,8 @@
module WowCommunityApi
class Character < BattleNet
- def self.find_by_realm_and_name(realm, name)
- get("/character/#{realm}/#{name}")
+ def self.find_by_realm_and_name(realm, name, *field)
+ fields = { :fields => field.join(",") } if field.size > 0
@incendium
incendium added a note Jul 20, 2011

Small nitpick: how about unless field.empty? instead of if field.size > 0?

@defeated
Owner
defeated added a note Jul 20, 2011

absolutely that's more idiomatic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ get("/character/#{realm}/#{name}", :query => fields)
end
end
end
View
17 spec/character_spec.rb
@@ -16,5 +16,22 @@
character.realm.should == 'Altar of Storms'
character.name.should == 'Johndoe'
end
+
+ it 'gets a character with optional field guild' do
+ stub_json 'http://us.battle.net/api/wow/character/uther/malkyth?fields=guild', 'character-guild.json'
+
+ character = Character.find_by_realm_and_name('uther', 'malkyth', :guild)
+ character.guild.name.should == "Havok"
+ character.guild.emblem.icon.should == 106
+ end
+
+ it 'gets a character with multiple optional fields' do
+ stub_json 'http://us.battle.net/api/wow/character/uther/malkyth?fields=guild,titles', 'character-all-fields.json'
+
+ character = Character.find_by_realm_and_name('uther', 'malkyth', :guild, :titles)
+ character.guild.name.should == "Havok"
+ character.titles.size.should == 3
+ character.titles[0].name.should == "Centurion %s"
+ end
end
end
View
39 spec/fixtures/character-all-fields.json
@@ -0,0 +1,39 @@
+{
+ "lastModified":1311111102000,
+ "name":"Malkyth",
+ "realm":"Uther",
+ "class":9,
+ "race":5,
+ "gender":0,
+ "level":85,
+ "achievementPoints":11030,
+ "thumbnail":"uther/243/6004211-avatar.jpg",
+ "guild":{
+ "name":"Havok",
+ "realm":"Uther",
+ "level":25,
+ "members":525,
+ "achievementPoints":1425,
+ "emblem":{
+ "icon":106,
+ "iconColor":"ffffff00",
+ "border":0,
+ "borderColor":"ffffffff",
+ "backgroundColor":"ffffff91"
+ }
+ },
+ "titles":[
+ {
+ "id":23,
+ "name":"Centurion %s"
+ },
+ {
+ "id":47,
+ "name":"Conqueror %s"
+ },
+ {
+ "id":81,
+ "name":"%s the Seeker"
+ }
+ ]
+}
View
25 spec/fixtures/character-guild.json
@@ -0,0 +1,25 @@
+{
+ "lastModified":1311111102000,
+ "name":"Malkyth",
+ "realm":"Uther",
+ "class":9,
+ "race":5,
+ "gender":0,
+ "level":85,
+ "achievementPoints":11030,
+ "thumbnail":"uther/243/6004211-avatar.jpg",
+ "guild":{
+ "name":"Havok",
+ "realm":"Uther",
+ "level":25,
+ "members":525,
+ "achievementPoints":1425,
+ "emblem":{
+ "icon":106,
+ "iconColor":"ffffff00",
+ "border":0,
+ "borderColor":"ffffffff",
+ "backgroundColor":"ffffff91"
+ }
+ }
+}

0 comments on commit 715490d

Please sign in to comment.
Something went wrong with that request. Please try again.