Sha256: b17b561928ea704b1077749f4066c1a43b2bc5473069dbd0506149e538068a29

Contents?: true

Size: 1.29 KB

Versions: 8

Compression:

Stored size: 1.29 KB

Contents

# coding: utf-8

require 'savon'

require 'libis/tools/xml_document'
require_relative 'http_error'
require_relative 'soap_error'

module Libis
  module Services

    module SoapClient
      attr_reader :client

      def configure(wsdl, options = {})
        opts = {
            wsdl: wsdl,
            raise_errors: false,
            soap_version: 1,
            filters: [:password],
            pretty_print_xml: true,
        }.merge options

        @client = Savon.client(opts) { yield if block_given? }
      end

      def operations
        @client.operations
      end

      def request(method, message = {}, call_options = {}, parse_options = {})
        response = client.call(method, message: message) do |locals|
          call_options.each do |key, value|
            locals.send(key, value)
          end
        end

        return yield(response) if block_given?
        parse_result(response, parse_options)
      end

      protected

      def parse_result(response, options = {})
        raise SoapError.new response.soap_fault.to_hash if response.soap_fault?
        raise HttpError.new response.http_error.to_hash if response.http_error?
        self.result_parser(response.body, options)
      end

      def result_parser(response, options = {})
        response
      end

    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
libis-services-0.1.7 lib/libis/services/soap_client.rb
libis-services-0.1.5 lib/libis/services/soap_client.rb
libis-services-0.1.3 lib/libis/services/soap_client.rb
libis-services-0.1.2 lib/libis/services/soap_client.rb
libis-services-0.1.1 lib/libis/services/soap_client.rb
libis-services-0.1.0-java lib/libis/services/soap_client.rb
libis-services-0.0.3 lib/libis/services/soap_client.rb
libis-services-0.0.2 lib/libis/services/soap_client.rb