14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/wovnrb/api_translator.rb', line 14
def translate(body)
connection = prepare_connection
request = prepare_request(body)
begin
response = connection.request(request)
rescue => e
WovnLogger.error("\"#{e.message}\" error occurred when contacting WOVNio translation API")
return body
end
case response
when Net::HTTPSuccess
begin
raw_response_body = @store.dev_mode? ? response.body : Zlib::GzipReader.new(StringIO.new(response.body)).read
rescue Zlib::GzipFile::Error
raw_response_body = response.body
end
begin
JSON.parse(raw_response_body)['body'] || body
rescue JSON::JSONError
body
end
else
WovnLogger.error("HTML-swapper call failed. Received \"#{response.message}\" from WOVNio translation API.")
body
end
end
|