sports_data_api 0.11.1 → 0.11.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 092e540e02537ab5918831ec241e04cadb65f685
4
- data.tar.gz: 2665a7853dd7f18b14b1d998cb9f5f22da39e712
3
+ metadata.gz: bda0af1487f0371b2b876bc00e102cacd57c13f6
4
+ data.tar.gz: f86806607d2d6b960bc6a72e6dfb1e93d187f522
5
5
  SHA512:
6
- metadata.gz: 71acae7815dd33b9457aa4c1a32a54ce0e344465efe54c0423cf47302a0c6c505749c016230c461543c6b2ab07213aa9f1bf22a48792433b7339c646dcc19386
7
- data.tar.gz: a614366fb3d170b18056be309f59757fdfedbb4276cb3225359f85ea12f451a395424c9fc832840ccb1d7a3e7002998471f261b2373b3795dfd30f2caf7f7622
6
+ metadata.gz: 74426b508a595bce7e35ccdf4e48bac91d14453d71482b61bce58480812ecad2cf9089dab42d06a492df26707f7c77bb7979a1e3debe290aec53184b008f7ca5
7
+ data.tar.gz: cb7ec0a93446561c3de6487a1d62a3bb6ffb9c6abbf02700ad92f5a5a245d2925339477a172a33da575f50c45731a2fa781e19a04012cb1dba8f5df352c423d9
@@ -20,12 +20,18 @@ module SportsDataApi
20
20
 
21
21
  class << self
22
22
  ##
23
- # Fetches all MLB leagues
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)
@@ -3,7 +3,10 @@ module SportsDataApi
3
3
  class Division < JsonData
4
4
  def teams
5
5
  @teams ||= division[:teams].map do |data|
6
- Team.new(data)
6
+ Team.new(data).tap do |t|
7
+ t.team[:division] = division[:name]
8
+ t.team[:division_alias] = division[:alias]
9
+ end
7
10
  end
8
11
  end
9
12
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module SportsDataApi
2
- VERSION = '0.11.1'
2
+ VERSION = '0.11.2'
3
3
  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
- expect(subject[:teams].first)
20
- .to be_instance_of SportsDataApi::Mlb::Team
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'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sports_data_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Lovelett