class ProcessOut::Response
Attributes
body[R]
Public Class Methods
new(resp)
click to toggle source
# File lib/processout/networking/response.rb, line 14 def initialize(resp) @resp = resp @status = resp.code.to_i @body = JSON.parse(resp.body) self.check end
Public Instance Methods
code()
click to toggle source
Code returns the error code contained in the response, if any
# File lib/processout/networking/response.rb, line 30 def code if @body.include? "error_type" return @body["error_type"] end "" end
message()
click to toggle source
Message returns the error message contained in the response, if any
# File lib/processout/networking/response.rb, line 38 def message if @body.include? "message" return @body["message"] end "" end
success()
click to toggle source
Success returns whether or not the response returned a successful message
# File lib/processout/networking/response.rb, line 22 def success if @body.include? "success" return @body["success"] end false end
Protected Instance Methods
check()
click to toggle source
Check checks the response didn't contain any error, or raises an error if one was found
# File lib/processout/networking/response.rb, line 47 def check unless self.success if @status == 404 raise NotFoundError.new(self.code, self.message) end if @status == 401 raise AuthenticationError.new(self.code, self.message) end if @status == 400 raise ValidationError.new(self.code, self.message) end if @status >= 500 raise InternalError.new(self.code, self.message) end raise GenericError.new(self.code, self.message) end end