Class: TranslationIO::API::Response
- Inherits:
-
Object
- Object
- TranslationIO::API::Response
- Defined in:
- lib/translation_io/api/response.rb
Overview
Response represents a response from TranslationIO.
It is returned when using methods in Request.
Instance Attribute Summary collapse
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
Instance Method Summary collapse
-
#body ⇒ Hash
Body of the response.
-
#code ⇒ Integer
Integer representing the HTTP response code.
-
#initialize(response) ⇒ TranslationIO::API::Response
constructor
Constructor.
-
#success? ⇒ Boolean
Was the response code 2xx.
Constructor Details
#initialize(response) ⇒ TranslationIO::API::Response
Constructor
20 21 22 |
# File 'lib/translation_io/api/response.rb', line 20 def initialize(response) @raw_response = response end |
Instance Attribute Details
#raw_response ⇒ Object (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
#body ⇒ Hash
Body of the response
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 |
#code ⇒ Integer
Integer representing the 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
28 29 30 |
# File 'lib/translation_io/api/response.rb', line 28 def success? @raw_response.is_a?(Net::HTTPSuccess) end |