espn 0.0.2 → 0.1.1

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.
@@ -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=
@@ -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
- # Ruby Wrapper for the ESPN API
1
+ # ESPN
2
2
 
3
- ## Why?
3
+ Simply Ruby Wrapper for the ESPN Developer API.
4
4
 
5
- I have seen this halfway implemented a few times. My goal is to take over the `espn` gem name.
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
@@ -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 = `git ls-files -cd`.split("\n")
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
@@ -4,22 +4,32 @@ require 'espn/error'
4
4
 
5
5
  module ESPN
6
6
  extend Configuration
7
+
7
8
  class << self
8
- # Alias for ESPN::Client.new
9
+
10
+ # Public: An alias for ESPN::Client.new.
9
11
  #
10
- # @return [ESPN::Client]
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
@@ -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
- def initialize(options={})
12
- options = ESPN.options.merge(options)
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
- # Provides the URL for accessing the API
35
+ # Public: Get the base URL for accessing the ESPN API.
19
36
  #
20
- # @return [String]
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 an api_key has been set
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
- # @return [Boolean]
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