sports_data_api 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sports_data_api/mlb.rb +7 -1
- data/lib/sports_data_api/mlb/division.rb +4 -1
- data/lib/sports_data_api/mlb/league.rb +11 -0
- data/lib/sports_data_api/version.rb +1 -1
- data/spec/lib/sports_data_api/mlb/division_spec.rb +4 -2
- data/spec/lib/sports_data_api/mlb/league_spec.rb +7 -0
- data/spec/lib/sports_data_api/mlb_spec.rb +20 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bda0af1487f0371b2b876bc00e102cacd57c13f6
|
4
|
+
data.tar.gz: f86806607d2d6b960bc6a72e6dfb1e93d187f522
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74426b508a595bce7e35ccdf4e48bac91d14453d71482b61bce58480812ecad2cf9089dab42d06a492df26707f7c77bb7979a1e3debe290aec53184b008f7ca5
|
7
|
+
data.tar.gz: cb7ec0a93446561c3de6487a1d62a3bb6ffb9c6abbf02700ad92f5a5a245d2925339477a172a33da575f50c45731a2fa781e19a04012cb1dba8f5df352c423d9
|
data/lib/sports_data_api/mlb.rb
CHANGED
@@ -20,12 +20,18 @@ module SportsDataApi
|
|
20
20
|
|
21
21
|
class << self
|
22
22
|
##
|
23
|
-
# Fetches
|
23
|
+
# Fetches leagues hierachy
|
24
24
|
def leagues
|
25
25
|
response = response_json('/league/hierarchy.json')
|
26
26
|
map_model response, 'leagues', League
|
27
27
|
end
|
28
28
|
|
29
|
+
##
|
30
|
+
# Fetches all MLB teams
|
31
|
+
def teams
|
32
|
+
leagues.flat_map(&:teams)
|
33
|
+
end
|
34
|
+
|
29
35
|
##
|
30
36
|
# Fetches MLB season schedule for a given year and season
|
31
37
|
def season_schedule(year, season)
|
@@ -6,6 +6,17 @@ module SportsDataApi
|
|
6
6
|
Division.new(data)
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
10
|
+
def teams
|
11
|
+
@teams ||= divisions.flat_map do |division|
|
12
|
+
division.teams.flat_map do |team|
|
13
|
+
team.tap do |t|
|
14
|
+
t.team[:conference] = league[:alias]
|
15
|
+
t.team[:conference_name] = league[:name]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
9
20
|
end
|
10
21
|
end
|
11
22
|
end
|
@@ -16,8 +16,10 @@ describe SportsDataApi::Mlb::Division, vcr: {
|
|
16
16
|
expect(subject[:id]).to eq '1d74e8e9-7faf-4cdb-b613-3944fa5aa739'
|
17
17
|
expect(subject[:name]).to eq 'East'
|
18
18
|
expect(subject[:teams].count).to eq 5
|
19
|
-
|
20
|
-
|
19
|
+
team = subject[:teams].first
|
20
|
+
expect(team).to be_instance_of SportsDataApi::Mlb::Team
|
21
|
+
expect(team[:division_alias]).to eq 'E'
|
22
|
+
expect(team[:division]).to eq 'East'
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
@@ -18,5 +18,12 @@ describe SportsDataApi::Mlb::League, vcr: {
|
|
18
18
|
expect(subject[:divisions].first)
|
19
19
|
.to be_instance_of SportsDataApi::Mlb::Division
|
20
20
|
end
|
21
|
+
|
22
|
+
it 'populates teams with conference' do
|
23
|
+
expect(subject[:teams].count).to eq 15
|
24
|
+
team = subject[:teams].first
|
25
|
+
expect(team[:conference]).to eq 'AL'
|
26
|
+
expect(team[:conference_name]).to eq 'American League'
|
27
|
+
end
|
21
28
|
end
|
22
29
|
|
@@ -13,6 +13,9 @@ describe SportsDataApi::Mlb do
|
|
13
13
|
describe '.leagues' do
|
14
14
|
it { expect { subject.leagues }.to raise_error(SportsDataApi::Exception) }
|
15
15
|
end
|
16
|
+
describe '.teams' do
|
17
|
+
it { expect { subject.teams }.to raise_error(SportsDataApi::Exception) }
|
18
|
+
end
|
16
19
|
describe '.season_schedule' do
|
17
20
|
it { expect { subject.season_schedule(2017, :REG) }.to raise_error(SportsDataApi::Exception) }
|
18
21
|
end
|
@@ -35,6 +38,9 @@ describe SportsDataApi::Mlb do
|
|
35
38
|
describe '.leagues' do
|
36
39
|
it { expect { subject.leagues }.to raise_error(SportsDataApi::Exception) }
|
37
40
|
end
|
41
|
+
describe '.teams' do
|
42
|
+
it { expect { subject.teams }.to raise_error(SportsDataApi::Exception) }
|
43
|
+
end
|
38
44
|
describe '.season_schedule' do
|
39
45
|
it { expect { subject.season_schedule(2017, :REG) }.to raise_error(SportsDataApi::Exception) }
|
40
46
|
end
|
@@ -73,6 +79,20 @@ describe SportsDataApi::Mlb do
|
|
73
79
|
expect(RestClient).to have_received(:get).with(season_url, params)
|
74
80
|
end
|
75
81
|
end
|
82
|
+
describe '.teams' do
|
83
|
+
it 'creates a valid url' do
|
84
|
+
season_url = 'https://api.sportradar.us/mlb-t6/league/hierarchy.json'
|
85
|
+
schedule_json = RestClient.get("#{season_url}?api_key=#{api_key(:mlb)}")
|
86
|
+
allow(RestClient).to receive(:get) { schedule_json }
|
87
|
+
|
88
|
+
teams = subject.teams
|
89
|
+
|
90
|
+
expect(teams.count).to eq 30
|
91
|
+
expect(teams.first).to be_instance_of SportsDataApi::Mlb::Team
|
92
|
+
params = { params: { api_key: SportsDataApi.key(:mlb) } }
|
93
|
+
expect(RestClient).to have_received(:get).with(season_url, params)
|
94
|
+
end
|
95
|
+
end
|
76
96
|
describe '.season_schedule' do
|
77
97
|
it 'creates a valid url' do
|
78
98
|
season_url = 'https://api.sportradar.us/mlb-t6/games/2017/REG/schedule.json'
|