lib/kentaa/api/response.rb in kentaa-api-0.3.2 vs lib/kentaa/api/response.rb in kentaa-api-0.4.0
- old
+ new
@@ -7,15 +7,15 @@
class Response
attr_reader :response, :body
def initialize(response)
@response = response
- @body = parse_body(response.body)
+ @body = response.body ? parse_body(response.body) : {}
end
def success?
- (http_code == 200 || http_code == 201) && !message
+ (http_code == 200 || http_code == 201 || http_code == 204) && !message
end
def error?
!success?
end
@@ -28,9 +28,23 @@
response.uri
end
def message
body[:message]
+ end
+
+ def errors
+ @errors ||= begin
+ errors = []
+
+ if body[:errors]
+ body[:errors].each do |error|
+ errors << Kentaa::Api::Resources::Error.new(error)
+ end
+ end
+
+ errors
+ end
end
private
def parse_body(body)