3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/ruby-tmdb/tmdb_movie.rb', line 3
def self.find(options)
options = {
:expand_results => true
}.merge(options)
raise ArgumentError, "At least one of: id, title, imdb should be supplied" if(options[:id].nil? && options[:imdb].nil? && options[:title].nil?)
results = []
unless(options[:id].nil? || options[:id].to_s.empty?)
results << Tmdb.api_call("Movie.getInfo", options[:id])
end
unless(options[:imdb].nil? || options[:imdb].to_s.empty?)
results << Tmdb.api_call("Movie.imdbLookup", options[:imdb])
options[:expand_results] = true
end
unless(options[:title].nil? || options[:title].to_s.empty?)
results << Tmdb.api_call("Movie.search", options[:title])
end
results.flatten!
unless(options[:limit].nil?)
raise ArgumentError, ":limit must be an integer greater than 0" unless(options[:limit].is_a?(Fixnum) && options[:limit] > 0)
results = results.slice(0, options[:limit])
end
results.map!{|m| TmdbMovie.new(m, options[:expand_results]) }
if(results.length == 1)
return results[0]
else
return results
end
end
|