Class: Dota::API::Client
- Inherits:
-
Object
- Object
- Dota::API::Client
- Defined in:
- lib/dota/api/client.rb
Instance Method Summary collapse
- #abilities(id = nil) ⇒ Object
- #configuration ⇒ Object
- #configure {|configuration| ... } ⇒ Object
- #cosmetic_rarities ⇒ Object
- #friends(user_id) ⇒ Object
- #get(interface, method, params = {}) ⇒ Object
- #heroes(id = nil) ⇒ Object
- #items(id = nil) ⇒ Object
- #leagues ⇒ Object
- #live_matches(options = {}) ⇒ Object
- #matches(options = {}) ⇒ Object
- #scheduled_matches(options = {}) ⇒ Object
- #teams(options = {}) ⇒ Object
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 |
#configuration ⇒ Object
7 8 9 |
# File 'lib/dota/api/client.rb', line 7 def configuration @configuration ||= Configuration.new end |
#configure {|configuration| ... } ⇒ Object
11 12 13 |
# File 'lib/dota/api/client.rb', line 11 def configure yield configuration end |
#cosmetic_rarities ⇒ Object
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 |
#leagues ⇒ Object
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( = {}) response = get("IDOTA2Match_570", "GetLiveLeagueGames", )["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( = {}) if .is_a?(Integer) id = response = get("IDOTA2Match_570", "GetMatchDetails", match_id: id)["result"] Match.new(response) if response else [:game_mode] = .delete(:mode_id) if [:mode_id] [:skill] = .delete(:skill_level) if [:skill_level] [:date_min] = .delete(:from) if [:from] [:date_max] = .delete(:to) if [:to] [:account_id] = .delete(:player_id) if [:player_id] [:start_at_match_id] = .delete(:after) if [:after] [:matches_requested] = .delete(:limit) if [:limit] [:tournament_games_only] = .delete(:league_only) if [:league_only] response = get("IDOTA2Match_570", "GetMatchHistory", )["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( = {}) [:date_min] = .delete(:from) if [:from] [:date_max] = .delete(:to) if [:to] response = get("IDOTA2Match_570", "GetScheduledLeagueGames", )["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( = {}) if .is_a?(Integer) id = 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 [:start_at_team_id] = .delete(:after) if [:after] [:teams_requested] = .delete(:limit) if [:limit] response = get("IDOTA2Match_570", "GetTeamInfoByTeamID", )["result"] if response && (teams = response["teams"] || []) teams.map { |team| Team.new(team) } end end end |