Class: WhereTo::TVDB

Inherits:
Object
  • Object
show all
Defined in:
lib/where_to/tvdb.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ TVDB

Returns a new instance of TVDB.



8
9
10
11
12
# File 'lib/where_to/tvdb.rb', line 8

def initialize(params = {})
  load_values_from params
  @api_key = WhereTo.configuration.tvdb_api_key
  @db = TvdbParty::Search.new api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



6
7
8
# File 'lib/where_to/tvdb.rb', line 6

def api_key
  @api_key
end

#episode_numberObject

Returns the value of attribute episode_number.



5
6
7
# File 'lib/where_to/tvdb.rb', line 5

def episode_number
  @episode_number
end

#episode_titleObject

Returns the value of attribute episode_title.



5
6
7
# File 'lib/where_to/tvdb.rb', line 5

def episode_title
  @episode_title
end

#seasonObject

Returns the value of attribute season.



5
6
7
# File 'lib/where_to/tvdb.rb', line 5

def season
  @season
end

#season_airdateObject

Returns the value of attribute season_airdate.



5
6
7
# File 'lib/where_to/tvdb.rb', line 5

def season_airdate
  @season_airdate
end

#series_idObject

Returns the value of attribute series_id.



5
6
7
# File 'lib/where_to/tvdb.rb', line 5

def series_id
  @series_id
end

#series_titleObject

Returns the value of attribute series_title.



5
6
7
# File 'lib/where_to/tvdb.rb', line 5

def series_title
  @series_title
end

Instance Method Details

#lookup!Object

Probably split into lookup_season, lookup_episode (which lazy instantiate) and lookup_season!, lookup_episode! (which force db hit):w



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/where_to/tvdb.rb', line 16

def lookup!
  validate!
  results = @db.search(series_title).first unless series_id
  series  = @db.get_series_by_id (series_id || results['seriesid'])
  episode = series.get_episode season, episode_number
  raise "It doesn't look like the series #{series.name} has an episode #{episode_number} for season #{season}" unless episode
  @episode_title  = episode.name
  @season_airdate = episode.air_date.year 

  updated = {}
  updated[:episode_title]  = episode_title
  updated[:season_airdate] = season_airdate
  updated
rescue URI::InvalidURIError
  raise 'You need to configure your TVDB API key before looking up episode information'
end

#lookup_series(series_id) ⇒ Object



33
34
35
# File 'lib/where_to/tvdb.rb', line 33

def lookup_series(series_id)
  @db.get_series_by_id series_id 
end

#validate!Object



37
38
39
40
41
42
# File 'lib/where_to/tvdb.rb', line 37

def validate!
  raise 'A series title is required to lookup episode information' if series_title.nil? && series_id.nil?
  raise 'An episode number is required to lookup episode information' if episode_number.nil?
  raise 'A season number is required to lookup episode information' if season.nil?
  true
end