Class: Wowr::API
- Inherits:
-
Object
- Object
- Wowr::API
- Defined in:
- lib/wowr.rb
Constant Summary collapse
- @@armory_url =
'http://www.wowarmory.com/'
- @@eu_armory_url =
'http://eu.wowarmory.com/'
- @@search_url =
'search.xml'
- @@character_sheet_url =
'character-sheet.xml'
- @@character_talents_url =
'character-talents.xml'
- @@character_skills_url =
'character-skills.xml'
- @@character_reputation_url =
'character-reputation.xml'
- @@guild_info_url =
'guild-info.xml'
- @@item_info_url =
'item-info.xml'
- @@item_tooltip_url =
'item-tooltip.xml'
- @@arena_team_url =
'team-info.xml'
- @@max_connection_tries =
10
- @@cache_directory_path =
'cache/'
- @@classes =
Part of the rails plugin stuff? @@profession_icons = { :alchemy => “Trade_Alchemy.png”, :blacksmithing => “Trade_BlackSmithing.png”, :engineering => “Trade_Engineering.png”, :enchanting => “Trade_Engraving.png”, :jewelcrafting => “INV_Hammer_21.png”, :herbalism => “Trade_Herbalism.png”, :leatherworking => “Trade_LeatherWorking.png”, :mining => “Trade_Mining.png”, :tailoring => “Trade_Tailoring.png”, :skinning => “INV_Weapon_ShortBlade_01.png” }
{ 1 => 'Warrior', 2 => 'Paladin', 3 => 'Hunter', 4 => 'Rogue', 5 => 'Priest', #6 => 'Gold Farmer', # there is no class 6 7 => 'Shaman', 8 => 'Mage', 9 => 'Warlock', #10 => 'Purveyor of Baked Goods', # there is no class 10 11 => 'Druid' }
- @@genders =
{ 0 => 'Male', 1 => 'Female' }
- @@races =
{ 1 => 'Human', 1 => 'Orc', 3 => 'Dwarf', 4 => 'Night Elf', 5 => 'Undead', 6 => 'Tauren', 7 => 'Gnome', 8 => 'Troll', #9 => 'Pandaren', # there is no race 9 10 => 'Blood Elf', 11 => 'Draenei' }
- @@search_types =
{ #:all => 'all', # TODO: All is too complex at the moment, API doesn't return all results in one query :item => 'items', :character => 'characters', :guild => 'guilds', :arena_team => 'arenateams' }
- @@arena_team_sizes =
[2, 3, 5]
Instance Attribute Summary collapse
-
#caching ⇒ Object
Returns the value of attribute caching.
-
#character_name ⇒ Object
Returns the value of attribute character_name.
-
#guild_name ⇒ Object
Returns the value of attribute guild_name.
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#realm ⇒ Object
Returns the value of attribute realm.
Instance Method Summary collapse
-
#clear_cache(cache_path = @@cache_directory_path) ⇒ Object
Clear the cache, optional filename.
- #get_arena_team(options = {:team_name => :nil, :team_size => nil, :realm => @realm, :caching => @caching}) ⇒ Object
- #get_character_sheet(options = {:character_name => @character_name, :realm => @realm, :caching => @caching}) ⇒ Object
- #get_guild(options = {:guild_name => @guild_name, :realm => @realm, :caching => @caching}) ⇒ Object
-
#get_item_info(options = {:item_id => nil, :locale => @locale, :caching => @caching}) ⇒ Object
end.
- #get_item_tooltip(options = {:item_id => nil, :caching => @caching}) ⇒ Object
-
#initialize(options = {:character_name => nil, :guild_name => nil, :realm => nil, :locale => :us, :caching => false}) ⇒ API
constructor
You can set up the API with an optional default guild and realm These will be used in all your API requests unless you specify otherwise For item requests, the locale will not matter in results, but may affect the speed of replies Caching is off by default TODO: are these nil declarations pointless?.
-
#search(options = {:search => nil, :type => nil}) ⇒ Object
General-purpose search All specific searches are wrappers around this method.
-
#search_arena_teams(options = {}) ⇒ Object
Arena Teams Caching is disabled for searching.
-
#search_characters(options = {:name => @character_name}) ⇒ Object
Characters Note searches go across all realms by default Caching is disabled for searching.
-
#search_guilds(options = {:search => @guild_name, :locale => @locale}) ⇒ Object
Guilds Note searches go across all realms by default Caching is disabled for searching.
-
#search_items(options = {:search => nil}) ⇒ Object
Items Items are not realm-specific Caching is disabled for searching.
Constructor Details
#initialize(options = {:character_name => nil, :guild_name => nil, :realm => nil, :locale => :us, :caching => false}) ⇒ API
You can set up the API with an optional default guild and realm These will be used in all your API requests unless you specify otherwise For item requests, the locale will not matter in results, but may affect the speed of replies Caching is off by default TODO: are these nil declarations pointless?
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/wowr.rb', line 122 def initialize( = {:character_name => nil, :guild_name => nil, :realm => nil, :locale => :us, :caching => false}) @character_name = [:character_name] @guild_name = [:guild_name] @realm = [:realm] @locale = [:locale] #|| :us @caching = [:caching] end |
Instance Attribute Details
#caching ⇒ Object
Returns the value of attribute caching.
115 116 117 |
# File 'lib/wowr.rb', line 115 def caching @caching end |
#character_name ⇒ Object
Returns the value of attribute character_name.
115 116 117 |
# File 'lib/wowr.rb', line 115 def character_name @character_name end |
#guild_name ⇒ Object
Returns the value of attribute guild_name.
115 116 117 |
# File 'lib/wowr.rb', line 115 def guild_name @guild_name end |
#locale ⇒ Object
Returns the value of attribute locale.
115 116 117 |
# File 'lib/wowr.rb', line 115 def locale @locale end |
#realm ⇒ Object
Returns the value of attribute realm.
115 116 117 |
# File 'lib/wowr.rb', line 115 def realm @realm end |
Instance Method Details
#clear_cache(cache_path = @@cache_directory_path) ⇒ Object
Clear the cache, optional filename
281 282 283 284 285 286 287 |
# File 'lib/wowr.rb', line 281 def clear_cache(cache_path = @@cache_directory_path) begin FileUtils.remove_dir(cache_path) rescue Exception => e end end |
#get_arena_team(options = {:team_name => :nil, :team_size => nil, :realm => @realm, :caching => @caching}) ⇒ Object
265 266 267 268 269 270 271 272 |
# File 'lib/wowr.rb', line 265 def get_arena_team( = {:team_name => :nil, :team_size => nil, :realm => @realm, :caching => @caching}) if !@@arena_team_sizes.include?([:team_size]) raise Wowr::Exceptions::InvalidArenaTeamSize.new("Arena teams size must be: #{@@arena_team_sizes.inspect}") end xml = get_xml(@@arena_team_url, ) return Wowr::Classes::ArenaTeam.new(xml%'arenaTeam') end |
#get_character_sheet(options = {:character_name => @character_name, :realm => @realm, :caching => @caching}) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/wowr.rb', line 192 def get_character_sheet( = {:character_name => @character_name, :realm => @realm, :caching => @caching}) xml = get_xml(@@character_sheet_url, ) # resist_types = ['arcane', 'fire', 'frost', 'holy', 'nature', 'shadow'] # @resistances = {} # resist_types.each do |res| # @resistances[res] = Wowr::Classes::Resistance.new(xml%'resistances'%res) # end # puts @resistances.to_yaml puts xml return Wowr::Classes::CharacterSheet.new(xml) end |
#get_guild(options = {:guild_name => @guild_name, :realm => @realm, :caching => @caching}) ⇒ Object
215 216 217 218 |
# File 'lib/wowr.rb', line 215 def get_guild( = {:guild_name => @guild_name, :realm => @realm, :caching => @caching}) xml = get_xml(@@guild_info_url, ) return Wowr::Classes::Guild.new(xml) end |
#get_item_info(options = {:item_id => nil, :locale => @locale, :caching => @caching}) ⇒ Object
end
236 237 238 239 240 241 242 243 |
# File 'lib/wowr.rb', line 236 def get_item_info( = {:item_id => nil, :locale => @locale, :caching => @caching}) xml = get_xml(@@item_info_url, ) if (xml%'itemInfo'%'item') return Wowr::Classes::ItemInfo.new(xml%'itemInfo'%'item') else return nil end end |
#get_item_tooltip(options = {:item_id => nil, :caching => @caching}) ⇒ Object
245 246 247 248 249 250 251 252 253 254 |
# File 'lib/wowr.rb', line 245 def get_item_tooltip( = {:item_id => nil, :caching => @caching}) xml = get_xml(@@item_tooltip_url, ) # tooltip returns empty document when not found if xml.nil? return nil #raise Wowr::Exceptions::ItemNotFound.new("Item not found with id: #{options[:item_id]}") end return Wowr::Classes::ItemTooltip.new(xml%'itemTooltip') end |
#search(options = {:search => nil, :type => nil}) ⇒ Object
General-purpose search All specific searches are wrappers around this method. Caching is disabled for searching
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/wowr.rb', line 138 def search( = {:search => nil, :type => nil}) if @@search_types.include? [:type] raise Wowr::Exceptions::InvalidSearchType.new end if [:search].nil? raise Wowr::Exceptions::NoSearchString.new end .merge!(:caching => false) xml = get_xml(@@search_url, ) results = [] if (xml) && (xml%'armorySearch') && (xml%'armorySearch'%'searchResults') case [:type] # TODO: Filter stuff when @@search_types[:item] (xml%'armorySearch'%'searchResults'%'items'/:item).each do |item| results << Wowr::Classes::SearchItem.new(item) end when @@search_types[:character] (xml%'armorySearch'%'searchResults'%'characters'/:character).each do |char| results << Wowr::Classes::Character.new(char) end when @@search_types[:guild] (xml%'armorySearch'%'searchResults'%'guilds'/:guild).each do |guild| results << Wowr::Classes::Guild.new(guild) end when @@search_types[:arena_team] (xml%'armorySearch'%'searchResults'%'arenaTeams'/:arenaTeam).each do |team| results << Wowr::Classes::ArenaTeam.new(team) end end end return results end |
#search_arena_teams(options = {}) ⇒ Object
Arena Teams Caching is disabled for searching
260 261 262 263 |
# File 'lib/wowr.rb', line 260 def search_arena_teams( = {}) .merge!(:type => @@search_types[:arena_team]) return search() end |
#search_characters(options = {:name => @character_name}) ⇒ Object
Characters Note searches go across all realms by default Caching is disabled for searching
187 188 189 190 |
# File 'lib/wowr.rb', line 187 def search_characters( = {:name => @character_name}) .merge!(:type => @@search_types[:character]) return search() end |
#search_guilds(options = {:search => @guild_name, :locale => @locale}) ⇒ Object
Guilds Note searches go across all realms by default Caching is disabled for searching
210 211 212 213 |
# File 'lib/wowr.rb', line 210 def search_guilds( = {:search => @guild_name, :locale => @locale}) .merge!(:type => @@search_types[:guild]) return search() end |
#search_items(options = {:search => nil}) ⇒ Object
Items Items are not realm-specific Caching is disabled for searching
225 226 227 228 |
# File 'lib/wowr.rb', line 225 def search_items( = {:search => nil}) .merge!(:type => @@search_types[:item]) return search() end |