Sha256: abf0bdf9eac117c95a8ce2501c56e19f4d50b2f1744e86ded6d44e1003d4ab46

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module Trackerific
  module Services
    module Concerns
      module XML
        extend ActiveSupport::Concern

        included do
          @xml_endpoint = ""
          @xml_parser = nil
          @xml_builder = nil
        end

        module ClassMethods
          attr_accessor :xml_endpoint
          attr_accessor :xml_parser
          attr_accessor :xml_builder
        end

        # Gets the tracking information for the package from the server
        # @param [String] id The package identifier
        # @return [Trackerific::Details] The tracking details
        # @api semipublic
        def track(id)
          response = self.class.xml_parser.new(id, http_response(id)).parse
          raise(response) if response.is_a?(Trackerific::Error)
          return response
        end

        protected

        def http_response(id)
          self.class.post(self.class.xml_endpoint, body: builder(id).xml)
        end

        def builder(id)
          members = self.class.xml_builder.members - [:package_id]
          credentials = @credentials.values_at(*members)
          credentials << id
          self.class.xml_builder.new(*credentials)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trackerific-0.7.2 lib/trackerific/services/concerns/xml.rb