rocketsofawesome/newgistics-ruby

View on GitHub
lib/newgistics/response_handlers/update_shipment_contents.rb

Summary

Maintainability
A
45 mins
Test Coverage
module Newgistics
  module ResponseHandlers
    class UpdateShipmentContents
      attr_reader :shipment

      def initialize(shipment)
        @shipment = shipment
      end

      def handle(response)
        PostErrors.new(shipment).handle(response)
        if shipment.errors.empty?
          handle_successful_response(response)
        end
      end

      private

      def handle_successful_response(response)
        xml = Nokogiri::XML(response.body)
        shipment.success = xml.at_css('success').text
      end
    end
  end
end