sports_data_api 0.15.1 → 0.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07f6aa2548068b6f74a06b0bda9eb6fffd2e422b0d3a5295c7eba744207a4788
4
- data.tar.gz: b9cc63e395efdf1a7ad01090341731640bffdeac47c832a4ec3a45dbbc4e9ce2
3
+ metadata.gz: 90a618d57290eff4689456381867315bce98c10c38800ab90b501834ba2e96a0
4
+ data.tar.gz: d30d9f0126b1986744d5593097c262c2bbc3a11a3cfc9b3f250699872329345b
5
5
  SHA512:
6
- metadata.gz: f482f859858ad07ca7787ffcd7fb3804ea42a6f541810ae4e747c0005516a6f991fd667d886a1a1b7da9f8babf89b223da8d36b6482ebf1f7ae3cd0cd3e58409
7
- data.tar.gz: 3a71cb9e7fd68ad00eab45db25df95d9f1c04a78d0dfbaefcccd2255354d5256b22c293eb64a0dd36653f42a7b843eafa33d1c70bbe660c90a74e5de56379c99
6
+ metadata.gz: 963da55d3d2a1fb7133f1cd10e85efc087dadf5dfee5fc2362800b58c3be7d7186f28948fc2277ffff741fa17f1bf8f78470ff380117f229c4150ef92cbd27a8
7
+ data.tar.gz: 614bf62757c001d026fae6c892cf2470f71b56f7c763d27ff22f2d426ecfcd6a950c9d507bfd3fd6e4773f2044ebd1c0beeb61d62b8e03c689d63c0fca335517
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v0.15.2
4
+ * [#94](https://github.com/RLovelett/sports_data_api/pull/94) [FIX] Safe map of json responses
5
+
3
6
  ## v0.15.1
4
7
  * [#92](https://github.com/RLovelett/sports_data_api/pull/92) [FIX] NFL extra points stats
5
8
  * [#93](https://github.com/RLovelett/sports_data_api/pull/93) [Feature] Stats have #fetch like hash
@@ -12,7 +12,7 @@ module SportsDataApi
12
12
  end
13
13
 
14
14
  def pairings
15
- @pairings ||= data['pairings'].map do |json|
15
+ @pairings ||= data.fetch('pairings', []).map do |json|
16
16
  Pairing.new(json)
17
17
  end
18
18
  end
@@ -10,7 +10,7 @@ module SportsDataApi
10
10
  end
11
11
 
12
12
  def players
13
- @players ||= data['players'].map do |json|
13
+ @players ||= data.fetch('players', []).map do |json|
14
14
  Player.new(json)
15
15
  end
16
16
  end
@@ -8,7 +8,7 @@ module SportsDataApi
8
8
  def initialize(season_hash)
9
9
  @year = season_hash['season']['year']
10
10
  @tour = season_hash['tour']['alias'].downcase.to_sym
11
- @tournaments = season_hash['tournaments'].map do |tournament_hash|
11
+ @tournaments = season_hash.fetch('tournaments', []).map do |tournament_hash|
12
12
  Tournament.new(tour, year, tournament_hash)
13
13
  end
14
14
  end
@@ -38,7 +38,7 @@ module SportsDataApi
38
38
  def players(tour, year)
39
39
  response = response_json UrlPaths::PLAYERS % { tour: tour, year: year }
40
40
 
41
- response['players'].map do |json|
41
+ response.fetch('players', []).map do |json|
42
42
  Player.new(json)
43
43
  end
44
44
  end
@@ -57,7 +57,7 @@ module SportsDataApi
57
57
  { tour: tour, year: year, tournament_id: tournament_id, round: round }
58
58
 
59
59
 
60
- response['round']['courses'].map do |json|
60
+ (response.dig('round', 'courses') || []).map do |json|
61
61
  Course.new(json)
62
62
  end
63
63
  end
@@ -73,7 +73,7 @@ module SportsDataApi
73
73
  status: response['round']['status'],
74
74
  year: year,
75
75
  tour: tour,
76
- players: response['round']['players'].map do |json|
76
+ players: (response.dig('round', 'players') || []).map do |json|
77
77
  Player.new(json)
78
78
  end
79
79
  }
@@ -84,7 +84,7 @@ module SportsDataApi
84
84
  response = response_json UrlPaths::LEADERBOARDS %
85
85
  { tour: tour, year: year, tournament_id: tournament_id }
86
86
 
87
- response['leaderboard'].map do |json|
87
+ response.fetch('leaderboard', []).map do |json|
88
88
  Player.new(json)
89
89
  end
90
90
  end
@@ -2,7 +2,7 @@ module SportsDataApi
2
2
  module Mlb
3
3
  class Division < JsonData
4
4
  def teams
5
- @teams ||= division[:teams].map do |data|
5
+ @teams ||= division.fetch(:teams, []).map do |data|
6
6
  Team.new(data).tap do |t|
7
7
  t.team[:division] = division[:name]
8
8
  t.team[:division_alias] = division[:alias]
@@ -2,7 +2,7 @@ module SportsDataApi
2
2
  module Mlb
3
3
  class League < JsonData
4
4
  def divisions
5
- @divisions ||= league[:divisions].map do |data|
5
+ @divisions ||= league.fetch(:divisions, []).map do |data|
6
6
  Division.new(data)
7
7
  end
8
8
  end
@@ -11,7 +11,7 @@ module SportsDataApi
11
11
  end
12
12
 
13
13
  def games
14
- @games ||= json['games'].map do |game_json|
14
+ @games ||= json.fetch('games', []).map do |game_json|
15
15
  Game.new(json: game_json)
16
16
  end
17
17
  end
@@ -11,7 +11,7 @@ module SportsDataApi
11
11
  end
12
12
 
13
13
  def games
14
- @games ||= json['games'].map do |game_json|
14
+ @games ||= json.fetch('games', []).map do |game_json|
15
15
  Game.new(year: year, season: type, json: game_json)
16
16
  end
17
17
  end
@@ -8,7 +8,7 @@ module SportsDataApi
8
8
  end
9
9
 
10
10
  def teams
11
- @teams ||= json['conferences'].flat_map do |conference|
11
+ @teams ||= json.fetch('conferences', []).flat_map do |conference|
12
12
  conference['divisions'].flat_map do |division|
13
13
  division['teams'].map do |json|
14
14
  Team.new(json, conference['alias'], division['alias'])
@@ -11,7 +11,7 @@ module SportsDataApi
11
11
  end
12
12
 
13
13
  def weeks
14
- @weeks ||= json['weeks'].map do |week|
14
+ @weeks ||= json.fetch('weeks', []).map do |week|
15
15
  Week.new(week, year, type)
16
16
  end
17
17
  end
@@ -13,7 +13,7 @@ module SportsDataApi
13
13
  end
14
14
 
15
15
  def teams
16
- @teams ||= json['conferences'].flat_map do |conference_json|
16
+ @teams ||= json.fetch('conferences', []).flat_map do |conference_json|
17
17
  conference = conference_json['name']
18
18
  conference_json['divisions'].flat_map do |division_json|
19
19
  division = division_json['name']
@@ -11,7 +11,7 @@ module SportsDataApi
11
11
  end
12
12
 
13
13
  def games
14
- @games ||= json['games'].map do |game|
14
+ @games ||= json.fetch('games', []).map do |game|
15
15
  Game.new(game, year: year, season: season, week: number)
16
16
  end
17
17
  end
@@ -11,7 +11,7 @@ module SportsDataApi
11
11
  end
12
12
 
13
13
  def games
14
- @games ||= json['games'].map do |game_json|
14
+ @games ||= json.fetch('games', []).map do |game_json|
15
15
  Game.new(json: game_json)
16
16
  end
17
17
  end
@@ -11,7 +11,7 @@ module SportsDataApi
11
11
  end
12
12
 
13
13
  def games
14
- @games ||= json['games'].map do |game_json|
14
+ @games ||= json.fetch('games', []).map do |game_json|
15
15
  Game.new(year: year, season: type, json: game_json)
16
16
  end
17
17
  end
@@ -8,7 +8,7 @@ module SportsDataApi
8
8
  end
9
9
 
10
10
  def teams
11
- @teams ||= json['conferences'].flat_map do |conference|
11
+ @teams ||= json.fetch('conferences', []).flat_map do |conference|
12
12
  conference['divisions'].flat_map do |division|
13
13
  division['teams'].map do |team_json|
14
14
  Team.new(team_json, conference['alias'], division['alias'])
@@ -1,3 +1,3 @@
1
1
  module SportsDataApi
2
- VERSION = '0.15.1'
2
+ VERSION = '0.15.2'
3
3
  end
@@ -1,5 +1,76 @@
1
1
  ---
2
2
  http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.sportradar.us/nhl/trial/v5/en/games/2018/PST/schedule.json?api_key=<API_KEY>
6
+ body:
7
+ encoding: US-ASCII
8
+ base64_string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - rest-client/2.0.2 (darwin16.7.0 x86_64) ruby/2.5.1p57
16
+ Host:
17
+ - api.sportradar.us
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Accept-Ranges:
24
+ - bytes
25
+ Age:
26
+ - '0'
27
+ Cache-Control:
28
+ - public, must-revalidate, max-age=11
29
+ Content-Language:
30
+ - en
31
+ Content-Type:
32
+ - application/json;charset=utf-8
33
+ Date:
34
+ - Fri, 21 Sep 2018 16:30:19 GMT
35
+ Expires:
36
+ - Fri, 21 Sep 2018 16:30:30 GMT
37
+ Server:
38
+ - nginx
39
+ Via:
40
+ - 1.1 varnish-v4
41
+ - 1.1 varnish-v4
42
+ X-Be-Cache:
43
+ - MISS
44
+ X-Fe-Cache:
45
+ - MISS
46
+ X-Mashery-Responder:
47
+ - prod-j-worker-us-east-1b-50.mashery.com
48
+ X-Plan-Qps-Allotted:
49
+ - '25'
50
+ X-Plan-Qps-Current:
51
+ - '1'
52
+ X-Plan-Quota-Allotted:
53
+ - '15000'
54
+ X-Plan-Quota-Current:
55
+ - '4'
56
+ X-Varnish:
57
+ - '11247620'
58
+ - '25454331'
59
+ X-Via:
60
+ - Translation-Proxy
61
+ Content-Length:
62
+ - '163'
63
+ Connection:
64
+ - keep-alive
65
+ body:
66
+ encoding: UTF-8
67
+ base64_string: |
68
+ eyJsZWFndWUiOnsiaWQiOiJmZDU2MDEwNy1hODViLTQzODgtYWIwZC02NTVh
69
+ ZDAyMmFmZjciLCJuYW1lIjoiTkhMIiwiYWxpYXMiOiJOSEwifSwic2Vhc29u
70
+ Ijp7ImlkIjoiNDU1MmM0OWUtMzBlNi00YmNiLThhM2MtYTllM2I3OTUwOWQy
71
+ IiwieWVhciI6MjAxOCwidHlwZSI6IlBTVCJ9fQ==
72
+ http_version:
73
+ recorded_at: Fri, 21 Sep 2018 16:30:19 GMT
3
74
  - request:
4
75
  method: get
5
76
  uri: https://api.sportradar.us/nhl/trial/v5/en/games/2013/REG/schedule.json?api_key=<API_KEY>
@@ -12,7 +83,7 @@ http_interactions:
12
83
  Accept-Encoding:
13
84
  - gzip, deflate
14
85
  User-Agent:
15
- - rest-client/2.0.2 (darwin16.7.0 x86_64) ruby/2.3.3p222
86
+ - rest-client/2.0.2 (darwin16.7.0 x86_64) ruby/2.5.1p57
16
87
  Host:
17
88
  - api.sportradar.us
18
89
  response:
@@ -31,9 +102,9 @@ http_interactions:
31
102
  Content-Type:
32
103
  - application/json;charset=utf-8
33
104
  Date:
34
- - Thu, 31 May 2018 20:58:18 GMT
105
+ - Fri, 21 Sep 2018 16:30:24 GMT
35
106
  Expires:
36
- - Thu, 31 May 2018 20:58:29 GMT
107
+ - Fri, 21 Sep 2018 16:30:35 GMT
37
108
  Server:
38
109
  - nginx
39
110
  Via:
@@ -44,7 +115,7 @@ http_interactions:
44
115
  X-Fe-Cache:
45
116
  - MISS
46
117
  X-Mashery-Responder:
47
- - prod-j-worker-us-east-1e-65.mashery.com
118
+ - prod-j-worker-us-east-1d-58.mashery.com
48
119
  X-Plan-Qps-Allotted:
49
120
  - '25'
50
121
  X-Plan-Qps-Current:
@@ -52,10 +123,10 @@ http_interactions:
52
123
  X-Plan-Quota-Allotted:
53
124
  - '15000'
54
125
  X-Plan-Quota-Current:
55
- - '29'
126
+ - '5'
56
127
  X-Varnish:
57
- - '1019646'
58
- - '1195953'
128
+ - '24303725'
129
+ - '9523988'
59
130
  X-Via:
60
131
  - Translation-Proxy
61
132
  Content-Length:
@@ -15712,5 +15783,5 @@ http_interactions:
15712
15783
  MThhOTA1NzY3ZTQ0IiwibmFtZSI6IkRhbGxhcyBTdGFycyIsImFsaWFzIjoi
15713
15784
  REFMIn19XX0=
15714
15785
  http_version:
15715
- recorded_at: Thu, 31 May 2018 20:58:19 GMT
15786
+ recorded_at: Fri, 21 Sep 2018 16:30:25 GMT
15716
15787
  recorded_with: VCR 3.0.3
@@ -1,11 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SportsDataApi::Nhl::Season, vcr: {
4
- cassette_name: 'sports_data_api_nhl_season',
5
- record: :new_episodes,
6
- match_requests_on: [:host, :path]
4
+ cassette_name: 'sports_data_api_nhl_season',
5
+ record: :new_episodes,
6
+ match_requests_on: [:host, :path]
7
7
  } do
8
8
  subject { SportsDataApi::Nhl::Season }
9
+
9
10
  describe '.season?' do
10
11
  context :PRE do
11
12
  it { SportsDataApi::Nhl::Season.valid?(:PRE).should eq(true) }
@@ -26,16 +27,30 @@ describe SportsDataApi::Nhl::Season, vcr: {
26
27
  it { subject.valid?(:pst).should eq(false) }
27
28
  end
28
29
  end
30
+
29
31
  context 'results from schedule fetch' do
30
- let(:season) do
31
- SportsDataApi.set_access_level(:nhl, 'trial')
32
- SportsDataApi.set_key(:nhl, api_key(:nhl))
33
- SportsDataApi::Nhl.schedule(2013, :reg)
34
- end
35
- subject { season }
36
- it { should be_an_instance_of(SportsDataApi::Nhl::Season) }
37
- its(:year) { should eq 2013 }
38
- its(:type) { should eq :REG }
39
- its(:games) { should have(1233).games }
32
+ let(:season) do
33
+ SportsDataApi.set_access_level(:nhl, 'trial')
34
+ SportsDataApi.set_key(:nhl, api_key(:nhl))
35
+ SportsDataApi::Nhl.schedule(2013, :reg)
36
+ end
37
+ subject { season }
38
+ it { should be_an_instance_of(SportsDataApi::Nhl::Season) }
39
+ its(:year) { should eq 2013 }
40
+ its(:type) { should eq :REG }
41
+ its(:games) { should have(1233).games }
42
+ end
43
+
44
+ context 'when season has no games' do
45
+ let(:season) do
46
+ SportsDataApi.set_access_level(:nhl, 'trial')
47
+ SportsDataApi.set_key(:nhl, api_key(:nhl))
48
+ SportsDataApi::Nhl.schedule(2018, :PST)
49
+ end
50
+ subject { season }
51
+ it { should be_an_instance_of(SportsDataApi::Nhl::Season) }
52
+ its(:year) { should eq 2018 }
53
+ its(:type) { should eq :PST }
54
+ its(:games) { should have(0).games }
40
55
  end
41
56
  end
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.15.1
4
+ version: 0.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Lovelett
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-29 00:00:00.000000000 Z
12
+ date: 2018-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri