Class: MyWoWArmory

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mywowarmory.rb

Defined Under Namespace

Classes: Profile

Instance Method Summary collapse

Instance Method Details

#get_profile(country, realm, character_name, options = {}) ⇒ Object

def initialize(username,password,options={})

@auth = {:username => username, :password => password}

end



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mywowarmory.rb', line 16

def get_profile(country,realm,character_name,options={})
  # options.merge!({:basic_auth => @auth})
  
  # detect the input as URL encoded or not by finding "%NN" character
  name = character_name.match(/%[0-9A-F]{2}/i) ? character_name : URI::encode(character_name)
  # name = URI::encode(URI::decode(character_name))
  
  # Check the realm
  realm_response = HTTParty.get("http://#{country}.battle.net/api/wow/realm/status", :query => {:realms => URI.encode(realm)} ).parsed_response
  realm = realm_response['realms'].select{|r| r['name'] == realm}.first['slug']
  
  query = {:name => name, :server => realm, :country => country}
  query.merge!(:style => options[:style]) if options[:style].present?

  MultiJson.decode(self.class.get("/api/getprofile.php", options.merge(:query => query)).parsed_response)
end