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.

See Also:

Attribute Summary

Method Summary

Methods included from Sofa::Mapping

included

Constructor Details

- (Show) initialize(id, options = {})

Returns a new instance of Show, loading and then mapping info from the TVRage API.

Parameters:

  • (String) id — The show_id as per the TVRage API

Options Hash (options):

  • (Boolean) :greedy N/A —Whether or not to eager load the Season and Episode info

Returns:

  • (Show) — a new instance of +Show+

Raises:

  • (RuntimeError)


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

Returns:

  • (Hash) — The full show info (including seasons and episodes)

See Also:



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.

Parameters:

  • (String) name — The name of the show to search for

Options Hash (options):

  • (Boolean) :greedy N/A —Whether or not to eager load the Season and Episode info

Returns:

  • (Show) — The show with id parsed from the Quickinfo search

Raises:

See Also:



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.

Parameters:

  • (String) sid — The show’s id

Returns:

  • (Hash) — The parsed XML

See Also:



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.

Parameters:

  • (String) sid — The show’s id

Returns:

  • (Hash) — The parsed XML

See Also:



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.

Parameters:

  • (String) sid — The show’s id

Returns:

  • (Hash) — The parsed XML

See Also:



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

Returns:

  • (Array) — 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

Returns:

  • (Array) — 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