Class: WoW::Character

Inherits:
Base
  • Object
show all
Defined in:
lib/wow/features/character.rb

Constant Summary collapse

CLASSES =
{
  1  => "warrior",
  2  => "paladin",
  3  => "hunter",
  4  => "rogue",
  5  => "priest",
  6  => "death_knight",
  7  => "shaman",
  8  => "mage",
  9  => "warlock",
  10 => "monk",
  11 => "druid",
}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#get, #get?, #gets

Constructor Details

#initialize(realm, character_name, fields = [], params = {}) ⇒ Character

Returns a new instance of Character.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/wow/features/character.rb', line 19

def initialize(realm, character_name, fields = [], params = {})
  if realm.to_s.empty?
    raise ArgumentError.new("realm cannot be blank")
  end
  if character_name.to_s.empty?
    raise ArgumentError.new("character name cannot be blank")
  end

  params = params.merge({fields: fields.join(',')})
  data = self.class.data(realm, character_name, params)

  if data.empty?
    raise APIError, "Character not active."
  end

  super(data)
end

Class Method Details

.data(realm, character_name, params = {}) ⇒ Object



38
39
40
41
42
# File 'lib/wow/features/character.rb', line 38

def data(realm, character_name, params = {})
  params.merge!({locale: WoW.locale})
  get("/#{CGI::escape(realm)}/#{CGI::escape(character_name)}",
    query: params).parsed_response
end