Sha256: 8252a8337b84b41705387d8d98efa5fee480386bdfa92030be26b1b8e113eb28

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

module Trackerific
  module Parsers
    class FedEx < Parsers::Base
      protected

      def response_error
        @response_error ||= if highest_severity == 'ERROR'
          Trackerific::Error.new(notifications[:message])
        else
          false
        end
      end

      def summary
        nil
      end

      def events
        track_details.map do |detail|
          Trackerific::Event.new(parse_date(detail), nil, location(detail))
        end
      end

      private

      def location(detail)
        a = detail[:destination_address]
        "#{a[:city]}, #{a[:state_or_province_code]} #{a[:country_code]}"
      end

      def parse_date(detail)
        detail[:ship_timestamp]
      end

      def track_reply
        @response.hash[:envelope][:body][:track_reply]
      end

      def track_details
        @track_details ||= begin
          details = track_reply[:completed_track_details][:track_details]
          details.select do |d|
            d[:ship_timestamp].present? && d[:destination_address].present? &&
            d[:destination_address][:city].present? &&
            d[:destination_address][:state_or_province_code].present?
          end
        end
      end

      def highest_severity
        track_reply[:highest_severity]
      end

      def notifications
        track_reply[:notifications]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trackerific-0.7.2 lib/trackerific/parsers/fedex.rb