Module: ESPN::Client::Headlines
- Included in:
- ESPN::Client
- Defined in:
- lib/espn/client/headlines.rb
Instance Method Summary collapse
-
#headlines(opts = {}) ⇒ Object
Public: Get latest sports news and analysis from the ESPN API.
Instance Method Details
#headlines(opts = {}) ⇒ Object
Public: Get latest sports news and analysis from the ESPN API.
opts - Hash options used to refine the selection (default: {}).
- :section - The news section (default: 'sports').
- :sport - The name of the sport (default: nil).
- :league - The name of the league (default: nil).
- :method - The method of headlines (default: nil).
- :headline_id - The id of a specific headline (default: nil).
Returns an Array of Hashie::Mash.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/espn/client/headlines.rb', line 15 def headlines(opts={}) url = opts[:section] || 'sports' unless opts[:sport].to_s.empty? url += "/#{opts[:sport]}" unless opts[:league].to_s.empty? url += "/#{opts[:league]}" end end url += '/news' unless opts[:method].to_s.empty? url += "/headlines/#{opts[:method]}" end unless opts[:headline_id].to_s.empty? url += "/#{opts[:headline_id]}" end puts url get(url, opts) end |