Class: Dinosaurus::Thesaurus

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

Class Method Summary collapse

Class Method Details

.lookup(word) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dinosaurus/thesaurus.rb', line 15

def self.lookup(word)
  return Dinosaurus::Results.new if word.blank?
  res = get(url_for(word))

  if res.code == 200
    json = JSON.parse(res.body)
    Dinosaurus::Results.new(json)  # Word does not exist.

  elsif res.code == 404
    Dinosaurus::Results.new
  else
    warning = "DINOSAURUS_WARNING: #{res.code}. WORD: #{word}."
    Logging.logger.warn(warning)
  end
end