Class: Nytimes::Articles::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/nytimes_articles/query.rb

Overview

The Query class represents a single query to the Article Search API. Supports all of the named parameters to Article.search as accessor methods.

Constant Summary collapse

FIELDS =
[:only_facets, :except_facets, :begin_date, :end_date, :since, 
:before, :fee, :has_thumbnail, :facets, :fields, :query, :offset] + Article::TEXT_FIELDS.map{|f| f.to_sym}

Instance Method Summary collapse

Instance Method Details

#hashObject

Produce a hash which uniquely identifies this query



15
16
17
18
# File 'lib/nytimes_articles/query.rb', line 15

def hash
  strs = FIELDS.collect {|f| "#{f}:#{send(f).inspect}"}
  Digest::SHA256.hexdigest(strs.join(' '))
end

#performObject

Perform this query. Returns result of Article.search



21
22
23
24
25
# File 'lib/nytimes_articles/query.rb', line 21

def perform
  params = {}
  FIELDS.each {|f| params[f] = send(f) unless send(f).nil?}
  Article.search(params)
end