class TranslationIO::API::Response

Response represents a response from TranslationIO.

It is returned when using methods in Request. @see TranslationIO::API::Request

Attributes

raw_response[R]

Public Class Methods

new(response) click to toggle source

Constructor

@param response [Net::HTTPResponse] raw response from Net::HTTP

@return [TranslationIO::API::Response

# File lib/translation_io/api/response.rb, line 20
def initialize(response)
  @raw_response = response
end

Public Instance Methods

body() click to toggle source

Body of the response

@return [Hash] response body

# File lib/translation_io/api/response.rb, line 44
def body
  return {} if @raw_response.body.strip.empty?

  JSON.parse(@raw_response.body)
end
code() click to toggle source

Integer representing the HTTP response code

@return [Integer] HTTP response code

# File lib/translation_io/api/response.rb, line 36
def code
  Integer(@raw_response.code)
end
success?() click to toggle source

Was the response code 2xx

@return [Boolean]

# File lib/translation_io/api/response.rb, line 28
def success?
  @raw_response.is_a?(Net::HTTPSuccess)
end