Class: TheTVDB::Client
Instance Attribute Summary collapse
-
#apikey ⇒ Object
readonly
Returns the value of attribute apikey.
Instance Method Summary collapse
- #each(&block) ⇒ Object
- #get_episode_info(season, episode, options = {}) ⇒ Object
-
#initialize(apikey) ⇒ Client
constructor
A new instance of Client.
- #search(query, options = {}) ⇒ Object
- #seriesname ⇒ Object
Constructor Details
#initialize(apikey) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/thetvdb.rb', line 9 def initialize(apikey) @apikey = apikey @base_url = "http://www.thetvdb.com" @results = {} end |
Instance Attribute Details
#apikey ⇒ Object (readonly)
Returns the value of attribute apikey.
8 9 10 |
# File 'lib/thetvdb.rb', line 8 def apikey @apikey end |
Instance Method Details
#each(&block) ⇒ Object
35 36 37 |
# File 'lib/thetvdb.rb', line 35 def each(&block) @results.each(&block) end |
#get_episode_info(season, episode, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/thetvdb.rb', line 38 def get_episode_info(season, episode, = {}) = { lang: 'en' } = .merge() season = Integer(season) episode = Integer(episode) url = "#{@base_url}/api/#{@apikey}/series/#{@results[@pointer][:id]}/default/#{season}/#{episode}/#{[:lang]}.xml" doc = Nokogiri::XML(open(url)) showinfo = doc.xpath('//Episode').first result = { tvdb_id: showinfo.xpath('id').text, series_id: showinfo.xpath('seriesid').text, show: @results[@pointer][:name], season: season, episode: episode, name: showinfo.xpath('EpisodeName').text, first_aired: showinfo.xpath('FirstAired').text, director: showinfo.xpath('Director').text, overview: showinfo.xpath('Overview').text, imdb_id: showinfo.xpath('IMDB_ID').text, } result end |
#search(query, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/thetvdb.rb', line 14 def search(query, = {}) = { lang: 'en' } = .merge() query = URI.encode(query) search_url = "#{@base_url}/api/GetSeries.php?seriesname=#{query}&language=#{[:lang]}" doc = Nokogiri::XML(open(search_url)) @results = doc.xpath('//Series').map do |item| { id: item.xpath('seriesid').text, name: item.xpath('SeriesName').text, overview: item.xpath('Overview').text, } end @pointer = 0 @results end |
#seriesname ⇒ Object
30 31 32 33 34 |
# File 'lib/thetvdb.rb', line 30 def seriesname if @results.count > 0 then @results[@pointer][:name] end end |