lib/google_translate/google_translate.rb in google-translate-1.0.0 vs lib/google_translate/google_translate.rb in google-translate-1.0.1

- old
+ new

@@ -29,11 +29,11 @@ end def say lang, text speech_content = call_speech_service(lang, text) - file = Tempfile.new('.google_translate_speech') + file = Tempfile.new('.google_translate_speech-') file.write(speech_content) file.close @@ -50,20 +50,10 @@ def speech_url(lang) "#{GOOGLE_TRANSLATE_SERVICE_URL}/translate_tts?tl=#{lang}&ie=UTF-8&oe=UTF-8" end - def call_service url, text=nil - uri = URI.parse(URI.escape(url)) - - http = Net::HTTP.new(uri.host, uri.port) - request = Net::HTTP::Post.new(uri.request_uri) - request.set_form_data(text: text) - - http.request(request) - end - def call_translate_service from_lang, to_lang, text url = translate_url(from_lang, to_lang) response = call_service url, text @@ -74,9 +64,19 @@ url = speech_url(lang) response = call_service url, text response.body + end + + def call_service url, text=nil + uri = URI.parse(URI.escape(url)) + + http = Net::HTTP.new(uri.host, uri.port) + request = Net::HTTP::Post.new(uri.request_uri) + request.set_form_data(text: text) + + http.request(request) end def collect_languages buffer, index, tag_name, tag_id languages = []