Sha256: 69f3add94308ec15907a14751daee0fb3528064877c8167657d2d0b2b8ecfed5
Contents?: true
Size: 903 Bytes
Versions: 2
Compression:
Stored size: 903 Bytes
Contents
require 'digest' module Nytimes module Articles ## # The Query class represents a single query to the Article Search API. Supports # all of the named parameters to Article.search as accessor methods. # class Query FIELDS = [:only_facets, :except_facets, :begin_date, :end_date, :since, :before, :fee, :has_thumbnail, :facets, :fields, :query, :offset] + Article::TEXT_FIELDS.map(&:to_sym) FIELDS.each {|f| attr_accessor f} # Produce a hash which uniquely identifies this query def hash strs = FIELDS.collect {|f| "#{f}:#{send(f).inspect}"} Digest::SHA256.hexdigest(strs.join(' ')) end # Perform this query. Returns result of Article.search def perform params = {} FIELDS.each {|f| params[f] = send(f) unless send(f).nil?} Article.search(params) end end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
harrisj-nytimes-articles-0.3.0 | lib/nytimes_articles/query.rb |
taylorbarstow-nytimes-articles-0.2.1 | lib/nytimes_articles/query.rb |