Sha256: e673091ecf0e9468ea71454b8dd27d22ad4ff62f4e6a7ca798dd8f8b677b800c

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

module NNEClient
  # @!visibility private
  class Request
    class << self
      def execute(command, &block)
        new(command).result_set(&block)
      end
    end

    def initialize(command)
      @command = command
    end

    def result_set(&block)
      retries = 3
      begin
        ResultSet.new(perform_request(&block))
      rescue HTTPClient::ReceiveTimeoutError => e
        retries -= 1
        retry if retries > 0
      rescue Net::HTTPRequestTimeOut => e
        retries -= 1
        retry if retries > 0
      end
    end

    private

    def perform_request(&block)
      client.request('wsdl', @command, request_attributes) do
        if false
          # Savon 0.9.5 does not support this
          soap.body do |xml|
            yield xml
          end
        else
          # So create a builder manually
          str = StringIO.new
          builder = Builder::XmlMarkup.new(:target => str)
          yield builder
          str.rewind
          soap.body = str.read
        end
      end
    end

    def request_attributes
      { "env:encodingStyle" => "http://schemas.xmlsoap.org/soap/encoding/" }
    end

    def client
      @client ||= Savon::Client.new do
        wsdl.document = File.expand_path("../../../wsdl/nne.wsdl", __FILE__)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nne_client-0.0.4 lib/nne_client/request.rb
nne_client-0.0.3 lib/nne_client/request.rb
nne_client-0.0.2 lib/nne_client/request.rb