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.
- checksums.yaml +8 -8
- data/README.md +91 -6
- data/lib/espn.rb +5 -0
- data/lib/espn/arguments.rb +41 -0
- data/lib/espn/client.rb +29 -5
- data/lib/espn/client/athletes.rb +39 -21
- data/lib/espn/client/audio.rb +20 -19
- data/lib/espn/client/headlines.rb +58 -27
- data/lib/espn/client/medals.rb +8 -0
- data/lib/espn/client/notes.rb +31 -21
- data/lib/espn/client/now.rb +11 -8
- data/lib/espn/client/scores.rb +33 -21
- data/lib/espn/client/sports.rb +20 -14
- data/lib/espn/client/standings.rb +20 -16
- data/lib/espn/client/teams.rb +39 -21
- data/lib/espn/client/video.rb +14 -17
- data/lib/espn/configuration.rb +29 -12
- data/lib/espn/error.rb +15 -3
- data/lib/espn/helpers.rb +39 -0
- data/lib/espn/mapper.rb +142 -0
- data/lib/espn/request.rb +86 -7
- data/lib/espn/version.rb +1 -1
- data/lib/faraday/response/raise_espn_error.rb +33 -11
- data/spec/espn/arguments_spec.rb +76 -0
- data/spec/espn/client/athletes_spec.rb +38 -47
- data/spec/espn/client/audio_spec.rb +30 -29
- data/spec/espn/client/headlines_spec.rb +80 -35
- data/spec/espn/client/medals_spec.rb +1 -1
- data/spec/espn/client/notes_spec.rb +39 -45
- data/spec/espn/client/now_spec.rb +1 -2
- data/spec/espn/client/scores_spec.rb +56 -39
- data/spec/espn/client/sports_spec.rb +56 -18
- data/spec/espn/client/standings_spec.rb +42 -19
- data/spec/espn/client/teams_spec.rb +61 -43
- data/spec/espn/client/video_spec.rb +9 -13
- data/spec/espn/helpers_spec.rb +31 -0
- data/spec/espn/mapper_spec.rb +136 -0
- data/spec/espn/request_spec.rb +65 -0
- data/spec/espn_spec.rb +11 -2
- data/spec/faraday/response/raise_espn_error_spec.rb +80 -0
- data/spec/responses/athletes.json +51 -0
- data/spec/responses/audio.json +101 -0
- data/spec/responses/headlines.json +174 -0
- data/spec/responses/medals.json +273 -0
- data/spec/responses/notes.json +100 -0
- data/spec/responses/now.json +44 -0
- data/spec/responses/scores.json +209 -0
- data/spec/responses/sports.json +164 -0
- data/spec/responses/standings.json +2689 -0
- data/spec/responses/teams.json +51 -0
- data/spec/responses/videos.json +28 -0
- data/spec/spec_helper.rb +11 -2
- metadata +37 -3
- data/lib/espn/connection.rb +0 -32
data/lib/espn/client/medals.rb
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
module ESPN
|
2
2
|
class Client
|
3
|
+
|
4
|
+
# Public: The mapping to the MEDALS API of the ESPN developer API.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# class Client
|
9
|
+
# include ESPN::Client::Medals
|
10
|
+
# end
|
3
11
|
module Medals
|
4
12
|
|
5
13
|
# Public: Get medal counts and competition from the olympic games.
|
data/lib/espn/client/notes.rb
CHANGED
@@ -1,33 +1,43 @@
|
|
1
1
|
module ESPN
|
2
2
|
class Client
|
3
|
+
|
4
|
+
# Public: The mapping to the RESEARCH NOTES API of the ESPN developer API.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# class Client
|
9
|
+
# include ESPN::Client::Notes
|
10
|
+
# end
|
3
11
|
module Notes
|
4
12
|
|
13
|
+
# Public: Get a specific note from the ESPN developer API.
|
14
|
+
#
|
15
|
+
# id - The id of a specific note.
|
16
|
+
# opts - Hash options used to refine the selection. You can find a full
|
17
|
+
# list of options on the ESPN developer API website (default: {}).
|
18
|
+
#
|
19
|
+
# Returns a Hashie::Mash.
|
20
|
+
def note(id, opts={})
|
21
|
+
get("sports/news/notes/#{id}", opts).notes.first
|
22
|
+
end
|
23
|
+
|
5
24
|
# Public: Get Exclusive factoids produced by ESPN's Stats and Information
|
6
25
|
# Group from the ESPN API.
|
7
26
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
27
|
+
# sport - A Symbol or String of the sport (optional).
|
28
|
+
# league - A Symbol or String of the league. If a league is passed, but
|
29
|
+
# not a sport, an attempt will be made to map the league to a
|
30
|
+
# sport (required).
|
31
|
+
# opts - Hash options used to refine the selection. If sport and/or
|
32
|
+
# league are passed in, they will override the mapped values
|
33
|
+
# You can find a full list of options on the ESPN developer API
|
34
|
+
# website (default: {}).
|
12
35
|
#
|
13
36
|
# Returns an Array of Hashie::Mash.
|
14
|
-
def notes(
|
15
|
-
|
16
|
-
|
17
|
-
|
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)
|
37
|
+
def notes(*args)
|
38
|
+
arguments = ESPN::Arguments.new(args)
|
39
|
+
pattern = "sports/:sport/:league/news/notes"
|
40
|
+
get(pattern, arguments.options).notes
|
31
41
|
end
|
32
42
|
|
33
43
|
end
|
data/lib/espn/client/now.rb
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
module ESPN
|
2
2
|
class Client
|
3
|
+
|
4
|
+
# Public: The mapping to the ESPN NOW API of the ESPN developer API.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# class Client
|
9
|
+
# include ESPN::Client::Now
|
10
|
+
# end
|
3
11
|
module Now
|
4
12
|
|
5
13
|
# Public: Get stream of the latest content published on ESPN.com.
|
6
14
|
#
|
7
15
|
# opts - Hash options used to refine the selection (default: {}).
|
8
|
-
#
|
16
|
+
# :method - The type of content to retrieve (default: nil).
|
9
17
|
#
|
10
18
|
# Returns an Array of Hashie::Mash
|
11
19
|
def now(opts={})
|
12
|
-
|
13
|
-
|
14
|
-
unless opts[:method].to_s.empty?
|
15
|
-
url += "/#{opts[:method]}"
|
16
|
-
end
|
17
|
-
|
18
|
-
get(url, opts)
|
20
|
+
pattern = 'now/:method'
|
21
|
+
get(pattern, opts).feed
|
19
22
|
end
|
20
23
|
|
21
24
|
end
|
data/lib/espn/client/scores.rb
CHANGED
@@ -1,32 +1,44 @@
|
|
1
1
|
module ESPN
|
2
2
|
class Client
|
3
|
+
|
4
|
+
# Public: The mapping to the SCORES & SCHEDULES API of the ESPN developer
|
5
|
+
# API.
|
6
|
+
#
|
7
|
+
# Examples
|
8
|
+
#
|
9
|
+
# class Client
|
10
|
+
# include ESPN::Client::Scores
|
11
|
+
# end
|
3
12
|
module Scores
|
4
13
|
|
14
|
+
# Public: Get the score for a specific event from the ESPN API.
|
15
|
+
#
|
16
|
+
# id - The id of an event to get the scores for.
|
17
|
+
# opts - Hash options used to refine the selection. You can find a full
|
18
|
+
# list of options on the ESPN developer API website (default: {}).
|
19
|
+
#
|
20
|
+
# Returns a Hashie::Mash.
|
21
|
+
def score(id, opts={})
|
22
|
+
get("sports/events/#{id}", opts).sports.first.leagues.first.events.first
|
23
|
+
end
|
24
|
+
|
5
25
|
# Public: Get schedule and scores information from the ESPN API.
|
6
26
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
27
|
+
# sport - A Symbol or String of the sport (optional).
|
28
|
+
# league - A Symbol or String of the league. If a league is passed, but
|
29
|
+
# not a sport, an attempt will be made to map the league to a
|
30
|
+
# sport (required).
|
31
|
+
# opts - Hash options used to refine the selection. If sport and/or
|
32
|
+
# league are passed in, they will override the mapped values
|
33
|
+
# You can find a full list of options on the ESPN developer API
|
34
|
+
# website (default: {}).
|
35
|
+
# :id - The id of a specific event (default: nil, optional).
|
11
36
|
#
|
12
37
|
# Returns an Array of Hashie::Mash.
|
13
|
-
def scores(
|
14
|
-
|
15
|
-
|
16
|
-
|
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)
|
38
|
+
def scores(*args)
|
39
|
+
arguments = ESPN::Arguments.new(args)
|
40
|
+
pattern = 'sports/:sport/:league/events/:id'
|
41
|
+
get(pattern, arguments.options).sports.first.leagues.first.events
|
30
42
|
end
|
31
43
|
|
32
44
|
end
|
data/lib/espn/client/sports.rb
CHANGED
@@ -1,25 +1,31 @@
|
|
1
1
|
module ESPN
|
2
2
|
class Client
|
3
|
+
|
4
|
+
# Public: The mapping to the SPORTS API of the ESPN developer API.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# class Client
|
9
|
+
# include ESPN::Client::Sports
|
10
|
+
# end
|
3
11
|
module Sports
|
4
12
|
|
5
13
|
# Public: Get sports and leagues supported in the ESPN API.
|
6
14
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
15
|
+
# sport - A Symbol or String of the sport (optional).
|
16
|
+
# league - A Symbol or String of the league. If a league is passed, but
|
17
|
+
# not a sport, an attempt will be made to map the league to a
|
18
|
+
# sport (required).
|
19
|
+
# opts - Hash options used to refine the selection. If sport and/or
|
20
|
+
# league are passed in, they will override the mapped values
|
21
|
+
# You can find a full list of options on the ESPN developer API
|
22
|
+
# website (default: {}).
|
10
23
|
#
|
11
24
|
# Returns an Array of Hashie::Mash.
|
12
|
-
def sports(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
url += "/#{opts[:sport]}"
|
17
|
-
unless opts[:league].to_s.empty?
|
18
|
-
url += "/#{opts[:league]}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
get(url, opts)
|
25
|
+
def sports(*args)
|
26
|
+
arguments = ESPN::Arguments.new(args)
|
27
|
+
pattern = 'sports/:sport/:league'
|
28
|
+
get(pattern, arguments.options).sports
|
23
29
|
end
|
24
30
|
|
25
31
|
end
|
@@ -1,27 +1,31 @@
|
|
1
1
|
module ESPN
|
2
2
|
class Client
|
3
|
+
|
4
|
+
# Public: The mapping to the STANDINGS API of the ESPN developer API.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# class Client
|
9
|
+
# include ESPN::Client::Standings
|
10
|
+
# end
|
3
11
|
module Standings
|
4
12
|
|
5
13
|
# Public: Get the latest league and divisional standings from ESPN.
|
6
14
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
15
|
+
# sport - A Symbol or String of the sport (optional).
|
16
|
+
# league - A Symbol or String of the league. If a league is passed, but
|
17
|
+
# not a sport, an attempt will be made to map the league to a
|
18
|
+
# sport (required).
|
19
|
+
# opts - Hash options used to refine the selection. If sport and/or
|
20
|
+
# league are passed in, they will override the mapped values
|
21
|
+
# You can find a full list of options on the ESPN developer API
|
22
|
+
# website (default: {}).
|
10
23
|
#
|
11
24
|
# Returns an Array of Hashie::Mash.
|
12
|
-
def standings(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
url += "/#{opts[:sport]}"
|
17
|
-
unless opts[:league].to_s.empty?
|
18
|
-
url += "/#{opts[:league]}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
url += '/standings'
|
23
|
-
|
24
|
-
get(url, opts)
|
25
|
+
def standings(*args)
|
26
|
+
arguments = ESPN::Arguments.new(args, {}, [:league])
|
27
|
+
pattern = 'sports/:sport/:league/standings'
|
28
|
+
get(pattern, arguments.options).sports.first.leagues.first.groups
|
25
29
|
end
|
26
30
|
|
27
31
|
end
|
data/lib/espn/client/teams.rb
CHANGED
@@ -1,32 +1,50 @@
|
|
1
1
|
module ESPN
|
2
2
|
class Client
|
3
|
+
|
4
|
+
# Public: The mapping to the TEAMS API of the ESPN developer API.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# class Client
|
9
|
+
# include ESPN::Client::Teams
|
10
|
+
# end
|
3
11
|
module Teams
|
4
12
|
|
13
|
+
# Public: Get a specific team from the ESPN API.
|
14
|
+
#
|
15
|
+
# id - An id of a team.
|
16
|
+
# sport - A Symbol or String of the sport (optional).
|
17
|
+
# league - A Symbol or String of the league. If a league is passed, but
|
18
|
+
# not a sport, an attempt will be made to map the league to a
|
19
|
+
# sport (required).
|
20
|
+
# opts - Hash options used to refine the selection. If sport and/or
|
21
|
+
# league are passed in, they will override the mapped values
|
22
|
+
# You can find a full list of options on the ESPN developer API
|
23
|
+
# website (default: {}).
|
24
|
+
#
|
25
|
+
# Returns a Hashie::Mash.
|
26
|
+
def team(id, *args)
|
27
|
+
arguments = ESPN::Arguments.new(args, {}, [:league])
|
28
|
+
pattern = "sports/:sport/:league/teams/#{id}"
|
29
|
+
get(pattern, arguments.options).sports.first.leagues.first.teams.first
|
30
|
+
end
|
31
|
+
|
5
32
|
# Public: Get sport team stats and information from the ESPN API.
|
6
33
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
34
|
+
# sport - A Symbol or String of the sport (optional).
|
35
|
+
# league - A Symbol or String of the league. If a league is passed, but
|
36
|
+
# not a sport, an attempt will be made to map the league to a
|
37
|
+
# sport (required).
|
38
|
+
# opts - Hash options used to refine the selection. If sport and/or
|
39
|
+
# league are passed in, they will override the mapped values
|
40
|
+
# You can find a full list of options on the ESPN developer API
|
41
|
+
# website (default: {}).
|
11
42
|
#
|
12
43
|
# Returns an Array of Hashie::Mash.
|
13
|
-
def teams(
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
url += "/#{opts[:sport]}"
|
18
|
-
unless opts[:league].to_s.empty?
|
19
|
-
url += "/#{opts[:league]}"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
url += '/teams'
|
24
|
-
|
25
|
-
unless opts[:team_id].to_s.empty?
|
26
|
-
url += "/#{opts[:team_id]}"
|
27
|
-
end
|
28
|
-
|
29
|
-
get(url, opts)
|
44
|
+
def teams(*args)
|
45
|
+
arguments = ESPN::Arguments.new(args, {}, [:league])
|
46
|
+
pattern = 'sports/:sport/:league/teams'
|
47
|
+
get(pattern, arguments.options).sports.first.leagues.first.teams
|
30
48
|
end
|
31
49
|
|
32
50
|
end
|
data/lib/espn/client/video.rb
CHANGED
@@ -1,28 +1,25 @@
|
|
1
1
|
module ESPN
|
2
2
|
class Client
|
3
|
+
|
4
|
+
# Public: The mapping to the VIDEO API of the ESPN developer API.
|
5
|
+
#
|
6
|
+
# Examples
|
7
|
+
#
|
8
|
+
# class Client
|
9
|
+
# include ESPN::Client::Video
|
10
|
+
# end
|
3
11
|
module Video
|
4
12
|
|
5
13
|
# Public: Get video clip and channel information from ESPN.
|
6
14
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
15
|
+
# channel_id - The id of a video channel.
|
16
|
+
# opts - Hash options used to refine the selection (default: {}).
|
17
|
+
# :clip_id - The id of the clip (default: nil).
|
10
18
|
#
|
11
19
|
# Returns an Array of Hashie::Mash.
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
unless opts[:category_id].to_s.empty?
|
16
|
-
url += "/#{opts[:category_id]}"
|
17
|
-
end
|
18
|
-
|
19
|
-
url += '/clips'
|
20
|
-
|
21
|
-
unless opts[:clip_id].to_s.empty?
|
22
|
-
url += "/#{opts[:clip_id]}"
|
23
|
-
end
|
24
|
-
|
25
|
-
get(url, opts)
|
20
|
+
def videos(channel_id, opts={})
|
21
|
+
pattern = "video/channels/#{channel_id}/clips/:clip_id"
|
22
|
+
get(pattern, opts).channels
|
26
23
|
end
|
27
24
|
|
28
25
|
end
|
data/lib/espn/configuration.rb
CHANGED
@@ -14,9 +14,30 @@ module ESPN
|
|
14
14
|
module Configuration
|
15
15
|
|
16
16
|
# Public: Array of all configuration options for an ESPN::Client.
|
17
|
-
VALID_OPTIONS_KEYS = [:adapter, :api_version, :
|
17
|
+
VALID_OPTIONS_KEYS = [:adapter, :api_version, :api_key, :proxy, :timeout,
|
18
18
|
:open_timeout, :user_agent].freeze
|
19
19
|
|
20
|
+
# Public: Gets/Sets the Symbol adapter.
|
21
|
+
attr_accessor :adapter
|
22
|
+
|
23
|
+
# Public: Gets/Sets the Fixnum api version.
|
24
|
+
attr_accessor :api_version
|
25
|
+
|
26
|
+
# Public: Gets/Sets the String api key.
|
27
|
+
attr_accessor :api_key
|
28
|
+
|
29
|
+
# Public: Gets/Sets the Fixnum open timeout.
|
30
|
+
attr_accessor :open_timeout
|
31
|
+
|
32
|
+
# Public: Gets/Sets the String proxy.
|
33
|
+
attr_accessor :proxy
|
34
|
+
|
35
|
+
# Public: Gets/Sets the Fixnum timeout.
|
36
|
+
attr_accessor :timeout
|
37
|
+
|
38
|
+
# Public: Gets/Sets the String user agent.
|
39
|
+
attr_accessor :user_agent
|
40
|
+
|
20
41
|
# Public: The default adapter used for requests.
|
21
42
|
DEFAULT_ADAPTER = Faraday.default_adapter
|
22
43
|
|
@@ -29,10 +50,6 @@ module ESPN
|
|
29
50
|
# Public: The default timeout for HTTP Requests.
|
30
51
|
DEFAULT_TIMEOUT = 10
|
31
52
|
|
32
|
-
# Public: Create an attr_accessor for each VALID_OPTIONS_KEYS when this
|
33
|
-
# module is extended into another.
|
34
|
-
attr_accessor(*VALID_OPTIONS_KEYS)
|
35
|
-
|
36
53
|
# Internal: Hook when this module is extended in another, we call #reset.
|
37
54
|
#
|
38
55
|
# Returns nothing.
|
@@ -64,13 +81,13 @@ module ESPN
|
|
64
81
|
#
|
65
82
|
# Returns nothing.
|
66
83
|
def reset
|
67
|
-
self.adapter
|
68
|
-
self.api_version
|
69
|
-
self.user_agent
|
70
|
-
self.timeout
|
71
|
-
self.open_timeout
|
72
|
-
self.api_key
|
73
|
-
self.proxy
|
84
|
+
self.adapter = DEFAULT_ADAPTER
|
85
|
+
self.api_version = DEFAULT_API_VERSION
|
86
|
+
self.user_agent = DEFAULT_USER_AGENT
|
87
|
+
self.timeout = DEFAULT_TIMEOUT
|
88
|
+
self.open_timeout = DEFAULT_TIMEOUT
|
89
|
+
self.api_key = nil
|
90
|
+
self.proxy = nil
|
74
91
|
end
|
75
92
|
end
|
76
93
|
end
|