Class: GoogleTts::Connector
- Inherits:
-
Object
- Object
- GoogleTts::Connector
- Defined in:
- lib/google_tts/connector.rb
Instance Method Summary collapse
- #get_contents(*paths) ⇒ Object
-
#initialize(http_connection = Net::HTTP) ⇒ Connector
constructor
A new instance of Connector.
- #raise_error(response) ⇒ Object
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 |