Class: Ilovepdf::Response
- Inherits:
-
Object
- Object
- Ilovepdf::Response
- Defined in:
- lib/ilovepdf/response.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
- #body ⇒ Object
- #code ⇒ Object
- #headers ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #raw_body ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
5 6 7 8 |
# File 'lib/ilovepdf/response.rb', line 5 def initialize(response) raise ArgumentError.new('Argument must be of type \'RestClient::Response\'') unless response.is_a? ::RestClient::Response self.response = response end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
3 4 5 |
# File 'lib/ilovepdf/response.rb', line 3 def response @response end |
Instance Method Details
#body ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/ilovepdf/response.rb', line 14 def body return @body if @body is_json = (/application\/json/i =~ self.response.headers[:content_type]) != nil if is_json @body ||= JSON.parse(self.response.body) else @body = self.response.body end end |
#code ⇒ Object
28 29 30 |
# File 'lib/ilovepdf/response.rb', line 28 def code self.response.code end |
#headers ⇒ Object
10 11 12 |
# File 'lib/ilovepdf/response.rb', line 10 def headers self.response.headers end |
#raw_body ⇒ Object
24 25 26 |
# File 'lib/ilovepdf/response.rb', line 24 def raw_body self.response.body end |
#success? ⇒ Boolean
32 33 34 |
# File 'lib/ilovepdf/response.rb', line 32 def success? self.response.code.to_s[0] == '2' end |