Class: GoogleWebTranslate::API

Inherits:
Object
  • Object
show all
Defined in:
lib/google_web_translate/api.rb

Overview

interface to the google web translation api

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ API

Returns a new instance of API.



7
8
9
10
11
12
13
# File 'lib/google_web_translate/api.rb', line 7

def initialize(options = {})
  @dt = options[:dt] || DEFAULT_DT
  @token_ttl = options[:token_ttl] || DEFAULT_TOKEN_TTL
  @debug = options[:debug]
  @http_client = options[:http_client] || HTTPClient.new(options)
  @rate_limit = options[:rate_limit] || DEFAULT_RATE_LIMIT
end

Instance Method Details

#languagesObject



20
21
22
23
24
25
# File 'lib/google_web_translate/api.rb', line 20

def languages
  @languages ||= begin
    html = fetch_main
    html.scan(/\['(\w{2})','(\w{2})'\]/).flatten.uniq.sort
  end
end

#translate(string, from, to) ⇒ Object



15
16
17
18
# File 'lib/google_web_translate/api.rb', line 15

def translate(string, from, to)
  data = fetch_translation(string, from, to)
  Result.new(data)
end