Sha256: eb3ea3203eb2a6ad61420aa5006832a95cb8abaa4ca39935aa37e7afad2b7f9e
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 KB
Contents
require 'httparty' class TimesTags include HTTParty base_uri "http://api.nytimes.com/svc/timestags" format :json def self.api_key config['api_key'] end def self.config @config ||= YAML::load_file(config_path) end # Path to the times_topics.yml file. def self.config_path if @config_path.nil? if defined?(Rails.env) @config_path = File.join(RAILS_ROOT, 'config', 'times_topics.yml') end end @config_path end def self.config_path= value @config_path = value end def self.person_search(name) get('/suggest', :query => { :query => name, :filter => '(Per)'}) end def self.organization_search(name) get('/suggest', :query => { :query => name, :filter => '(Org)'}) end def self.geographic_search(name) get('/suggest', :query => { :query => name, :filter => '(Geo)'}) end def self.subject_search(name) get('/suggest', :query => { :query => name, :filter => '(Des)'}) end def self.search(query, type) case type when /person/ person_search(query) when /organization/ organization_search(query) when /geographic/ geographic_search(query) when /subject|description/ subject_search(query) else person_search(query) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
times_topics-0.1.0 | lib/times_tags.rb |