Sha256: a750c1012973bbe546410c3f2673ed333926331a2c45fe6a3df0cb331554fa99

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

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

        included do
          @soap_track_operation = :track
          @soap_builder = nil
          @soap_parser = nil
          @soap_wsdl = ""
        end

        module ClassMethods
          attr_accessor :soap_track_operation
          attr_accessor :soap_builder
          attr_accessor :soap_parser
          attr_accessor :soap_wsdl
        end

        def track(id)
          operation = self.class.soap_track_operation
          request = client.call(operation, message: builder(id).hash)
          response = self.class.soap_parser.new(id, request).parse
          response.is_a?(Trackerific::Error) ? raise(response) : response
        end

        protected

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

        def client
          @client ||= Savon.client(
            convert_request_keys_to: :camelcase,
            wsdl: Trackerific::SOAP::WSDL.path(self.class.soap_wsdl))
        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/soap.rb