lib/nytimes_articles/article.rb in harrisj-nytimes-articles-0.3.0 vs lib/nytimes_articles/article.rb in harrisj-nytimes-articles-0.4.0
- old
+ new
@@ -28,10 +28,14 @@
# Facets that return multiple values
attr_reader :classifiers, :descriptions, :geo, :material_types, :organizations, :persons, :nytd_bylines, :nytd_descriptions, :nytd_geo, :nytd_organizations, :nytd_persons, :nytd_sections, :nytd_works_mentioned, :works_mentioned
alias :people :persons
alias :nytd_people :nytd_persons
+ alias :places :geo
+ alias :nytd_places :nytd_geo
+ alias :subjects :descriptions
+ alias :nytd_subjects :nytd_descriptions
##
# Create a new Article from hash arguments. You really don't need to call this as Article instances are automatically returned from the API
def initialize(params={})
params.each_pair do |k,v|
@@ -181,17 +185,18 @@
# The <tt>:facets</tt> argument can be used to specify up to 5 facet fields to be returned alongside the search that provide overall counts
# of how much each facet term appears in the search results. FIXME provide list of available facets as well as description of :nytd parameter.
#
# == ARTICLE FIELDS
#
- # The <tt>:fields</tt> parameter is used to indicate what fields are returned with each article from the search results. If not specified, only
- # the following fields are returned for each article: body, byline, date, title, and url. To return specific fields, any of the search fields
+ # The <tt>:fields</tt> parameter is used to indicate what fields are returned with each article from the search results. If not specified, all
+ # fields are returned. To return specific fields, any of the search fields
# from above can be explicitly specified in a comma-delimited list, as well as the additional display-only (not searchable) fields below (these
# are strings or symbols):
#
# * <tt>:all</tt> - return all fields for the article
# * <tt>:none</tt> - display only the facet breakdown and no article results
+ # * <tt>:basic</tt> - return only the body, byline, date, title, and url
# * <tt>:multimedia</tt> - return any related multimedia links for the article
# * <tt>:thumbnail</tt> - return information for a related thumbnail image (if the article has one)
# * <tt>:word_count</tt> - the word_count of the article.
def self.search(query, params={})
params = params.dup
@@ -224,13 +229,12 @@
return arg.strftime("%Y%m%d") if arg.respond_to? :strftime
raise ArgumentError, "Only a string or Date/Time object is allowed as a parameter to the #{field_name} input"
end
def self.facet_params(params, facet_name)
- return nil if params[facet_name].nil?
-
- params[facet_name].map {|f| Facet.new(facet_name, f, nil) }
+ #return nil if params[facet_name].nil?
+ params[facet_name] # .map {|f| Facet.new(facet_name, f, nil) }
end
def self.text_argument(field, argument)
arg = argument.dup
subquery = []
@@ -271,13 +275,13 @@
end
end
def self.add_fields_param(out_params, in_params)
case in_params[:fields]
- when nil
- # do nothing
- when :all
+ when nil, :all
out_params['fields'] = ALL_FIELDS.join(',')
+ when :basic
+ # do nothing, the API will return basic URLs
when :none
out_params['fields'] = ' '
unless out_params['facets']
out_params['facets'] = Facet::DEFAULT_RETURN_FACETS.join(',')
end
\ No newline at end of file