Class: Starcraft2::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/starcraft2/client.rb

Constant Summary collapse

ACHIEVEMENTS_PATH =
'/api/sc2/data/achievements'
REWARDS_PATH =
'/api/sc2/data/rewards'
LADDER_PATH =
'/api/sc2/ladder/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
# File 'lib/starcraft2/client.rb', line 9

def initialize(options = {})
  options.each do |k, v|
    self.send(:"#{k}=", v)
  end

  self.host = 'us.battle.net' if self.host.nil?
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/starcraft2/client.rb', line 7

def host
  @host
end

#localeObject

Returns the value of attribute locale.



7
8
9
# File 'lib/starcraft2/client.rb', line 7

def locale
  @locale
end

Instance Method Details

#achievementsObject



25
26
27
# File 'lib/starcraft2/client.rb', line 25

def achievements
  Achievement.build(achievements_data)
end

#flush_cacheObject



45
46
47
# File 'lib/starcraft2/client.rb', line 45

def flush_cache
  @memoizations = {}
end

#grandmaster_ladderObject



37
38
39
# File 'lib/starcraft2/client.rb', line 37

def grandmaster_ladder
  ladder('grandmaster')
end

#ladder(id) ⇒ Object



33
34
35
# File 'lib/starcraft2/client.rb', line 33

def ladder(id)
  Ladder.build(ladder_data(id))
end

#last_grandmaster_ladderObject



41
42
43
# File 'lib/starcraft2/client.rb', line 41

def last_grandmaster_ladder
  ladder('grandmaster/last')
end

#profile(options = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/starcraft2/client.rb', line 17

def profile(options = {})
  if (args = [:character_name, :id, :realm] - options.keys).empty?
    Profile.build(self, profile_data(options))
  else
    raise MissingArgumentsError, "Missing Keys: #{args.map { |i| ":#{i}" }.join(', ')}"
  end
end

#rewardsObject



29
30
31
# File 'lib/starcraft2/client.rb', line 29

def rewards
  Reward.build(rewards_data)
end