Class: Sc2RanksApi

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/sc2ranksapi.rb,
lib/sc2ranksapi/team.rb,
lib/sc2ranksapi/version.rb,
lib/sc2ranksapi/character.rb

Defined Under Namespace

Classes: Character, Team

Constant Summary collapse

BNET_REGEX =
%r{http://([a-zA-Z]+)\.battle\.net/sc2/[a-zA-Z0-9]+/profile/([0-9]+)/[01]/([a-zA-Z0-9]+)/}
VERSION =
"0.0.1"

Instance Method Summary collapse

Constructor Details

#initialize(appKey) ⇒ Sc2RanksApi

Returns a new instance of Sc2RanksApi.



11
12
13
# File 'lib/sc2ranksapi.rb', line 11

def initialize(appKey)
  self.class.default_params :appKey => appKey
end

Instance Method Details

#character(url) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/sc2ranksapi.rb', line 15

def character(url)
  region, char = parse_bnet_url url

  json_response = self.class.get("/api/base/teams/#{region}/#{char}.json")

  Character.new json_response.parsed_response
end

#parse_bnet_url(url) ⇒ Object



23
24
25
26
# File 'lib/sc2ranksapi.rb', line 23

def parse_bnet_url(url)
  Sc2RanksApi::BNET_REGEX =~ url
  return $1, "#{$3}!#{$2}"
end