lib/ruby-tmdb3/tmdb_movie.rb in ruby-tmdb3-0.3.3 vs lib/ruby-tmdb3/tmdb_movie.rb in ruby-tmdb3-0.3.4
- old
+ new
@@ -11,11 +11,15 @@
results = []
unless(options[:id].nil? || options[:id].to_s.empty?)
results << Tmdb.api_call("movie", {:id => options[:id].to_s}, options[:language])
end
unless(options[:title].nil? || options[:title].to_s.empty?)
- api_return = Tmdb.api_call("search/movie", {:query => options[:title].to_s}, options[:language])
+ data = {:query => options[:title].to_s}
+ unless options[:year].nil?
+ data[:year] = options[:year].to_s
+ end
+ api_return = Tmdb.api_call("search/movie", data, options[:language])
results << api_return["results"] if api_return
end
unless(options[:imdb].nil? || options[:imdb].to_s.empty?)
results << Tmdb.api_call("movie", {:id => options[:imdb].to_s}, options[:language])
options[:expand_results] = true
@@ -40,23 +44,25 @@
end
def self.new(raw_data, expand_results = false, language = nil)
# expand the result by calling movie unless :expand_results is false or the data is already complete
# (as determined by checking for the posters property in the raw data)
- if(expand_results && (!raw_data.has_key?("posters") || !raw_data['releases'] || !raw_data['cast']))
+ if(expand_results && (!raw_data.has_key?("posters") || !raw_data['releases'] || !raw_data['cast'] || !raw_data['trailers']))
begin
movie_id = raw_data['id']
raw_data = Tmdb.api_call 'movie', { :id => movie_id }, language
@images_data = Tmdb.api_call("movie/images", {:id => movie_id}, language)
@releases_data = Tmdb.api_call('movie/releases', {:id => movie_id}, language)
@cast_data = Tmdb.api_call('movie/casts', {:id => movie_id}, language)
+ @trailers_data = Tmdb.api_call('movie/trailers', {:id => movie_id}, language)
raw_data['posters'] = @images_data['posters']
raw_data['backdrops'] = @images_data['backdrops']
raw_data['releases'] = @releases_data['countries']
raw_data['cast'] = @cast_data['cast']
raw_data['crew'] = @cast_data['crew']
+ raw_data['trailers'] = @trailers_data['youtube']
rescue => e
- raise ArgumentError, "Unable to fetch expanded infos for Movie ID: '#{movie_id}'" if @images_data.nil? || @releases_data.nil? || @cast_data.nil?
+ raise ArgumentError, "Unable to fetch expanded infos for Movie ID: '#{movie_id}'" if @images_data.nil? || @releases_data.nil? || @cast_data.nil? || @trailers_data.nil?
end
end
return Tmdb.data_to_object(raw_data)
end