Class: TVDBApi
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #get(path, query = nil, options = {}) ⇒ Object
- #get_episode_by_air_date(series_id, air_date, lang = @lang) ⇒ Object
- #get_retings_for_user(account_id, series_id = nil) ⇒ Object
- #get_series(series_name, lang = @lang) ⇒ Object
- #get_series_by_remote_id(type, id, lang = @lang) ⇒ Object
-
#initialize(api_key, opts = {}) ⇒ TVDBApi
constructor
A new instance of TVDBApi.
- #to_full(path) ⇒ Object
- #user_favorites(account_id, change = nil, series_id = nil) ⇒ Object
- #user_preferred_language(account_id) ⇒ Object
- #user_rating(account_id, item_type, item_id, rating) ⇒ Object
Constructor Details
#initialize(api_key, opts = {}) ⇒ TVDBApi
Returns a new instance of TVDBApi.
9 10 11 12 13 |
# File 'lib/tvdb_api.rb', line 9 def initialize(api_key,opts = {}) @lang = opts[:lang] || 'en' @api_key = api_key @tries = 3 end |
Instance Method Details
#[](*args) ⇒ Object
119 120 121 |
# File 'lib/tvdb_api.rb', line 119 def [](*args) get args end |
#get(path, query = nil, options = {}) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/tvdb_api.rb', line 99 def get(path,query=nil, ={}) if path.respond_to? :join path = path.join("/") end path = to_full path if query [:query] = query end ex = nil @tries.times do begin res = self.class.get(path,) return res rescue => e ex = e end end raise ex end |
#get_episode_by_air_date(series_id, air_date, lang = @lang) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tvdb_api.rb', line 29 def get_episode_by_air_date(series_id, air_date, lang = @lang) if air_date.respond_to? :to_time air_date = air_date.to_time end if air_date.respond_to? :strftime air_date = air_date.strftime('%F') end get 'GetEpisodeByAirDate.php', apikey: @api_key, language: lang, seriesid: series_id, airdate: air_date end |
#get_retings_for_user(account_id, series_id = nil) ⇒ Object
42 43 44 45 46 |
# File 'lib/tvdb_api.rb', line 42 def get_retings_for_user(account_id, series_id = nil) query = { apikey: @api_key, accountid: account_id } query[:seriesid] = series_id if series_id get 'GetRatingsForUser.php', query end |
#get_series(series_name, lang = @lang) ⇒ Object
15 16 17 |
# File 'lib/tvdb_api.rb', line 15 def get_series(series_name, lang = @lang) get 'GetSeries.php', seriesname: series_name, language: lang end |
#get_series_by_remote_id(type, id, lang = @lang) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/tvdb_api.rb', line 19 def get_series_by_remote_id(type, id, lang = @lang) query = {language: lang} case type when :imdb then query[:imdbid] = id when :zap2it then query[:zap2it] = id else raise "Invalid remote id type '#{type}'" end get 'GetSeriesByRemoteID.php', query end |
#to_full(path) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/tvdb_api.rb', line 71 def to_full(path) if path !~ /\.php$/ path = @api_key+'/'+path if path =~ /\/\d+(\/all)?\/?$/ path += '/' + @lang + '.xml' end if path =~ /(.*\/updates\/)(?!updates_)(.*)/ path = $1+"updates_"+$2 end if path =~ /\/[^\/\.]*$/ path += '.xml' end end if path[0] != '/' if path !~ /^?api\// path = '/api/'+path else path = '/' + path end end path end |
#user_favorites(account_id, change = nil, series_id = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tvdb_api.rb', line 52 def user_favorites(account_id, change = nil, series_id = nil) query = {accountid: account_id} if change if [:add,:remove].include?(change) && series_id query[:type] = change query[:seriesid] = series_id else raise ArgumentError.new("change may only be :add or :remove and series_id must be set if change is set") end end get 'User_Favorites.php', query end |
#user_preferred_language(account_id) ⇒ Object
48 49 50 |
# File 'lib/tvdb_api.rb', line 48 def user_preferred_language(account_id) get 'User_PreferredLanguage.php', accountid: account_id end |
#user_rating(account_id, item_type, item_id, rating) ⇒ Object
65 66 67 68 69 |
# File 'lib/tvdb_api.rb', line 65 def (account_id, item_type, item_id, ) get 'User_Rating.php', accountid: account_id, itemtype: item_type, itemid: itemid, rating: end |