espn 0.0.2 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE.md +20 -0
- data/README.md +38 -3
- data/espn.gemspec +6 -2
- data/lib/espn.rb +13 -3
- data/lib/espn/client.rb +34 -7
- data/lib/espn/client/athletes.rb +34 -0
- data/lib/espn/client/audio.rb +37 -0
- data/lib/espn/client/headlines.rb +42 -0
- data/lib/espn/client/medals.rb +16 -0
- data/lib/espn/client/notes.rb +35 -0
- data/lib/espn/client/now.rb +23 -0
- data/lib/espn/client/scores.rb +34 -0
- data/lib/espn/client/sports.rb +16 -8
- data/lib/espn/client/standings.rb +29 -0
- data/lib/espn/client/teams.rb +23 -8
- data/lib/espn/client/video.rb +30 -0
- data/lib/espn/configuration.rb +40 -8
- data/lib/espn/request.rb +8 -0
- data/lib/espn/version.rb +4 -1
- data/spec/espn/client/athletes_spec.rb +73 -0
- data/spec/espn/client/audio_spec.rb +46 -0
- data/spec/espn/client/headlines_spec.rb +64 -0
- data/spec/espn/client/medals_spec.rb +14 -0
- data/spec/espn/client/notes_spec.rb +73 -0
- data/spec/espn/client/now_spec.rb +22 -0
- data/spec/espn/client/scores_spec.rb +73 -0
- data/spec/espn/client/sports_spec.rb +41 -0
- data/spec/espn/client/standings_spec.rb +41 -0
- data/spec/espn/client/teams_spec.rb +73 -0
- data/spec/espn/client/video_spec.rb +30 -0
- data/spec/espn/client_spec.rb +49 -0
- data/spec/espn/configuration_spec.rb +30 -0
- data/spec/espn_spec.rb +31 -0
- data/spec/spec_helper.rb +11 -0
- metadata +62 -39
- data/.gitignore +0 -3
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -65
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MmNiOWEzYWM3YTI5MzBkYTZkMTI3ZWYzNjU5ODJlNzEyYzg5OWI4Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTY0NGE5MzY5YzVlNGEyNDAyM2ZlYzRjOTE2MjY5YmQzZjM3OGMwYw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
N2FlMmU2MjA0YmMwNTk4OWIzYmYxMjRmZWQ4NmVjMWUzZTU2OGYxMjUzYzEy
|
10
|
+
ZTZhMTk1Y2ZkOTdjOTljODIxZWVhN2E2MTFkMDE0YWRjOWQ0NDRhZWM0ZTE2
|
11
|
+
ZDg0MjAzZGU1Njg5NDgwMjg4NTAyZDJjZTgzN2M5ZTM4NjNhM2U=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Zjk1Njc1OGNjZDBhNzFmYjdkMjAyYzA2ZDg3MWYzMGNiNTc4ODNkNjUyY2Vm
|
14
|
+
ZDBjNjgwNzM2Y2IxNWJiMGNiYTY0MWYzOThmOTBhMGZjMjU1NTk0ZWM1M2Mw
|
15
|
+
MmE0ODc1MWFmMDdhZDRiMDM5N2MwYTc2ZDU5ZWUwMTRiNGQ4NWU=
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Andrew Thorp
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,5 +1,40 @@
|
|
1
|
-
#
|
1
|
+
# ESPN
|
2
2
|
|
3
|
-
|
3
|
+
Simply Ruby Wrapper for the ESPN Developer API.
|
4
4
|
|
5
|
-
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem install espn
|
8
|
+
|
9
|
+
## Examples
|
10
|
+
|
11
|
+
First, setup your client:
|
12
|
+
|
13
|
+
client = ESPN::Client.new(api_key: 'your_api_key_here')
|
14
|
+
|
15
|
+
Next, make calls against the ESPN API.
|
16
|
+
|
17
|
+
### Sports
|
18
|
+
|
19
|
+
sport = client.sports(sport: 'baseball', league: 'mlb').sports.first
|
20
|
+
puts sport.leagues.first.groups.first.name
|
21
|
+
# => American League
|
22
|
+
|
23
|
+
### Headlines
|
24
|
+
|
25
|
+
headline = client.headlines(sport: 'baseball', league: 'mlb').headlines.first
|
26
|
+
puts headline.title
|
27
|
+
# => Atlanta Braves outfielder Jason Heyward hit in jaw with pitch
|
28
|
+
|
29
|
+
## Inspiration
|
30
|
+
|
31
|
+
A ton of inspiration was taken from [Octokit][octokit]. Thanks to those guys for
|
32
|
+
showing the world how API Wrappers should work.
|
33
|
+
|
34
|
+
[octokit]: http://github.com/octokit/octokit.rb
|
35
|
+
|
36
|
+
## Copyright
|
37
|
+
|
38
|
+
Copyright (c) 2013 Andrew Thorp. See [LICENSE][] for details.
|
39
|
+
|
40
|
+
[license]: LICENSE.md
|
data/espn.gemspec
CHANGED
@@ -3,7 +3,7 @@ require File.expand_path('../lib/espn/version', __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'espn'
|
6
|
-
s.version = ESPN::VERSION
|
6
|
+
s.version = ESPN::VERSION.dup
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
|
9
9
|
s.authors = ['Andrew Thorp']
|
@@ -24,10 +24,14 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency 'rspec'
|
25
25
|
s.add_development_dependency 'simplecov'
|
26
26
|
s.add_development_dependency 'webmock'
|
27
|
+
s.add_development_dependency 'vcr'
|
27
28
|
s.add_development_dependency 'yard'
|
28
29
|
s.add_development_dependency 'markdown'
|
29
30
|
|
30
|
-
s.files
|
31
|
+
s.files = %w(LICENSE.md README.md espn.gemspec)
|
32
|
+
s.files += Dir.glob("lib/**/*.rb")
|
33
|
+
s.files += Dir.glob("spec/**/*")
|
34
|
+
|
31
35
|
s.test_files = Dir.glob("spec/**/*")
|
32
36
|
s.require_paths = ["lib"]
|
33
37
|
end
|
data/lib/espn.rb
CHANGED
@@ -4,22 +4,32 @@ require 'espn/error'
|
|
4
4
|
|
5
5
|
module ESPN
|
6
6
|
extend Configuration
|
7
|
+
|
7
8
|
class << self
|
8
|
-
|
9
|
+
|
10
|
+
# Public: An alias for ESPN::Client.new.
|
9
11
|
#
|
10
|
-
#
|
12
|
+
# Returns an ESPN::Client.
|
11
13
|
def new(options={})
|
12
14
|
ESPN::Client.new(options)
|
13
15
|
end
|
14
16
|
|
15
|
-
# Delegate to ESPN::Client.new
|
17
|
+
# Public: Delegate methods to ESPN::Client.new. If a ESPN::Client does not
|
18
|
+
# respond_to? the :method, pass it up the chain.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
16
21
|
def method_missing(method, *args, &block)
|
17
22
|
return super unless new.respond_to?(method)
|
18
23
|
new.send(method, *args, &block)
|
19
24
|
end
|
20
25
|
|
26
|
+
# Public: Delegate to ESPN::Client.new respond_to?
|
27
|
+
#
|
28
|
+
# Returns nothing.
|
21
29
|
def respond_to?(method, include_private=false)
|
22
30
|
new.respond_to?(method, include_private) || super(method, include_private)
|
23
31
|
end
|
32
|
+
|
24
33
|
end
|
34
|
+
|
25
35
|
end
|
data/lib/espn/client.rb
CHANGED
@@ -1,38 +1,65 @@
|
|
1
1
|
require 'espn/connection'
|
2
2
|
require 'espn/request'
|
3
|
+
|
4
|
+
require 'espn/client/athletes'
|
5
|
+
require 'espn/client/audio'
|
6
|
+
require 'espn/client/headlines'
|
7
|
+
require 'espn/client/medals'
|
8
|
+
require 'espn/client/notes'
|
9
|
+
require 'espn/client/now'
|
10
|
+
require 'espn/client/scores'
|
3
11
|
require 'espn/client/sports'
|
12
|
+
require 'espn/client/standings'
|
4
13
|
require 'espn/client/teams'
|
14
|
+
require 'espn/client/video'
|
5
15
|
|
6
16
|
module ESPN
|
7
17
|
|
8
18
|
class Client
|
19
|
+
|
20
|
+
# Public: An attr_accessor for each configuration option.
|
9
21
|
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
10
22
|
|
11
|
-
|
12
|
-
|
23
|
+
# Public: Initialize a new Client. To see all options that can be
|
24
|
+
# configured, look at the Configuration module, specifically
|
25
|
+
# VALID_OPTIONS_KEYS.
|
26
|
+
#
|
27
|
+
# opts - A Hash of configuration options.
|
28
|
+
def initialize(opts={})
|
29
|
+
options = ESPN.options.merge(opts)
|
13
30
|
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
14
31
|
send("#{key}=", options[key])
|
15
32
|
end
|
16
33
|
end
|
17
34
|
|
18
|
-
#
|
35
|
+
# Public: Get the base URL for accessing the ESPN API.
|
19
36
|
#
|
20
|
-
#
|
37
|
+
# Returns a String.
|
21
38
|
def api_url
|
22
|
-
"http://api.espn.com/v1"
|
39
|
+
"http://api.espn.com/v1/"
|
23
40
|
end
|
24
41
|
|
25
|
-
# Determine if
|
42
|
+
# Public: Determine if the ESPN::Client has been authenticated. At this
|
43
|
+
# point, we are just checking to see if an :api_key has been set.
|
26
44
|
#
|
27
|
-
#
|
45
|
+
# Returns a Boolean.
|
28
46
|
def authed?
|
29
47
|
!api_key.nil?
|
30
48
|
end
|
31
49
|
|
32
50
|
include ESPN::Connection
|
33
51
|
include ESPN::Request
|
52
|
+
include ESPN::Client::Athletes
|
53
|
+
include ESPN::Client::Audio
|
54
|
+
include ESPN::Client::Headlines
|
55
|
+
include ESPN::Client::Medals
|
56
|
+
include ESPN::Client::Notes
|
57
|
+
include ESPN::Client::Now
|
58
|
+
include ESPN::Client::Scores
|
34
59
|
include ESPN::Client::Sports
|
60
|
+
include ESPN::Client::Standings
|
35
61
|
include ESPN::Client::Teams
|
62
|
+
include ESPN::Client::Video
|
36
63
|
|
37
64
|
end
|
38
65
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ESPN
|
2
|
+
class Client
|
3
|
+
module Athletes
|
4
|
+
|
5
|
+
# Public: Get athlete stats and information from the ESPN API.
|
6
|
+
#
|
7
|
+
# opts - Hash options used to refine the selection (default: {}).
|
8
|
+
# - :sport - The name of the sport (default: nil).
|
9
|
+
# - :league - The name of the league (default: nil).
|
10
|
+
# - :athlete_id - The id of the athlete (default: nil).
|
11
|
+
#
|
12
|
+
# Returns an Array of Hashie::Mash.
|
13
|
+
def athletes(opts={})
|
14
|
+
url = "sports"
|
15
|
+
|
16
|
+
unless opts[:sport].to_s.empty?
|
17
|
+
url += "/#{opts[:sport]}"
|
18
|
+
unless opts[:league].to_s.empty?
|
19
|
+
url += "/#{opts[:league]}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
url += "/athletes"
|
24
|
+
|
25
|
+
unless opts[:athlete_id].to_s.empty?
|
26
|
+
url += "/#{opts[:athlete_id]}"
|
27
|
+
end
|
28
|
+
|
29
|
+
get(url, opts)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ESPN
|
2
|
+
class Client
|
3
|
+
module Audio
|
4
|
+
|
5
|
+
# Public: Get audio podcasts and clips from ESPN.
|
6
|
+
#
|
7
|
+
# opts - Hash options used to refine the selection (default: {}).
|
8
|
+
# - :method - The name of the sport (default: 'podcasts').
|
9
|
+
# - :podast_id - The id of the podcast (default: nil).
|
10
|
+
# - :recording_id - The id of the recording (default: nil).
|
11
|
+
#
|
12
|
+
# Returns an Array of Hashie::Mash.
|
13
|
+
def audio(opts={})
|
14
|
+
opts [:method] ||= 'podcasts'
|
15
|
+
|
16
|
+
url = 'audio'
|
17
|
+
|
18
|
+
if opts[:method] == 'podcast_recordings'
|
19
|
+
url += '/podcasts/recordings'
|
20
|
+
else
|
21
|
+
url += "/#{opts[:method]}"
|
22
|
+
end
|
23
|
+
|
24
|
+
unless opts[:podcast_id].to_s.empty?
|
25
|
+
url += "/#{opts[:podcast_id]}"
|
26
|
+
end
|
27
|
+
|
28
|
+
unless opts[:recording_id].to_s.empty?
|
29
|
+
url += "/#{opts[:recording_id]}"
|
30
|
+
end
|
31
|
+
|
32
|
+
get(url, opts)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ESPN
|
2
|
+
class Client
|
3
|
+
module Headlines
|
4
|
+
|
5
|
+
# Public: Get latest sports news and analysis from the ESPN API.
|
6
|
+
#
|
7
|
+
# opts - Hash options used to refine the selection (default: {}).
|
8
|
+
# - :section - The news section (default: 'sports').
|
9
|
+
# - :sport - The name of the sport (default: nil).
|
10
|
+
# - :league - The name of the league (default: nil).
|
11
|
+
# - :method - The method of headlines (default: nil).
|
12
|
+
# - :headline_id - The id of a specific headline (default: nil).
|
13
|
+
#
|
14
|
+
# Returns an Array of Hashie::Mash.
|
15
|
+
def headlines(opts={})
|
16
|
+
url = opts[:section] || 'sports'
|
17
|
+
|
18
|
+
unless opts[:sport].to_s.empty?
|
19
|
+
url += "/#{opts[:sport]}"
|
20
|
+
unless opts[:league].to_s.empty?
|
21
|
+
url += "/#{opts[:league]}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
url += '/news'
|
26
|
+
|
27
|
+
unless opts[:method].to_s.empty?
|
28
|
+
url += "/headlines/#{opts[:method]}"
|
29
|
+
end
|
30
|
+
|
31
|
+
unless opts[:headline_id].to_s.empty?
|
32
|
+
url += "/#{opts[:headline_id]}"
|
33
|
+
end
|
34
|
+
|
35
|
+
puts url
|
36
|
+
|
37
|
+
get(url, opts)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ESPN
|
2
|
+
class Client
|
3
|
+
module Medals
|
4
|
+
|
5
|
+
# Public: Get medal counts and competition from the olympic games.
|
6
|
+
#
|
7
|
+
# opts - Hash options used to refine the selection (default: {}).
|
8
|
+
#
|
9
|
+
# Returns an Array of Hashie::Mash.
|
10
|
+
def medals(opts={})
|
11
|
+
get('sports/olympics/medals', opts)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ESPN
|
2
|
+
class Client
|
3
|
+
module Notes
|
4
|
+
|
5
|
+
# Public: Get Exclusive factoids produced by ESPN's Stats and Information
|
6
|
+
# Group from the ESPN API.
|
7
|
+
#
|
8
|
+
# opts - Hash options used to refine the selection (default: {}).
|
9
|
+
# - :sport - The name of the sport (default: nil).
|
10
|
+
# - :league - The name of the league (default: nil).
|
11
|
+
# - :note_id - The id of the note (default: nil).
|
12
|
+
#
|
13
|
+
# Returns an Array of Hashie::Mash.
|
14
|
+
def notes(opts={})
|
15
|
+
url = 'sports'
|
16
|
+
|
17
|
+
unless opts[:sport].to_s.empty?
|
18
|
+
url += "/#{opts[:sport]}"
|
19
|
+
unless opts[:league].to_s.empty?
|
20
|
+
url += "/#{opts[:league]}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
url += '/news/notes'
|
25
|
+
|
26
|
+
unless opts[:note_id].to_s.empty?
|
27
|
+
url += "/#{opts[:note_id]}"
|
28
|
+
end
|
29
|
+
|
30
|
+
get(url, opts)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ESPN
|
2
|
+
class Client
|
3
|
+
module Now
|
4
|
+
|
5
|
+
# Public: Get stream of the latest content published on ESPN.com.
|
6
|
+
#
|
7
|
+
# opts - Hash options used to refine the selection (default: {}).
|
8
|
+
# - :method - The type of content to retrieve (default: nil).
|
9
|
+
#
|
10
|
+
# Returns an Array of Hashie::Mash
|
11
|
+
def now(opts={})
|
12
|
+
url = 'now'
|
13
|
+
|
14
|
+
unless opts[:method].to_s.empty?
|
15
|
+
url += "/#{opts[:method]}"
|
16
|
+
end
|
17
|
+
|
18
|
+
get(url, opts)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ESPN
|
2
|
+
class Client
|
3
|
+
module Scores
|
4
|
+
|
5
|
+
# Public: Get schedule and scores information from the ESPN API.
|
6
|
+
#
|
7
|
+
# opts - Hash options used to refine the selection (default: {}).
|
8
|
+
# - :sport - The name of the sport (default: nil).
|
9
|
+
# - :league - The name of the league (default: nil).
|
10
|
+
# - :event_id - The event to get information about (default: nil).
|
11
|
+
#
|
12
|
+
# Returns an Array of Hashie::Mash.
|
13
|
+
def scores(opts={})
|
14
|
+
url = 'sports'
|
15
|
+
|
16
|
+
unless opts[:sport].to_s.empty?
|
17
|
+
url += "/#{opts[:sport]}"
|
18
|
+
unless opts[:league].to_s.empty?
|
19
|
+
url += "/#{opts[:league]}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
url += '/events'
|
24
|
+
|
25
|
+
unless opts[:event_id].to_s.empty?
|
26
|
+
url += "/#{opts[:event_id]}"
|
27
|
+
end
|
28
|
+
|
29
|
+
get(url, opts)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|