lib/check_mot/response.rb in check_mot-0.1.0 vs lib/check_mot/response.rb in check_mot-0.3.1
- old
+ new
@@ -5,34 +5,29 @@
@raw_response = raw_response
end
delegate :success?, :status, to: :raw_response
- def sanitized
- return unless success?
+ def raw
+ raw_response.body
+ end
- case parsed_response
- when Array
- parsed_response.map(&method(:transform))
- else
- transform(parsed_response)
- end
+ def validate
+ fail ResponseError.new(status, raw) unless success?
end
- def raw
- raw_response.body
+ protected
+
+ def parsed_response
+ @_parsed_response ||= JSON.parse(raw_response.body)
end
private
attr_reader :raw_response
def transform(response_hash)
response_hash.deep_transform_keys { |key| key.underscore.to_sym }
- end
-
- def parsed_response
- @_parsed_response ||= JSON.parse(raw_response.body)
end
end
end