lib/monday/response.rb in monday_ruby-0.2.0 vs lib/monday/response.rb in monday_ruby-0.3.0
- old
+ new
@@ -4,10 +4,13 @@
# Encapsulates the response that comes back from
# the Monday.com API.
#
# Returns status code, parsed body and headers.
class Response
+ ERROR_OBJECT_KEYS = %w[errors error_code error_message].freeze
+ private_constant :ERROR_OBJECT_KEYS
+
attr_reader :status, :body, :headers
def initialize(response)
@response = response
@status = response.code.to_i
@@ -24,10 +27,10 @@
private
attr_reader :response
def errors?
- parse_body.key?("errors") || parse_body.key?("error_message")
+ (parse_body.keys & ERROR_OBJECT_KEYS).any?
end
def parse_body
JSON.parse(response.body)
end