Class: GoogleTts::Connector

Inherits:
Object
  • Object
show all
Defined in:
lib/google_tts/connector.rb

Instance Method Summary collapse

Constructor Details

#initialize(http_connection = Net::HTTP) ⇒ Connector

Returns a new instance of Connector.



7
8
9
# File 'lib/google_tts/connector.rb', line 7

def initialize(http_connection = Net::HTTP)
  @connection = http_connection
end

Instance Method Details

#get_contents(*paths) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/google_tts/connector.rb', line 11

def get_contents(*paths)
  begin
    http = @connection.start('translate.google.com') 

    result = paths.map do |path|
      response = http.get path
      raise_error(response) if response.code != "200"
      response.body
    end

    result

  ensure
    http.finish
  end

end

#raise_error(response) ⇒ Object



29
30
31
# File 'lib/google_tts/connector.rb', line 29

def raise_error(response)
  raise "Error: response code #{response.code} #{response.body}"
end