espn 0.1.3 → 0.2.0

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.
Files changed (54) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +91 -6
  3. data/lib/espn.rb +5 -0
  4. data/lib/espn/arguments.rb +41 -0
  5. data/lib/espn/client.rb +29 -5
  6. data/lib/espn/client/athletes.rb +39 -21
  7. data/lib/espn/client/audio.rb +20 -19
  8. data/lib/espn/client/headlines.rb +58 -27
  9. data/lib/espn/client/medals.rb +8 -0
  10. data/lib/espn/client/notes.rb +31 -21
  11. data/lib/espn/client/now.rb +11 -8
  12. data/lib/espn/client/scores.rb +33 -21
  13. data/lib/espn/client/sports.rb +20 -14
  14. data/lib/espn/client/standings.rb +20 -16
  15. data/lib/espn/client/teams.rb +39 -21
  16. data/lib/espn/client/video.rb +14 -17
  17. data/lib/espn/configuration.rb +29 -12
  18. data/lib/espn/error.rb +15 -3
  19. data/lib/espn/helpers.rb +39 -0
  20. data/lib/espn/mapper.rb +142 -0
  21. data/lib/espn/request.rb +86 -7
  22. data/lib/espn/version.rb +1 -1
  23. data/lib/faraday/response/raise_espn_error.rb +33 -11
  24. data/spec/espn/arguments_spec.rb +76 -0
  25. data/spec/espn/client/athletes_spec.rb +38 -47
  26. data/spec/espn/client/audio_spec.rb +30 -29
  27. data/spec/espn/client/headlines_spec.rb +80 -35
  28. data/spec/espn/client/medals_spec.rb +1 -1
  29. data/spec/espn/client/notes_spec.rb +39 -45
  30. data/spec/espn/client/now_spec.rb +1 -2
  31. data/spec/espn/client/scores_spec.rb +56 -39
  32. data/spec/espn/client/sports_spec.rb +56 -18
  33. data/spec/espn/client/standings_spec.rb +42 -19
  34. data/spec/espn/client/teams_spec.rb +61 -43
  35. data/spec/espn/client/video_spec.rb +9 -13
  36. data/spec/espn/helpers_spec.rb +31 -0
  37. data/spec/espn/mapper_spec.rb +136 -0
  38. data/spec/espn/request_spec.rb +65 -0
  39. data/spec/espn_spec.rb +11 -2
  40. data/spec/faraday/response/raise_espn_error_spec.rb +80 -0
  41. data/spec/responses/athletes.json +51 -0
  42. data/spec/responses/audio.json +101 -0
  43. data/spec/responses/headlines.json +174 -0
  44. data/spec/responses/medals.json +273 -0
  45. data/spec/responses/notes.json +100 -0
  46. data/spec/responses/now.json +44 -0
  47. data/spec/responses/scores.json +209 -0
  48. data/spec/responses/sports.json +164 -0
  49. data/spec/responses/standings.json +2689 -0
  50. data/spec/responses/teams.json +51 -0
  51. data/spec/responses/videos.json +28 -0
  52. data/spec/spec_helper.rb +11 -2
  53. metadata +37 -3
  54. data/lib/espn/connection.rb +0 -32
@@ -3,71 +3,62 @@ require 'spec_helper'
3
3
  describe ESPN::Client::Athletes do
4
4
  before do
5
5
  @client = ESPN::Client.new
6
+ stub_get 'athletes.json'
6
7
  end
7
8
 
8
- describe '#athletes' do
9
+ describe '#athlete' do
10
+ it 'should return an athlete' do
11
+ @client.athlete(1, :mlb).fullName.should eq('Chase Utley')
12
+ end
9
13
 
10
- it 'gets all athletes' do
11
- stub_get('sports/athletes')
12
- @client.athletes
13
- assert_requested :get, espn_url('sports/athletes')
14
+ it 'should get an athlete for the given league' do
15
+ @client.athlete(1, :mlb)
16
+ assert_requested :get, espn_url('sports/baseball/mlb/athletes/1')
14
17
  end
15
18
 
16
- context 'with a sport param' do
17
- it 'should include the sport in the request' do
18
- stub_get('sports/baseball/athletes')
19
- @client.athletes(sport: 'baseball')
20
- assert_requested :get, espn_url('sports/baseball/athletes')
21
- end
19
+ it 'should accept a league in the opts hash' do
20
+ @client.athlete(1, league: 'mlb')
21
+ assert_requested :get, espn_url('sports/baseball/mlb/athletes/1')
22
+ end
22
23
 
