class MyData::ResponseParser
Attributes
original_response[R]
resource[R]
root[R]
Public Class Methods
new(response, resource: nil, root: nil)
click to toggle source
# File lib/my_data/response_parser.rb, line 4 def initialize(response, resource: nil, root: nil) @original_response = response @resource = resource @root = root end
Public Instance Methods
errors()
click to toggle source
# File lib/my_data/response_parser.rb, line 31 def errors @errors ||= if success? [] elsif response_type? response.response.map(&:errors).flatten else [MyData::Resources::ErrorType.new(JSON.parse(original_response.body))] end end
responded_at()
click to toggle source
# File lib/my_data/response_parser.rb, line 27 def responded_at @responded_at ||= Time.parse(original_response.headers["date"]) end
response()
click to toggle source
# File lib/my_data/response_parser.rb, line 42 def response return @response if defined? @response @response = if original_response.status == 200 MyData::XmlParser.xml_to_resource(xml: original_response.body, resource: resource, root: root) end end
status()
click to toggle source
# File lib/my_data/response_parser.rb, line 10 def status if success? :success elsif original_response.status == 401 :unauthorized elsif original_response.status == 400 :bad_request else :validation_error end end
success?()
click to toggle source
# File lib/my_data/response_parser.rb, line 22 def success? original_response.status == 200 && (!response_type? || response.response.all? { |r| r.status_code == "Success" }) end
Private Instance Methods
response_type?()
click to toggle source
# File lib/my_data/response_parser.rb, line 53 def response_type? response&.is_a?(MyData::Resources::Response) end