Class: TmdbMovie
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #alternative_titles ⇒ Object
- #fanarts ⇒ Object
- #idents ⇒ Object
- #image ⇒ Object
- #imdb_ids ⇒ Object
-
#initialize(ident, key, logger) ⇒ TmdbMovie
constructor
A new instance of TmdbMovie.
- #posters ⇒ Object
- #releases ⇒ Object
- #scores ⇒ Object
- #short_overviews ⇒ Object
- #titles ⇒ Object
- #to_hash ⇒ Object
- #to_xml ⇒ Object
- #to_yaml ⇒ Object
- #types ⇒ Object
- #urls ⇒ Object
Constructor Details
#initialize(ident, key, logger) ⇒ TmdbMovie
Returns a new instance of TmdbMovie.
5 6 7 8 9 10 |
# File 'lib/tmdb/tmdb_movie.rb', line 5 def initialize(ident, key, logger) @imdb_id = 'tt' + ident.gsub(/^tt/, '') unless ident.blank? @api_key = key @query = "http://api.themoviedb.org/2.0/Movie.imdbLookup?imdb_id=#{@imdb_id}&api_key=#{key}" @logger = OptionalLogger.new(logger) end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
3 4 5 |
# File 'lib/tmdb/tmdb_movie.rb', line 3 def query @query end |
Instance Method Details
#alternative_titles ⇒ Object
69 70 71 |
# File 'lib/tmdb/tmdb_movie.rb', line 69 def alternative_titles document['moviematches'].first['movie'].first['alternative_title'] rescue nil end |
#fanarts ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tmdb/tmdb_movie.rb', line 16 def fanarts result = [] begin document['moviematches'].each do |moviematches| moviematches['movie'].each do |movie| backdrop = movie['backdrop'] unless backdrop.blank? result += backdrop end end end rescue end result end |
#idents ⇒ Object
45 46 47 |
# File 'lib/tmdb/tmdb_movie.rb', line 45 def idents document['moviematches'].first['movie'].first['id'] rescue nil end |
#image ⇒ Object
12 13 14 |
# File 'lib/tmdb/tmdb_movie.rb', line 12 def image TmdbImage.new(@imdb_id.gsub(/^tt/, ''), @api_key, @logger) rescue nil end |
#imdb_ids ⇒ Object
53 54 55 |
# File 'lib/tmdb/tmdb_movie.rb', line 53 def imdb_ids document['moviematches'].first['movie'].first['imdb'] rescue nil end |
#posters ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/tmdb/tmdb_movie.rb', line 32 def posters result = [] begin document['moviematches'].each do |moviematches| moviematches['movie'].each do |movie| result += movie['poster'] end end rescue end result end |
#releases ⇒ Object
73 74 75 |
# File 'lib/tmdb/tmdb_movie.rb', line 73 def releases document['moviematches'].first['movie'].first['release'] rescue nil end |
#scores ⇒ Object
77 78 79 |
# File 'lib/tmdb/tmdb_movie.rb', line 77 def scores document['moviematches'].first['movie'].first['score'] rescue nil end |
#short_overviews ⇒ Object
61 62 63 |
# File 'lib/tmdb/tmdb_movie.rb', line 61 def short_overviews document['moviematches'].first['movie'].first['short_overview'] rescue nil end |
#titles ⇒ Object
57 58 59 |
# File 'lib/tmdb/tmdb_movie.rb', line 57 def titles document['moviematches'].first['movie'].first['title'] rescue nil end |
#to_hash ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/tmdb/tmdb_movie.rb', line 81 def to_hash hash = {} [:fanarts, :posters, :idents, :urls, :imdb_ids, :titles, :short_overviews, :types, :alternative_titles, :releases, :scores ].each do |sym| begin value = send(sym.to_s) hash[sym.to_s] = value unless value.nil? rescue Exception => e puts "Error getting data for hash for #{sym} - #{e.to_s}" end end hash end |
#to_xml ⇒ Object
96 97 98 |
# File 'lib/tmdb/tmdb_movie.rb', line 96 def to_xml XmlSimple.xml_out(document, 'NoAttr' => true, 'RootName' => 'movie') end |
#to_yaml ⇒ Object
100 101 102 |
# File 'lib/tmdb/tmdb_movie.rb', line 100 def to_yaml YAML.dump(document) end |
#types ⇒ Object
65 66 67 |
# File 'lib/tmdb/tmdb_movie.rb', line 65 def types document['moviematches'].first['movie'].first['type'] rescue nil end |
#urls ⇒ Object
49 50 51 |
# File 'lib/tmdb/tmdb_movie.rb', line 49 def urls document['moviematches'].first['movie'].first['url'] rescue nil end |