Module: Footballdata
- Defined in:
- lib/models/team.rb,
lib/footballdata.rb,
lib/configuration.rb,
lib/models/league.rb,
lib/models/fixture.rb
Defined Under Namespace
Classes: Configuration, Fixture, League, Team
Class Method Summary
collapse
Class Method Details
.configuration ⇒ Object
10
11
12
|
# File 'lib/configuration.rb', line 10
def self.configuration
@configuration ||= Configuration.new
end
|
.configuration=(config) ⇒ Object
14
15
16
|
# File 'lib/configuration.rb', line 14
def self.configuration=(config)
@configuration = config
end
|
18
19
20
|
# File 'lib/configuration.rb', line 18
def self.configure
yield configuration
end
|
.current_season ⇒ Object
38
39
40
|
# File 'lib/footballdata.rb', line 38
def self.current_season
Time.now.month >= 7 ? Time.now.year : Time.now.year - 1
end
|
.leagues(season: current_season) ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/footballdata.rb', line 16
def self.leagues(season: current_season)
open("#{BASE_URL}/soccerseasons?season=#{season}", "X-Auth-Token" => api_key) do |response|
JSON.parse(response.read).map do |league|
League.new(
id: league["id"],
name: league["caption"]
)
end
end
end
|
.team(id) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/footballdata.rb', line 27
def self.team(id)
open("#{BASE_URL}/teams/#{id}", "X-Auth-Token" => api_key) do |response|
team = JSON.parse(response.read)
id = team["_links"]["fixtures"]["href"].split("/")[-2]
Team.new(
id: id,
name: team["name"]
)
end
end
|