Sha256: b9353d21c148dc8ad2dcb2377d906b3de16810dfdb5124bb15559faf22231d08

Contents?: true

Size: 1.68 KB

Versions: 26

Compression:

Stored size: 1.68 KB

Contents

module Ratis

  class Request

    extend Savon::Model

    def initialize(config = nil)
      config = Ratis.config if config.nil?
      raise Errors::ConfigError('It appears that Ratis.configure has not been called') unless config.valid?
      
      self.class.client do
        wsdl.endpoint     = Ratis.config.endpoint
        wsdl.namespace    = Ratis.config.namespace
        http.proxy        = Ratis.config.proxy unless Ratis.config.proxy.blank?
        http.open_timeout = Ratis.config.timeout unless Ratis.config.timeout.blank?
      end
    rescue ArgumentError => e
      raise ArgumentError.new 'Invalid ATIS SOAP server configuration: ' + e.message
    end

    def self.get(action, params = {})
      begin
        raise Errors::ConfigError, 'It appears that Ratis.configure has not been called or properly setup' unless Ratis.config.valid?

        # ClassMethods from Savon::Model
        # Necessary since calling Ratis.configure doesn't allow changing of values set during Savon initialization
        # Savon memoizes the client config
        endpoint(Ratis.config.endpoint)
        namespace(Ratis.config.namespace)

        response = client.request action, :soap_action => "#{Ratis.config.namespace}##{action}", :xmlns => Ratis.config.namespace do
          soap.body = params unless params.blank?
        end

        # version = response.to_hash["#{action.downcase}_response".to_sym][:version]

        response
      rescue Errno::ECONNREFUSED => e
        raise Errno::ECONNREFUSED.new 'Refused request to ATIS SOAP server'
      rescue Savon::SOAP::Fault => e
        raise Errors::SoapError.new e
      rescue Timeout::Error => e
        raise "TIMEOUT!"
      end
    end

  end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
ratis-3.4.3 lib/ratis/request.rb
ratis-3.4.2 lib/ratis/request.rb
ratis-3.4.1 lib/ratis/request.rb
ratis-3.4.0 lib/ratis/request.rb
ratis-3.3.7 lib/ratis/request.rb
ratis-3.3.6 lib/ratis/request.rb
ratis-3.3.5 lib/ratis/request.rb
ratis-3.3.4 lib/ratis/request.rb
ratis-3.3.3 lib/ratis/request.rb
ratis-3.3.2 lib/ratis/request.rb
ratis-3.3.1 lib/ratis/request.rb
ratis-3.3.0 lib/ratis/request.rb
ratis-3.2.1 lib/ratis/request.rb
ratis-3.2.0 lib/ratis/request.rb
ratis-3.1.8 lib/ratis/request.rb
ratis-3.1.7 lib/ratis/request.rb
ratis-3.1.6 lib/ratis/request.rb
ratis-3.1.5.1 lib/ratis/request.rb
ratis-3.1.5 lib/ratis/request.rb
ratis-3.1.4 lib/ratis/request.rb