lib/translation.rb in habluhablu-0.4.0 vs lib/translation.rb in habluhablu-0.4.1

- old
+ new

@@ -23,22 +23,26 @@ @request["accept-encoding"] = "application/gzip" File.open("config/locales/api_key.txt", "a+") do |f| $KEY = f.read end if $KEY.length <= 2 || $KEY.nil? - @request["x-rapidapi-key"] = '069f34f2bamsha3ef70a3f7e20cap1dcfe9jsn2dcff8d20c4e' + @request["x-rapidapi-key"] = 'ef9f61b3d0mshb95dcad44627e7cp176d4bjsn8f4d9e2a1706' else @request["x-rapidapi-key"] = $KEY end @request["x-rapidapi-host"] = "google-translate1.p.rapidapi.com" @request.body = "q=#{@text}!&target=#{@target}&source=#{@source}" # Example "q=Hello%2C%20dear%2C%20friend!&target=es&source=en" end def response response = @http.request(@request) - content = JSON.parse(response.read_body)["data"]["translations"].first["translatedText"] + content = JSON.parse(response.read_body) + content = content["data"]["translations"].first["translatedText"] File.open("config/locales/#{@target}.yml", "a+") do |f| - f.write({ "Translation" => content }.to_yaml) + f.write({ "translation" => content.to_s }.to_yaml) end end end + +tr = Translation.new("Hi_there", "es") +tr.response