Class: TranslationIO::API::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/translation_io/api/response.rb

Overview

Response represents a response from TranslationIO.

It is returned when using methods in Request.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ TranslationIO::API::Response

Constructor

Parameters:

  • response (Net::HTTPResponse)

    raw response from Net::HTTP



20
21
22
# File 'lib/translation_io/api/response.rb', line 20

def initialize(response)
  @raw_response = response
end

Instance Attribute Details

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



12
13
14
# File 'lib/translation_io/api/response.rb', line 12

def raw_response
  @raw_response
end

Instance Method Details

#bodyHash

Body of the response

Returns:

  • (Hash)

    response body



44
45
46
47
48
# File 'lib/translation_io/api/response.rb', line 44

def body
  return {} if @raw_response.body.strip.empty?

  JSON.parse(@raw_response.body)
end

#codeInteger

Integer representing the HTTP response code

Returns:

  • (Integer)

    HTTP response code



36
37
38
# File 'lib/translation_io/api/response.rb', line 36

def code
  Integer(@raw_response.code)
end

#success?Boolean

Was the response code 2xx

Returns:

  • (Boolean)


28
29
30
# File 'lib/translation_io/api/response.rb', line 28

def success?
  @raw_response.is_a?(Net::HTTPSuccess)
end