Class: TmdbMovie
- Inherits:
-
Object
- Object
- TmdbMovie
- Defined in:
- lib/ruby-tmdb3/tmdb_movie.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.find(options) ⇒ Object
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 37 38 39 40 41 42 43 44 |
# File 'lib/ruby-tmdb3/tmdb_movie.rb', line 3 def self.find() = { :expand_results => true, :language => Tmdb.default_language }.merge() raise ArgumentError, "At least one of: id, title, imdb should be supplied" if([:id].nil? && [:title].nil? && [:imdb].nil?) results = [] unless([:id].nil? || [:id].to_s.empty?) results << Tmdb.api_call("movie", {:id => [:id].to_s}, [:language]) end unless([:title].nil? || [:title].to_s.empty?) data = {:query => [:title].to_s} unless [:year].nil? data[:year] = [:year].to_s end api_return = Tmdb.api_call("search/movie", data, [:language]) results << api_return["results"] if api_return end unless([:imdb].nil? || [:imdb].to_s.empty?) results << Tmdb.api_call("movie", {:id => [:imdb].to_s}, [:language]) [:expand_results] = true end results.flatten!(1) results.uniq! results.delete_if &:nil? unless([:limit].nil?) raise ArgumentError, ":limit must be an integer greater than 0" unless([:limit].is_a?(Fixnum) && [:limit] > 0) results = results.slice(0, [:limit]) end results.map!{|m| TmdbMovie.new(m, [:expand_results], [:language])} if(results.length == 1) return results.first else return results end end |
.new(raw_data, expand_results = false, language = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ruby-tmdb3/tmdb_movie.rb', line 46 def self.new(raw_data, = 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( && (!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? || @trailers_data.nil? end end return Tmdb.data_to_object(raw_data) end |
Instance Method Details
#==(other) ⇒ Object
70 71 72 73 |
# File 'lib/ruby-tmdb3/tmdb_movie.rb', line 70 def ==(other) return false unless(other.is_a?(TmdbMovie)) return @raw_data == other.raw_data end |