Class: TimesTags

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/times_tags.rb

Class Method Summary collapse

Class Method Details

.api_keyObject



9
10
11
# File 'lib/times_tags.rb', line 9

def self.api_key
  config['api_key']
end

.configObject



13
14
15
# File 'lib/times_tags.rb', line 13

def self.config
  @config ||= YAML::load_file(config_path)
end

.config_pathObject

Path to the times_topics.yml file.



18
19
20
21
22
23
24
25
# File 'lib/times_tags.rb', line 18

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

.config_path=(value) ⇒ Object



27
28
29
# File 'lib/times_tags.rb', line 27

def self.config_path= value
  @config_path = value
end

.geographic_search(name) ⇒ Object



39
40
41
# File 'lib/times_tags.rb', line 39

def self.geographic_search(name)
  get('/suggest', :query => { :query => name, :filter => '(Geo)', 'api-key' => api_key})
end

.organization_search(name) ⇒ Object



35
36
37
# File 'lib/times_tags.rb', line 35

def self.organization_search(name)
  get('/suggest', :query => { :query => name, :filter => '(Org)', 'api-key' => api_key})
end

.person_search(name) ⇒ Object



31
32
33
# File 'lib/times_tags.rb', line 31

def self.person_search(name)
  get('/suggest', :query => { :query => name, :filter => '(Per)', 'api-key' => api_key})
end

.search(query, type) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/times_tags.rb', line 47

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

.subject_search(name) ⇒ Object



43
44
45
# File 'lib/times_tags.rb', line 43

def self.subject_search(name)
  get('/suggest', :query => { :query => name, :filter => '(Des)', 'api-key' => api_key})
end