23
- context 'with a athlete_id param' do
24
- it 'should include the sport and athlete_id params in the request' do
25
- stub_get('sports/baseball/athletes/5')
26
- @client.athletes(sport: 'baseball', athlete_id: 5)
27
- assert_requested :get, espn_url('sports/baseball/athletes/5')
28
- end
24
+ context 'when league is not passed' do
25
+ it 'should raise an argument error' do
26
+ expect { @client.athlete(1) }.to raise_error(ArgumentError)
29
27
  end
30
28
  end
31
29
 
32
- context 'with a sport and a league param' do
33
- it 'should include the sport and league params in the request' do
34
- stub_get('sports/baseball/mlb/athletes')
35
- @client.athletes(sport: 'baseball', league: 'mlb')
36
- assert_requested :get, espn_url('sports/baseball/mlb/athletes')
30
+ context 'when invalid league is passed' do
31
+ it 'should raise an argument error' do
32
+ expect { @client.athlete(1, :foobar) }.to raise_error(ArgumentError)
37
33
  end
34
+ end
35
+ end
38
36
 
39
- context 'with a athlete_id param' do
40
- it 'should include the sport, league and athlete_id params' do
41
- stub_get('sports/baseball/mlb/athletes/1')
42
- @client.athletes(sport: 'baseball', league: 'mlb', athlete_id: 1)
43
- assert_requested :get, espn_url('sports/baseball/mlb/athletes/1')
44
- end
45
- end
37
+ describe '#athletes' do
38
+ it 'should return an array of athletes' do
39
+ @client.athletes(:mlb).first.fullName.should eq('Chase Utley')
46
40
  end
47
41
 
48
- context 'with a athlete_id param' do
49
- it 'should include the athlete_id in the request' do
50
- stub_get('sports/athletes/5')
51
- @client.athletes(athlete_id: 5)
52
- assert_requested :get, espn_url('sports/athletes/5')
53
- end
42
+ it 'should get athletes for the given league' do
43
+ @client.athletes(:nba)
44
+ assert_requested :get, espn_url('sports/basketball/nba/athletes')
54
45
  end
55
46
 
56
- context 'with a league param and no sport param' do
57
- it 'should not include either in the request' do
58
- stub_get('sports/athletes')
59
- @client.athletes(league: 'mlb')
60
- assert_requested :get, espn_url('sports/athletes')
61
- end
47
+ it 'should accept a league in the opts hash' do
48
+ @client.athletes(league: 'mlb')
49
+ assert_requested :get, espn_url('sports/baseball/mlb/athletes')
50
+ end
62
51
 
63
- context 'with a athlete_id param' do
64
- it 'should include the athlete_id in the request' do
65
- stub_get('sports/athletes/2')
66
- @client.athletes(league: 'mlb', athlete_id: 2)
67
- assert_requested :get, espn_url('sports/athletes/2')
68
- end
52
+ context 'when league is not passed' do
53
+ it 'should raise an argument error' do
54
+ expect { @client.athletes }.to raise_error(ArgumentError)
69
55
  end
70
56
  end
71
57
 
58
+ context 'when invalid league is passed' do
59
+ it 'should raise an argument error' do
60
+ expect { @client.athletes(:foobar) }.to raise_error(ArgumentError)
61
+ end
62
+ end
72
63
  end
73
64
  end
@@ -3,44 +3,45 @@ require 'spec_helper'
3
3
  describe ESPN::Client::Audio do
4
4
  before do
5
5
  @client = ESPN::Client.new
6
+ stub_get 'audio.json'
6
7
  end
7
8
 
8
- it 'should get all podcasts' do
9
- stub_get('audio/podcasts')
10
- @client.audio
11
- assert_requested :get, espn_url('audio/podcasts')
12
- end
9
+ describe '#audio' do
10
+ it 'should return an array of podcast recordings' do
11
+ @client.audio.first.categories.first.respond_to?(:podcast).should be_true
12
+ end
13
13
 
