lib/nytimes_articles/article.rb in harrisj-nytimes-articles-0.1.2 vs lib/nytimes_articles/article.rb in harrisj-nytimes-articles-0.1.3

- old
+ new

@@ -14,10 +14,12 @@ IMAGE_FIELDS = %w(small_image small_image_url small_image_height small_image_width) MULTIMEDIA_FIELDS = %w(multimedia related_multimedia) ALL_FIELDS = TEXT_FIELDS + RAW_FIELDS + NUMERIC_FIELDS + BOOLEAN_FIELDS + MULTIMEDIA_FIELDS + Facet::ALL_FACETS + IMAGE_FIELDS + EARLIEST_BEGIN_DATE = '19810101' + attr_reader *ALL_FIELDS # special additional objects attr_reader :thumbnail @@ -162,15 +164,17 @@ # # The following two search fields are used for facet searching: # * <tt>:only_facets</tt> - takes a single value or array of facets to search. Facets can either be specified as array pairs (like <tt>[Facet::GEOGRAPHIC, 'CALIFORNIA']</tt>) or facets returned from a previous search can be passed directly. A single string can be passed as well if you have hand-crafted string. # * <tt>:except_facets</tt> - similar to <tt>:only_facets</tt> but is used to specify a list of facets to exclude. # + # == TIME SEARCHES + # * <tt>:begin_date</tt>, <tt>:end_date</tt> - the parameters are used to specify a start and end date for search results. BOTH of these must be provided or the API will return an error. Accepts either a Time/Date argument or a string of the format YYYYMMDD. For convenience the following alternative methods are provided + # * <tt>:before</tt> - an alternative to :end_date. Automatically adds a :before_date of sometime in 1980 if no :since argument is also provided. + # * <tt>:since</tt> - An alternative to :begin_date. Automatically adds an :end_date of Time.now if no :before argument is provided. + # # == OTHER SEARCH FIELDS # * <tt>:fee</tt> - if set to true, only returns articles that must be purchased. If false, returns only free articles. If not specified, returns all articles - # * <tt>:begin_date</tt>, <tt>:end_date</tt> - the parameters are used to specify a start and end date for search results. BOTH of these must be provided or the API will return an error. Accepts either a Time/Date argument or a string of the format YYYYMMDD. For convenience the following alternative methods are provided - # * <tt>:before</tt> - an alternative to :end_date. Automatically adds a :before_date of sometime in 1980 if no :since argument is also provided; to be implemented - # * <tt>:since</tt> - An alternative to :begin_date. Automatically adds an :end_date of Time.now if no :before argument is provided; to be implemented. # * <tt>:has_thumbnail</tt> - returns only articles that have thumbnail images associated. Note that to see the thumbnails, you must specify either <tt>:thumbnail</tt> or <tt>:all</tt> in the <tt>:fields</tt> argument). # * <tt>:has_multimedia</tt> - to be implemented # # == FACET SUMMARIES # @@ -392,9 +396,33 @@ out_params['begin_date'] = date_argument(:begin_date, in_params[:begin_date]) end if in_params[:end_date] out_params['end_date'] = date_argument(:end_date, in_params[:end_date]) + end + + if in_params[:since] + if in_params[:begin_date] + raise ArgumentError, "You can't specify both :begin_date and :since as arguments" + end + + out_params['begin_date'] = date_argument(:since, in_params[:since]) + end + + if in_params[:before] + if in_params[:end_date] + raise ArgumentError, "You can't specify both :end_date and :before as arguments" + end + + out_params['end_date'] = date_argument(:before, in_params[:before]) + end + + if in_params[:before] && out_params['begin_date'].nil? + out_params['begin_date'] = EARLIEST_BEGIN_DATE + end + + if in_params[:since] && out_params['end_date'].nil? + out_params['end_date'] = date_argument(:end_date, Time.now) end end def self.add_offset_params(out_params, in_params) if in_params[:page] \ No newline at end of file