module Nytimes module Movies class Review < Base attr_reader :nyt_movie_id, :display_title, :sort_name, :mpaa_rating, :byline, :headline, :summary_short, :publication_date, :opening_date, :dvd_release_date, \ :date_updated, :seo_name, :critics_pick, :thousand_best, :thumbnail, :link, :related_links, :critic alias :updated_on :date_updated alias :critics_pick? :critics_pick alias :thousand_best? :thousand_best alias :critic_name :byline alias :movie_title :display_title alias :review_title :headline BATCH_SIZE = 20 def initialize(params={}) params.each_pair do |k,v| instance_variable_set("@#{k}", v) end end class <:text - search movie title and indexed terms for the movie. To limit to exact matches, enclose parts of the query in single quotes. Otherwise, it will include include partial matches ("head words") as well as exact matches (e.g., president will match president, presidents and presidential). Multiple terms will be ORed together # * :critics_pick - set to true to only search movies that are designated critics picks. Should your tastes be more lowbrow, set to false to return movies that are specifically NOT critic's picks. To get all movies, don't send this parameter at all. # * :thousand_best - search only movies on the Times List of "Thousand Best Movies Ever Made". Set to false if you want to explicitly search movies not on the list. Omit if you want all movies. # * :dvd - if true, search only movies out on DVD. If false, movies not on DVD. Don't specify if you want all movies. # * :reviewer - search reviews made by a specific critic. The full-name or the SEO name can be used to specify the critic. # * :publication_date - when the review was published. This can be either a single Date or Time object or a range of Times (anything that responds to .first and .last). If you'd prefer, you can also pass in a "YYYY-MM-DD" string # * :opening_date - when the movie opened in theaters in the NY Metro area. See +:publication_date+ for argument times. # # In addition, you can also specify the following order and pagination values: # * :offset - a maximum of 20 result are returned for queries. To retrieve further pages, an offset from the first result can be specified. This must be a multiple of 20. So +20+ means results +21 - 40+ # * :page - as a convenience, page will calculate the offset for here. This is not an API parameter and is translated into an offset. # * :order - ordering for the results. The following four sorting options are available: :title (ascending), :publication_date, :opening_date, :dvd_release_date (most recent first). If you do not specify a sort order, the results will be ordered by closest match. # * :load_critics - if true, automatically load the Critic object for each record's reviewer. Note that this requires N additional API calls (where N is the unique number of critics in the result set) def find(in_params={}) params = {} if in_params[:text] params['query'] = in_params[:text] end params['thousand-best'] = boolean_to_query_arg(in_params[:thousand_best]) params['critics-pick'] = boolean_to_query_arg(in_params[:critics_pick]) params['dvd'] = boolean_to_query_arg(in_params[:dvd]) params['publication-date'] = date_to_query_arg(in_params[:publication_date]) params['opening-date'] = date_to_query_arg(in_params[:opening_date]) if in_params.has_key? :reviewer params['reviewer'] = Critic.escape_critic_name(in_params[:reviewer]) end params['offset'] = in_params[:offset] if in_params.has_key? :page params['offset'] = BATCH_SIZE * (in_params[:page] - 1) end if in_params.has_key? :order params['order'] = case in_params[:order] when :title, :publication_date, :opening_date, :dvd_release_date "by-#{in_params[:order].to_s.gsub('_', '-')}" else raise ArgumentError, "Order can only be :title, :publication_date, :opening_date, or :dvd_release_date" end end params.delete_if {|k, v| v.nil? } reply = invoke 'reviews/search', params out = ResultSet.new(params, reply, Review) if in_params[:load_critics] critics_hash = {} out.results.each do |r| name = r.byline if critics_hash.has_key? name critic = critics_hash[name] else critic = Critic.find_by_name(name) critics_hash[name] = critic end r.instance_variable_set '@critic', critic end end out end def find_by_type(params={}) end def find_by_reviewer(params={}) end end end end end