14
- context 'with a method param' do
15
- context 'if method is podcast_recordings' do
16
- it 'should include podcasts/recordings in the request' do
17
- stub_get('audio/podcasts/recordings')
18
- @client.audio(method: 'podcast_recordings')
19
- assert_requested :get, espn_url('audio/podcasts/recordings')
20
- end
14
+ it 'should get all podcasts by default' do
15
+ @client.audio
16
+ assert_requested :get, espn_url('audio/podcasts')
21
17
  end
22
18
 
23
- it 'should include the method in the request' do
24
- stub_get('audio/recordings')
25
- @client.audio(method: 'recordings')
26
- assert_requested :get, espn_url('audio/recordings')
19
+ context 'with a method param' do
20
+ it 'should include the method in the request' do
21
+ @client.audio(method: 'recordings')
22
+ assert_requested :get, espn_url('audio/recordings')
23
+ end
24
+
25
+ context 'if method is podcast_recordings' do
26
+ it 'should convert to podcasts/recordings' do
27
+ @client.audio(method: 'podcast_recordings')
28
+ assert_requested :get, espn_url('audio/podcasts/recordings')
29
+ end
30
+ end
27
31
  end
28
- end
29
32
 
30
- context 'with a podcast_id param' do
31
- it 'should include the podcast_id in the param' do
32
- stub_get('audio/podcasts/1')
33
- @client.audio(podcast_id: 1)
34
- assert_requested :get, espn_url('audio/podcasts/1')
33
+ context 'with a podcast_id param' do
34
+ it 'should include the podcast_id in the param' do
35
+ @client.audio(podcast_id: 1)
36
+ assert_requested :get, espn_url('audio/podcasts/1')
37
+ end
35
38
  end
36
- end
37
39
 
38
- context 'with a recording_id param' do
39
- it 'should include the recording_id in the param' do
40
- stub_get('audio/podcasts/2')
41
- @client.audio(recording_id: 2)
42
- assert_requested :get, espn_url('audio/podcasts/2')
40
+ context 'with a recording_id param' do
41
+ it 'should include the recording_id in the param' do
42
+ @client.audio(recording_id: 2)
43
+ assert_requested :get, espn_url('audio/podcasts/2')
44
+ end
43
45
  end
44
46
  end
45
-
46
47
  end
@@ -3,60 +3,105 @@ require 'spec_helper'
3
3
  describe ESPN::Client::Headlines do
4
4
  before do
5
5
  @client = ESPN::Client.new
6
+ stub_get 'headlines.json'
7
+ end
8
+
9
+ describe '#headline' do
10
+ it 'should include the id in the request' do
11
+ @client.headline(5)
12
+ assert_requested :get, espn_url('sports/news/5')
13
+ end
14
+
15
+ it 'should not return an array' do
16
+ @client.headline(5).should_not be_a(Array)
17
+ end
18
+
19
+ it 'should return the headline' do
20
+ @client.headline(5).type.should eq('HeadlineNews')
21
+ end
6
22
  end
7
23
 
8
24
  describe '#headlines' do
25
+ it 'should return an array of headlines' do
26
+ @client.headlines.first.type.should eq('HeadlineNews')
27
+ end
28
+
9
29
  it 'should get headlines for sports by default' do
10
- stub_get('sports/news')
11
30
  @client.headlines
12
31
  assert_requested :get, espn_url('sports/news')
13
32
  end
14
33
 
15
- context 'with a section param' do
16
- it 'should get headlines for that section' do
17
- stub_get('cities/news')
18
- @client.headlines(section: 'cities')
19
- assert_requested :get, espn_url('cities/news')
34
+ context 'when passing values as args' do
35
+ context 'when passing the sport' do
36
+ it 'should request headlines for that sport' do
37
+ @client.headlines('horse-racing')
38
+ assert_requested :get, espn_url('sports/horse-racing/news')
39
+ end
20
40
  end
21
- end
22
41
 
23
- context 'with a sport param' do
24
- it 'should include the sport in the request' do
25
- stub_get('sports/baseball/news')
26
- @client.headlines(sport: 'baseball')
27
- assert_requested :get, espn_url('sports/baseball/news')
42
+ context 'when passing the league' do
43
+ it 'should request headlines for that league' do
44
+ @client.headlines(:mlb)
45
+ assert_requested :get, espn_url('sports/baseball/mlb/news')
46
+ end
28
47
  end
29
- end
30
48
 
