Class: Wovnrb::ApiTranslator
- Inherits:
-
Object
- Object
- Wovnrb::ApiTranslator
- Defined in:
- lib/wovnrb/api_translator.rb
Instance Method Summary collapse
-
#initialize(store, headers) ⇒ ApiTranslator
constructor
A new instance of ApiTranslator.
- #translate(body) ⇒ Object
Constructor Details
#initialize(store, headers) ⇒ ApiTranslator
Returns a new instance of ApiTranslator.
8 9 10 11 |
# File 'lib/wovnrb/api_translator.rb', line 8 def initialize(store, headers) @store = store @headers = headers end |
Instance Method Details
#translate(body) ⇒ Object
13 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 |
# File 'lib/wovnrb/api_translator.rb', line 13 def translate(body) connection = prepare_connection request = prepare_request(body) begin response = connection.request(request) rescue => e WovnLogger.error("\"#{e.}\" error occurred when contacting WOVNio translation API") return body end case response when Net::HTTPSuccess if response.header['Content-Encoding'] == 'gzip' response_body = Zlib::GzipReader.new(StringIO.new(response.body)).read JSON.parse(response_body)['body'] || body else WovnLogger.error("Received invalid content (\"#{response.header['Content-Encoding']}\") from WOVNio translation API.") body end else WovnLogger.error("Received \"#{response.}\" from WOVNio translation API.") body end end |