Permalink
Browse files

Started to add achievements

Use api.get_character_achievements to get a CharacterAchievementsInfos.
You can access to the latest modified achievements using CharacterAchievementsInfos#latest_achievements.

Coming soon : achievement categories

Signed-off-by: Peter Wood <peter@alastria.net>
  • Loading branch information...
1 parent 0a053fc commit dea0d848ba4fe0af97173a44830c669d7b95c4bc @renchap renchap committed with pwood Mar 24, 2009
Showing with 53 additions and 1 deletion.
  1. +14 −1 lib/wowr.rb
  2. +39 −0 lib/wowr/achievements.rb
View
@@ -30,6 +30,7 @@
require 'wowr/calendar.rb'
require 'wowr/character.rb'
+require 'wowr/achievements.rb'
require 'wowr/guild.rb'
require 'wowr/item.rb'
require 'wowr/arena_team.rb'
@@ -52,7 +53,7 @@ class API
@@character_talents_url = 'character-talents.xml'
@@character_reputation_url = 'character-reputation.xml'
- @@character_achievements_url = 'character_achievements.xml'
+ @@character_achievements_url = 'character-achievements.xml'
@@calendar_user_url = 'vault/calendar/month-user.json'
@@calendar_world_url = 'vault/calendar/month-world.json'
@@ -230,6 +231,18 @@ def get_character(name = @character_name, options = {})
def get_character_sheet(name = @character_name, options = {})
return get_character(name, options)
end
+
+ # Get achievement infos for a character.
+ # Requires realm.
+ # * name (String) Name of the character to get, defaults to that specified in constructor
+ # * options (Hash) Optional hash of arguments identical to those used in the API constructor (realm, debug, cache etc.)
+ def get_character_achievements(name = @character_name, options = {})
+ options = character_options(name, options)
+
+ character_achievements = get_xml(@@character_achievements_url, options)
+
+ return Wowr::Classes::CharacterAchievementsInfos.new(character_achievements, self)
+ end
# Find all guilds with the given string, return array of Wowr::Classes::SearchGuild.
# Searches across all realms.
View
@@ -0,0 +1,39 @@
+module Wowr
+ module Classes
+ class CharacterAchievementsInfos
+ attr_reader :latest_achievements
+
+ def initialize elem, api
+ @api = api
+ @latest_achievements = Array.new
+
+ achievements = elem%'achievements'
+
+ summary = achievements%'summary'
+ summary.search('achievement').each do |achievement|
+ @latest_achievements << CompletedAchievement.new(achievement)
+ end
+ end
+ end
+
+ class Achievement
+ attr_reader :desc, :title, :category_id, :icon, :id, :points, :title
+ def initialize achievement
+ @desc = achievement['desc']
+ @category_id = achievement['categoryId']
+ @icon = achievement['icon']
+ @id = achievement['id']
+ @points = achievement['points']
+ @title = achievement['title']
+ end
+ end
+
+ class CompletedAchievement < Achievement
+ attr_reader :date_completed
+ def initialize achievement
+ super(achievement)
+ @date_completed = achievement['dateCompleted']
+ end
+ end
+ end
+end

0 comments on commit dea0d84

Please sign in to comment.