Sha256: f98d9d4d726661b24dc6be77a8d1b2aacd9d4ae75f0fa08be92b29dc5381d26d

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 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
        req      = new Ratis.config
        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

2 entries across 2 versions & 1 rubygems

Version Path
ratis-2.5.2.7 lib/ratis/request.rb
ratis-2.5.2.6 lib/ratis/request.rb