class Dota::API::Client
Public Instance Methods
abilities(id = nil)
click to toggle source
# File lib/dota/api/client.rb, line 23 def abilities(id = nil) id ? Ability.new(id) : Ability.all end
configuration()
click to toggle source
# File lib/dota/api/client.rb, line 7 def configuration @configuration ||= Configuration.new end
configure() { |configuration| ... }
click to toggle source
# File lib/dota/api/client.rb, line 11 def configure yield configuration end
cosmetic_rarities()
click to toggle source
# 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)
click to toggle source
# 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 = {})
click to toggle source
# File lib/dota/api/client.rb, line 103 def get(interface, method, params = {}) do_request(method, params, interface) end
heroes(id = nil)
click to toggle source
# File lib/dota/api/client.rb, line 15 def heroes(id = nil) id ? Hero.find(id) : Hero.all end
items(id = nil)
click to toggle source
# File lib/dota/api/client.rb, line 19 def items(id = nil) id ? Item.new(id) : Item.all end
leagues()
click to toggle source
# 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 = {})
click to toggle source
# 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 = {})
click to toggle source
# 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 = {})
click to toggle source
# 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 = {})
click to toggle source
# 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
Private Instance Methods
do_request(method, params, interface = "IDOTA2Match_570")
click to toggle source
# File lib/dota/api/client.rb, line 109 def do_request(method, params, interface = "IDOTA2Match_570") method_version = params.delete(:api_version) || configuration.api_version url = "https://api.steampowered.com/#{interface}/#{method}/#{method_version}/" @faraday = Faraday.new(url) do |faraday| faraday.response :json faraday.adapter Faraday.default_adapter end response = @faraday.get do |request| request.url(url, params.merge(key: configuration.api_key)) end response.body end