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-tmdb3/tmdb_cast.rb', line 3
def self.find(options)
options = {
:expand_results => true,
:language => Tmdb.default_language
}.merge(options)
raise ArgumentError, "At least one of: id, name, should be supplied" if(options[:id].nil? && options[:name].nil?)
results = []
unless(options[:id].nil? || options[:id].to_s.empty?)
results << Tmdb.api_call("person", {:id => options[:id].to_s}, options[:language])
end
unless(options[:name].nil? || options[:name].to_s.empty?)
api_return = Tmdb.api_call('search/person', {:query => options[:name].to_s}, options[:language])
results << api_return["results"] if api_return
end
results.flatten!(1)
results.uniq!
results.delete_if &:nil?
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!{|c| TmdbCast.new(c, options[:expand_results], options[:language])}
if(results.length == 1)
return results.first
else
return results
end
end
|