Class: Sofa::TVRage::Show
- Inherits:
-
Object
- Object
- Sofa::TVRage::Show
- Includes:
- HTTParty, 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.
Defined Under Namespace
Classes: ShowNotFound
Instance Attribute Summary collapse
-
#greedy ⇒ Hash
Stores all the info that was greedy-loaded.
Class Method Summary collapse
-
.by_name(name, options = {}) ⇒ Show
Finds the Show by name using TVRage's Quickinfo API.
-
.episode_list(sid) ⇒ Hash
Gets the episode list for a Show.
-
.full_info(sid) ⇒ Hash
Gets the full show info (info + season list + episode list) for a Show.
-
.info(sid) ⇒ Hash
Gets the info for a Show.
-
.list ⇒ Hash
Gets the list of all shows.
Instance Method Summary collapse
-
#episode_list ⇒ Array
The list of episodes.
-
#initialize(id, options = {}) ⇒ Show
constructor
Returns a new instance of Show, loading and then mapping info from the TVRage API.
-
#season_list ⇒ Array
The list of seasons.
Methods included from Mapping
Constructor Details
#initialize(id, options = {}) ⇒ Show
Returns a new instance of Show, loading and then mapping info from the TVRage API.
116 117 118 119 120 121 122 123 124 |
# File 'lib/sofa/tvrage/show.rb', line 116
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
|
Instance Attribute Details
#greedy ⇒ Hash
Stores all the info that was greedy-loaded
110 111 112 |
# File 'lib/sofa/tvrage/show.rb', line 110
def greedy
@greedy
end
|
Class Method Details
.by_name(name, options = {}) ⇒ Show
Finds the Show by name using TVRage's Quickinfo API.
59 60 61 62 63 64 65 |
# File 'lib/sofa/tvrage/show.rb', line 59
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
|
.episode_list(sid) ⇒ Hash
Gets the episode list for a Show.
47 48 49 50 |
# File 'lib/sofa/tvrage/show.rb', line 47
def episode_list(sid)
xml = get('/feeds/episode_list.php', :query => {:sid => sid})
xml["Show"]
end
|
.full_info(sid) ⇒ Hash
Gets the full show info (info + season list + episode list) for a Show.
37 38 39 40 |
# File 'lib/sofa/tvrage/show.rb', line 37
def full_info(sid)
xml = get('/feeds/full_show_info.php', :query => {:sid => sid})
xml["Show"]
end
|
.info(sid) ⇒ Hash
Gets the info for a Show.
27 28 29 30 |
# File 'lib/sofa/tvrage/show.rb', line 27
def info(sid)
xml = get('/feeds/showinfo.php', :query => {:sid => sid})
xml["Showinfo"]
end
|
.list ⇒ Hash
Gets the list of all shows
17 18 19 20 |
# File 'lib/sofa/tvrage/show.rb', line 17
def list
xml = get('/feeds/show_list.php', query: {})
xml["shows"]['show']
end
|
Instance Method Details
#episode_list ⇒ Array
Returns The list of episodes.
133 134 135 |
# File 'lib/sofa/tvrage/show.rb', line 133
def episode_list
season_list.map { |season| season.episodes }.flatten
end
|
#season_list ⇒ Array
Returns The list of seasons.
127 128 129 130 |
# File 'lib/sofa/tvrage/show.rb', line 127
def season_list
update_with_mapping(self.class.episode_list(@show_id)) unless @season_list
@season_list
end
|