Class: Dota::API::Client

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

Instance Method Summary collapse

Instance Method Details

#abilities(id = nil) ⇒ Object



23
24
25
# File 'lib/dota/api/client.rb', line 23

def abilities(id = nil)
  id ? Ability.new(id) : Ability.all
end

#configurationObject



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

def configuration
  @configuration ||= Configuration.new
end

#configure {|configuration| ... } ⇒ Object

Yields:



11
12
13
# File 'lib/dota/api/client.rb', line 11

def configure
  yield configuration
end

#cosmetic_raritiesObject



89
90
91
92
93
94
# File 'lib/dota/api/client.rb', line 89

def cosmetic_rarities
  response = get("IEconDOTA2_570", "GetRarities", language: "en")["result"]
  if response && (rarities = response["rarities"] || [])
    rarities.map { |rarity| Cosmetic::Rarity.new(rarity) }
  end
end

#friends(user_id) ⇒ Object



96
97
98
99
100
101
# File 'lib/dota/api/client.rb', line 96

def friends(user_id)
  response = get("ISteamUser", "GetFriendList", steamid: user_id)["friendslist"]
  if response && (friends = response["friends"] || [])
    friends.map { |friend| Friend.new(friend) }
  end
end

#get(interface, method, params = {}) ⇒ Object



103
104
105
# File 'lib/dota/api/client.rb', line 103

def get(interface, method, params = {})
  do_request(method, params, interface)
end

#heroes(id = nil) ⇒ Object



15
16
17
# File 'lib/dota/api/client.rb', line 15

def heroes(id = nil)
  id ? Hero.find(id) : Hero.all
end

#items(id = nil) ⇒ Object



19
20
21
# File 'lib/dota/api/client.rb', line 19

def items(id = nil)
  id ? Item.new(id) : Item.all
end

#leaguesObject



65
66
67
68
69
70
# File 'lib/dota/api/client.rb', line 65

def leagues
  response = get("IDOTA2Match_570", "GetLeagueListing", language: "en")["result"]
  if response && (leagues = response["leagues"] || [])
    leagues.map { |league| League.new(league) }
  end
end

#live_matches(options = {}) ⇒ Object



72
73
74
75
76
77
# File 'lib/dota/api/client.rb', line 72

def live_matches(options = {})
  response = get("IDOTA2Match_570", "GetLiveLeagueGames", options)["result"]
  if response && (live_matches = response["games"] || [])
    live_matches.map { |game| LiveMatch.new(game) }
  end
end

#matches(options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dota/api/client.rb', line 43

def matches(options = {})
  if options.is_a?(Integer)
    id = options
    response = get("IDOTA2Match_570", "GetMatchDetails", match_id: id)["result"]
    Match.new(response) if response
  else
    options[:game_mode]             = options.delete(:mode_id) if options[:mode_id]
    options[:skill]                 = options.delete(:skill_level) if options[:skill_level]
    options[:date_min]              = options.delete(:from) if options[:from]
    options[:date_max]              = options.delete(:to) if options[:to]
    options[:account_id]            = options.delete(:player_id) if options[:player_id]
    options[:start_at_match_id]     = options.delete(:after) if options[:after]
    options[:matches_requested]     = options.delete(:limit) if options[:limit]
    options[:tournament_games_only] = options.delete(:league_only) if options[:league_only]

    response = get("IDOTA2Match_570", "GetMatchHistory", options)["result"]
    if response && (matches = response["matches"] || [])
      matches.map { |match| Match.new(match) }
    end
  end
end

#scheduled_matches(options = {}) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/dota/api/client.rb', line 79

def scheduled_matches(options = {})
  options[:date_min] = options.delete(:from) if options[:from]
  options[:date_max] = options.delete(:to) if options[:to]

  response = get("IDOTA2Match_570", "GetScheduledLeagueGames", options)["result"]
  if response && (scheduled_matches = response["games"] || [])
    scheduled_matches.map { |game| ScheduledMatch.new(game) }
  end
end

#teams(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dota/api/client.rb', line 27

def teams(options = {})
  if options.is_a?(Integer)
    id = options
    response = get("IDOTA2Match_570", "GetTeamInfoByTeamID", start_at_team_id: id, teams_requested: 1)["result"]["teams"][0]
    Team.new(response) if response && id == response["team_id"]
  else
    options[:start_at_team_id] = options.delete(:after) if options[:after]
    options[:teams_requested]  = options.delete(:limit) if options[:limit]

    response = get("IDOTA2Match_570", "GetTeamInfoByTeamID", options)["result"]
    if response && (teams = response["teams"] || [])
      teams.map { |team| Team.new(team) }
    end
  end
end