class Newgistics::ResponseHandlers::PostErrors

Attributes

model[R]

Public Class Methods

new(model) click to toggle source
# File lib/newgistics/response_handlers/post_errors.rb, line 6
def initialize(model)
  @model = model
end

Public Instance Methods

handle(response) click to toggle source
# File lib/newgistics/response_handlers/post_errors.rb, line 10
def handle(response)
  if response.success?
    handle_successful_response(response)
  else
    handle_failed_response(response)
  end
end

Private Instance Methods

error_nodes(xml) click to toggle source
# File lib/newgistics/response_handlers/post_errors.rb, line 31
def error_nodes(xml)
  xml.css('errors error') + xml.css('Errors Error')
end
handle_failed_response(response) click to toggle source
# File lib/newgistics/response_handlers/post_errors.rb, line 26
def handle_failed_response(response)
  message = "API Error: #{response.status}"
  model.errors << message
end
handle_successful_response(response) click to toggle source
# File lib/newgistics/response_handlers/post_errors.rb, line 20
def handle_successful_response(response)
  xml = Nokogiri::XML(response.body)
  model.errors = error_nodes(xml).map(&:text)
  model.warnings = warning_nodes(xml).map(&:text)
end
warning_nodes(xml) click to toggle source
# File lib/newgistics/response_handlers/post_errors.rb, line 35
def warning_nodes(xml)
  xml.css('warnings warning') + xml.css('Warnings warning')
end