31
- context 'with a sport and league param' do
32
- it 'should include both params in the request' do
33
- stub_get('sports/baseball/mlb/news')
34
- @client.headlines(sport: 'baseball', league: 'mlb')
35
- assert_requested :get, espn_url('sports/baseball/mlb/news')
49
+ context 'when passing the league and sport' do
50
+ it 'should request headlines for that sport and league' do
51
+ @client.headlines('horse-racing', 'mlb')
52
+ assert_requested :get, espn_url('sports/horse-racing/mlb/news')
53
+ end
36
54
  end
37
- end
38
55
 
39
- context 'with a league param but no sport param' do
40
- it 'should not include the league in the request' do
41
- stub_get('sports/news')
42
- @client.headlines(league: 'mlb')
43
- assert_requested :get, espn_url('sports/news')
56
+ context 'when passing sport in the opts hash' do
57
+ it 'should override the symbol with the opts' do
58
+ @client.headlines(:basketball, sport: 'baseball')
59
+ assert_requested :get, espn_url('sports/baseball/news')
60
+ end
44
61
  end
45
- end
46
62
 
47
- context 'with a method param' do
48
- it 'should include the method in the request' do
49
- stub_get('sports/news/headlines/top')
50
- @client.headlines(method: 'top')
51
- assert_requested :get, espn_url('sports/news/headlines/top')
63
+ context 'when passing league in the opts hash' do
64
+ it 'should override the symbol with the opts' do
65
+ @client.headlines('wnba', league: 'mlb')
66
+ assert_requested :get, espn_url('sports/basketball/mlb/news')
67
+ end
52
68
  end
53
69
  end
54
70
 
55
- context 'with a headline_id param' do
56
- it 'should include the headline_id in the request' do
57
- stub_get('sports/news/5')
58
- @client.headlines(headline_id: 5)
59
- assert_requested :get, espn_url('sports/news/5')
71
+ context 'when passing values in the opts hash' do
72
+ context 'with a section param' do
73
+ it 'should get headlines for that section' do
74
+ @client.headlines(section: 'cities')
75
+ assert_requested :get, espn_url('cities/news')
76
+ end
77
+ end
78
+
79
+ context 'with a sport param' do
80
+ it 'should get headlines for that sport' do
81
+ @client.headlines(sport: 'baseball')
82
+ assert_requested :get, espn_url('sports/baseball/news')
83
+ end
84
+ end
85
+
86
+ context 'with a sport and league param' do
87
+ it 'should get headlines for that sport and league' do
88
+ @client.headlines(sport: 'baseball', league: 'mlb')
89
+ assert_requested :get, espn_url('sports/baseball/mlb/news')
90
+ end
91
+ end
92
+
93
+ context 'with a league param but no sport param' do
94
+ it 'should get headlines for that league mapped to a sport' do
95
+ @client.headlines(league: 'mlb')
96
+ assert_requested :get, espn_url('sports/baseball/mlb/news')
97
+ end
98
+ end
99
+
100
+ context 'with a method param' do
101
+ it 'should get headlines for that method' do
102
+ @client.headlines(method: 'top')
103
+ assert_requested :get, espn_url('sports/news/headlines/top')
104
+ end
60
105
  end
61
106
  end
62
107
  end
@@ -3,10 +3,10 @@ require 'spec_helper'
3
3
  describe ESPN::Client::Medals do
4
4
  before do
5
5
  @client = ESPN::Client.new
6
+ stub_get 'medals.json'
6
7
  end
7
8
 
8
9
  it 'should get all medals' do
9
- stub_get('sports/olympics/medals')
10
10
  @client.medals
11
11
  assert_requested :get, espn_url('sports/olympics/medals')
12
12
  end
@@ -3,71 +3,65 @@ require 'spec_helper'
3
3
  describe ESPN::Client::Notes do
4
4
  before do
5
5
  @client = ESPN::Client.new
6
+ stub_get 'notes.json'
7
+ end
8
+
9
+ describe '#note' do
10
+ it 'should return a note' do
11
+ @client.note(1).headline.should eq('Cowboys Stink')
12
+ end
13
+
14
+ it 'should include the id in the request' do
15
+ @client.note(1)
16
+ assert_requested :get, espn_url('sports/news/notes/1')
17
+ end
6
18
  end
7
19
 
8
20
  describe '#notes' do
21
+ it 'should return an array of notes' do
22
+ @client.notes.first.respond_to?(:headline).should be_true
23
+ end
9
24
 
10
- it 'gets all notes' do
11
- stub_get('sports/news/notes')
25
+ it 'gets all notes by default' do
12
26
  @client.notes
13
27
  assert_requested :get, espn_url('sports/news/notes')
14
28
  end
15
29
 
16
- context 'with a sport param' do
17
- it 'should include the sport in the request' do
18
- stub_get('sports/baseball/news/notes')
19
- @client.notes(sport: 'baseball')
20
- assert_requested :get, espn_url('sports/baseball/news/notes')
21
- end
22
-
23
- context 'with a note_id param' do
24
- it 'should include the sport and note_id params in the request' do
25
- stub_get('sports/baseball/news/notes/5')
26
- @client.notes(sport: 'baseball', note_id: 5)
27
- assert_requested :get, espn_url('sports/baseball/news/notes/5')
30
+ context 'when passing values as args' do
31
+ context 'when passing the sport' do
32
+ it 'should request notes for that sport' do
33
+ @client.notes(:football)
34
+ assert_requested :get, espn_url('sports/football/news/notes')
28
35
  end
29
36
  end
30
- end
31
-
32
- context 'with a sport and a league param' do
33
- it 'should include the sport and league params in the request' do
34
- stub_get('sports/baseball/mlb/news/notes')
35
- @client.notes(sport: 'baseball', league: 'mlb')
36
- assert_requested :get, espn_url('sports/baseball/mlb/news/notes')
37
- end
38
37
 
39
- context 'with a note_id param' do
40
- it 'should include the sport, league and note_id params' do
41
- stub_get('sports/baseball/mlb/news/notes/1')
42
- @client.notes(sport: 'baseball', league: 'mlb', note_id: 1)
43
- assert_requested :get, espn_url('sports/baseball/mlb/news/notes/1')
38
+ context 'when passing the league' do
39
+ it 'should request notes for the league' do
40
+ @client.notes(:nfl)
41
+ assert_requested :get, espn_url('sports/football/nfl/news/notes')
44
42
  end
45
43
  end
46
- end
47
44
 
48
- context 'with a note_id param' do
49
- it 'should include the note_id in the request' do
50
- stub_get('sports/news/notes/5')
51
- @client.notes(note_id: 5)
52
- assert_requested :get, espn_url('sports/news/notes/5')
45
+ context 'when passing the league and sport' do
46
+ it 'should request notes for that league and sport' do
47
+ @client.notes(:baseball, 'mlb')
48
+ assert_requested :get, espn_url('sports/baseball/mlb/news/notes')
49
+ end
53
50
  end
54
- end
55
51
 
56
- context 'with a league param and no sport param' do
57
- it 'should not include either in the request' do
58
- stub_get('sports/news/notes')
59
- @client.notes(league: 'mlb')
60
- assert_requested :get, espn_url('sports/news/notes')
52
+ context 'when passing sport in the opts hash' do
53
+ it 'should override the symbol with the opts' do
54
+ @client.notes(:basketball, sport: 'baseball')
55
+ assert_requested :get, espn_url('sports/baseball/news/notes')
56
+ end
61
57
  end
62
58
 
63
- context 'with a note_id param' do
64
- it 'should include the note_id in the request' do
65
- stub_get('sports/news/notes/2')
66
- @client.notes(league: 'mlb', note_id: 2)
67
- assert_requested :get, espn_url('sports/news/notes/2')
59
+ context 'when passing league in the opts hash' do
60
+ it 'should override the symbol with the opts' do
61
+ @client.notes('wnba', league: 'mlb')
62
+ assert_requested :get, espn_url('sports/basketball/mlb/news/notes')
68
63
  end
69
64
  end
70
65
  end
71
-
72
66
  end
73
67
  end
@@ -3,17 +3,16 @@ require 'spec_helper'
3
3
  describe ESPN::Client::Now do
4
4
  before do
5
5
  @client = ESPN::Client.new
6
+ stub_get 'now.json'
6
7
  end
7
8
 
8
9
  it 'gets all latest content' do
9
- stub_get('now')
10
10
  @client.now
11
11
  assert_requested :get, espn_url('now')
12
12
  end
13
13
 
14
14
  context 'with a method param' do
15
15
  it 'should include the method in the request' do
16
- stub_get('now/popular')
17
16
  @client.now(method: 'popular')
18
17
  assert_requested :get, espn_url('now/popular')
19
18
  end