Class: GoogleLanguage

Inherits:
Object
  • Object
show all
Includes:
Typhoeus
Defined in:
lib/google_language.rb

Constant Summary collapse

URL =
'http://ajax.googleapis.com/ajax/services/language/translate'
API_VERSION =
'1.0'
DEBUG =
false
SUCCESS_HANDLER =
lambda do |response|
  puts response.inspect if DEBUG

  r = JSON.parse(response.body)
  d = r['responseData']
  s = r['responseStatus']
  raise GoogleLanguageError, r['responseDetails'] if d.nil?
  
  d['translatedText']
end
ERROR_HANDLER =
lambda do |response| 
  raise "Error: #{response.code}. Body #{response.body}"
end

Class Method Summary collapse

Class Method Details

.translate(text, options = {}) ⇒ Object



42
43
44
# File 'lib/google_language.rb', line 42

def translate(text, options = {})
  get_translate(:params => to_params(text, options)) 
end

.url(text, options = {}) ⇒ Object



38
39
40
# File 'lib/google_language.rb', line 38

def url(text, options = {})
  "#{URL}?#{to_uri(options)}"
end