Sha256: 144f61f9f0b56f6af7eab8bcd3b456cf0b2cbcdd4ef8d33e88928eb8b0f5ba9e

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

module ActiveMerchant #:nodoc:
  class ConnectionError < ActiveMerchantError
  end
  
  module PostsData  #:nodoc:
    
    def self.included(base)
      base.class_inheritable_accessor :ssl_strict
      base.ssl_strict = true
      
      base.class_inheritable_accessor :pem_password
      base.pem_password = false
    end
    
    def ssl_post(url, data, headers = {})
      uri   = URI.parse(url)

      http = Net::HTTP.new(uri.host, uri.port) 
      http.use_ssl        = true
      
      if ssl_strict
        http.verify_mode    = OpenSSL::SSL::VERIFY_PEER
        http.ca_file        = File.dirname(__FILE__) + '/../../certs/cacert.pem'
      else
        http.verify_mode    = OpenSSL::SSL::VERIFY_NONE
      end
      
      if @options && !@options[:pem].blank?
        http.cert           = OpenSSL::X509::Certificate.new(@options[:pem])
        
        if pem_password
          raise ArgumentError, "The private key requires a password" if @options[:pem_password].blank?
          http.key            = OpenSSL::PKey::RSA.new(@options[:pem], @options[:pem_password])
        else
          http.key            = OpenSSL::PKey::RSA.new(@options[:pem])
        end
      end

      begin
        http.post(uri.request_uri, data, headers).body
      rescue EOFError => e
        raise ConnectionError, "The remote server dropped the connection"
      rescue Errno::ECONNREFUSED => e
        raise ConnectionError, "The remote server refused the connection"
      end
    end    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activemerchant-1.2.0 lib/active_merchant/lib/posts_data.rb
activemerchant-1.2.1 lib/active_merchant/lib/posts_data.rb