Class: TVdb::Client
- Inherits:
-
Object
- Object
- TVdb::Client
- Defined in:
- lib/tvdb/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#urls ⇒ Object
readonly
Returns the value of attribute urls.
Instance Method Summary collapse
- #get_serie_zip(id, lang = 'en') ⇒ Object
-
#initialize(api_key) ⇒ Client
constructor
A new instance of Client.
- #search(name, options = {}) ⇒ Object
- #serie_in_language(serie, lang) ⇒ Object
Constructor Details
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
3 4 5 |
# File 'lib/tvdb/client.rb', line 3 def api_key @api_key end |
#urls ⇒ Object (readonly)
Returns the value of attribute urls.
3 4 5 |
# File 'lib/tvdb/client.rb', line 3 def urls @urls end |
Instance Method Details
#get_serie_zip(id, lang = 'en') ⇒ Object
36 37 38 39 |
# File 'lib/tvdb/client.rb', line 36 def get_serie_zip(id, lang='en') zip_file = open_or_rescue(@urls[:serie_zip] % {:serie_id => id, :language => lang}) zip_file.nil? ? nil : Zip::ZipFile.new(zip_file.path) end |
#search(name, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tvdb/client.rb', line 10 def search(name, ={}) = {:lang => 'en', :match_mode => :all} = .merge() search_url = @urls[:get_series] % {:name => URI.escape(name), :language => [:lang]} doc = Hpricot(OpenURI.open_uri(search_url).read) ids = if [:match_mode] == :exact doc.search('series').select{|s| s.search('seriesname').inner_text == name }.collect{|e| e.search('id')}.map(&:inner_text) else doc.search('series').search('id').map(&:inner_text) end ids.map do |sid| get_serie_from_zip(sid, [:lang]) end.compact end |
#serie_in_language(serie, lang) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/tvdb/client.rb', line 29 def serie_in_language(serie, lang) return nil if !serie.respond_to?(:tvdb_id) return serie if lang == serie.language get_serie_from_zip(serie.tvdb_id, lang) end |