Class: TmdbMovie
- Inherits:
-
Object
- Object
- TmdbMovie
- Defined in:
- lib/ruby-tmdb/tmdb_movie.rb
Class Method Summary collapse
- .browse(options) ⇒ Object
- .find(options) ⇒ Object
- .new(raw_data, expand_results = false, language = nil) ⇒ Object
Instance Method Summary collapse
Class Method Details
.browse(options) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ruby-tmdb/tmdb_movie.rb', line 39 def self.browse() = { :expand_results => false }.merge() = .delete(:expand_results) language = .delete(:language) results = [] results << Tmdb.api_call("Movie.browse", , language) results.flatten! results.compact! results.map!{|m| TmdbMovie.new(m, , language) } if(results.length == 1) return results[0] else return results end end |
.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 |
# File 'lib/ruby-tmdb/tmdb_movie.rb', line 3 def self.find() = { :expand_results => true }.merge() raise ArgumentError, "At least one of: id, title, imdb should be supplied" if([:id].nil? && [:imdb].nil? && [:title].nil?) results = [] unless([:id].nil? || [:id].to_s.empty?) results << Tmdb.api_call("Movie.getInfo", [:id], [:language]) end unless([:imdb].nil? || [:imdb].to_s.empty?) results << Tmdb.api_call("Movie.imdbLookup", [:imdb], [:language]) [:expand_results] = true end unless([:title].nil? || [:title].to_s.empty?) results << Tmdb.api_call("Movie.search", [:title], [:language]) end results.flatten! results.compact! 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[0] else return results end end |
.new(raw_data, expand_results = false, language = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ruby-tmdb/tmdb_movie.rb', line 63 def self.new(raw_data, = false, language = nil) # expand the result by calling Movie.getInfo unless :expand_results is false or the data is already complete # (as determined by checking for the trailer property in the raw data) if( && !raw_data.has_key?("trailer")) = Tmdb.api_call('Movie.getInfo', raw_data["id"], language) raise ArgumentError, "Unable to fetch expanded info for Movie ID: '#{raw_data["id"]}'" if .nil? raw_data = .first end return Tmdb.data_to_object(raw_data) end |
Instance Method Details
#==(other) ⇒ Object
74 75 76 77 |
# File 'lib/ruby-tmdb/tmdb_movie.rb', line 74 def ==(other) return false unless(other.is_a?(TmdbMovie)) return @raw_data == other.raw_data end |