Class: ApiSports::TeamsResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/api_sports/resources/teams.rb

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#get_request, #get_single_resource, #handle_response, #initialize

Constructor Details

This class inherits a constructor from ApiSports::Resource

Instance Method Details

#list(**params) ⇒ Object



5
6
7
8
# File 'lib/api_sports/resources/teams.rb', line 5

def list(**params)
  response = get_request("teams", params: params)
  Collection.from_response(response, type: Team)
end

#retrieve(team_id:) ⇒ Object



10
11
12
13
14
15
# File 'lib/api_sports/resources/teams.rb', line 10

def retrieve(team_id:)
  response = get_single_resource("teams", params: { id: team_id }) do |r|
    r.body["response"].first.dig("team")
  end
  Team.new(response)
end

#seasons(team_id:) ⇒ Object



22
23
24
25
# File 'lib/api_sports/resources/teams.rb', line 22

def seasons(team_id:)
  response = get_request("teams/seasons", params: { team: team_id })
  Collection.from_response(response, type: Season)
end

#statistics(league_id:, season_id:, team_id:) ⇒ Object



17
18
19
20
# File 'lib/api_sports/resources/teams.rb', line 17

def statistics(league_id:, season_id:, team_id:)
  response = get_request("teams/statistics", params: { team: team_id, league: league_id, season: season_id })
  Statistics.new(response.body["response"])
end