Module: Tvdb

Defined in:
lib/tvdb/ruby.rb,
lib/tvdb/ruby/version.rb,
lib/generators/tvdb/show.rb,
lib/generators/tvdb/episode.rb

Defined Under Namespace

Modules: Ruby Classes: Episode, Show

Class Method Summary collapse

Class Method Details

.harvest(apiKey, seriesId) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tvdb/ruby.rb', line 17

def harvest(apiKey, seriesId)
  url = "http://thetvdb.com/api/#{apiKey}/series/#{seriesId}/all/en.xml"
  doc = Nokogiri::HTML(open(url))

  show = Show.new(
      id: doc.css("id").text,
      name: doc.css("seriesname").text,
      airsDayOfWeek: doc.css("airs_dayofweek").text,
      airsTime: doc.css("airs_time").text,
      firstAired: doc.css("firstaired").text,
      genre: doc.css("genre").text,
      network: doc.css("network").text,
      overview: doc.css("overview").text,
      rating: doc.css("rating").text,
      ratingCount: doc.css("ratingcount").text,
      runtime: doc.css("runtime").text,
      status: doc.css("status").text,
      poster: doc.css("poster").text
  )

  doc.css("episode").each do |episode|
    show.epidosodes.new(
        seasonNumber: episode.css("seasonnumber").text,
        id: episode.css("episodenumber").text,
        name: episode.css("episodename").text,
        firstAired: episode.css("firstaired").text,
        overview: episode.css("overview").text
    )

  end

end

.initialize(apiKey, seriesName) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/tvdb/ruby.rb', line 7

def initialize(apiKey, seriesName)
  #apiKey = '9EF1D1E7D28FDA0B'
  #seriesName = 'Breaking+Bad'
  url = "http://thetvdb.com/api/GetSeries.php?seriesname=#{seriesName}"
  doc = Nokogiri::HTML(open(url))
  seriesId = doc.at_css("seriesid").text

  harvest(apiKey, seriesId)
end