Class: TmdbMovie

Inherits:
Object show all
Defined in:
lib/tmdb/tmdb_movie.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#queryObject (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_titlesObject



69
70
71
# File 'lib/tmdb/tmdb_movie.rb', line 69

def alternative_titles
  document['moviematches'].first['movie'].first['alternative_title']  rescue nil
end

#fanartsObject



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

#identsObject



45
46
47
# File 'lib/tmdb/tmdb_movie.rb', line 45

def idents
  document['moviematches'].first['movie'].first['id']  rescue nil
end

#imageObject



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_idsObject



53
54
55
# File 'lib/tmdb/tmdb_movie.rb', line 53

def imdb_ids
  document['moviematches'].first['movie'].first['imdb']  rescue nil
end

#postersObject



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

#releasesObject



73
74
75
# File 'lib/tmdb/tmdb_movie.rb', line 73

def releases
  document['moviematches'].first['movie'].first['release']  rescue nil
end

#scoresObject



77
78
79
# File 'lib/tmdb/tmdb_movie.rb', line 77

def scores
  document['moviematches'].first['movie'].first['score']  rescue nil
end

#short_overviewsObject



61
62
63
# File 'lib/tmdb/tmdb_movie.rb', line 61

def short_overviews
  document['moviematches'].first['movie'].first['short_overview']  rescue nil
end

#titlesObject



57
58
59
# File 'lib/tmdb/tmdb_movie.rb', line 57

def titles
  document['moviematches'].first['movie'].first['title']  rescue nil
end

#to_hashObject



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_xmlObject



96
97
98
# File 'lib/tmdb/tmdb_movie.rb', line 96

def to_xml
  XmlSimple.xml_out(document, 'NoAttr' => true, 'RootName' => 'movie')
end

#to_yamlObject



100
101
102
# File 'lib/tmdb/tmdb_movie.rb', line 100

def to_yaml
  YAML.dump(document)
end

#typesObject



65
66
67
# File 'lib/tmdb/tmdb_movie.rb', line 65

def types
  document['moviematches'].first['movie'].first['type']  rescue nil
end

#urlsObject



49
50
51
# File 'lib/tmdb/tmdb_movie.rb', line 49

def urls
  document['moviematches'].first['movie'].first['url']  rescue nil
end