Class: Sofa::TVRage::Show
- Inherits:
- Object
- Includes:
- HTTParty, Sofa::Mapping
- Defined in:
- lib/sofa/tvrage/show.rb
Overview
This class holds the XML information of a single Show as per the TVRage API. It’s also the root point for communicating with the API.
Attribute Summary
- - (Hash) greedy Stores all the info that was greedy-loaded.
Method Summary
- + (Show) by_name(name, options = {}) Finds the Show by name using TVRage’s Quickinfo API.
- + (Hash) episode_list(sid) Gets the episode list for a Show.
- + (Hash) full_info(sid) Gets the full show info (info + season list + episode list) for a Show.
- + (Hash) info(sid) Gets the info for a Show.
- - (Array) episode_list The list of episodes.
- - (Show) initialize(id, options = {}) Returns a new instance of Show, loading and then mapping info from the TVRage API.
- - (Array) season_list The list of seasons.
Methods included from Sofa::Mapping
Constructor Details
- (Show) initialize(id, options = {})
Returns a new instance of Show, loading and then mapping info from the TVRage API.
107 108 109 110 111 112 113 114 115 |
# File 'lib/sofa/tvrage/show.rb', line 107
def initialize(id, options = {})
raise RuntimeError.new("id is required") unless (@show_id = id)
klass = self.class
if options[:greedy]
update_with_mapping(@greedy = klass.full_info(@show_id))
else
update_with_mapping(klass.info(@show_id))
end
end
|
Attribute Details
- (Hash) greedy
Stores all the info that was greedy-loaded
101 102 103 |
# File 'lib/sofa/tvrage/show.rb', line 101
def greedy
@greedy
end
|
Method Details
+ (Show) by_name(name, options = {})
Finds the Show by name using TVRage’s Quickinfo API.
50 51 52 53 54 55 56 |
# File 'lib/sofa/tvrage/show.rb', line 50
def by_name(name, options = {})
html = get('/tools/quickinfo.php', :query => {:show => name}, :format => :html)
show_info = Crack::XML.parse(html)["pre"]
raise ShowNotFound unless show_info
id = show_info.split("\n").first.gsub(%r{^Show ID@}, '').strip
Show.new(id, options)
end
|
+ (Hash) episode_list(sid)
Gets the episode list for a Show.
38 39 40 41 |
# File 'lib/sofa/tvrage/show.rb', line 38
def episode_list(sid)
xml = get('/feeds/episode_list.php', :query => {:sid => sid})
xml["Show"]
end
|
+ (Hash) full_info(sid)
Gets the full show info (info + season list + episode list) for a Show.
28 29 30 31 |
# File 'lib/sofa/tvrage/show.rb', line 28
def full_info(sid)
xml = get('/feeds/full_show_info.php', :query => {:sid => sid})
xml["Show"]
end
|
+ (Hash) info(sid)
Gets the info for a Show.
18 19 20 21 |
# File 'lib/sofa/tvrage/show.rb', line 18
def info(sid)
xml = get('/feeds/showinfo.php', :query => {:sid => sid})
xml["Showinfo"]
end
|
- (Array) episode_list
The list of episodes
124 125 126 |
# File 'lib/sofa/tvrage/show.rb', line 124
def episode_list
season_list.map { |season| season.episodes }.flatten
end
|
- (Array) season_list
The list of seasons
118 119 120 121 |
# File 'lib/sofa/tvrage/show.rb', line 118
def season_list
update_with_mapping(self.class.episode_list(@show_id)) unless @season_list
@season_list
end
|