lib/active_merchant/lib/posts_data.rb in activemerchant-1.1.0 vs lib/active_merchant/lib/posts_data.rb in activemerchant-1.2.0
- old
+ new
@@ -1,30 +1,48 @@
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 self.class.ssl_strict
+ 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
- unless @options[:pem].blank?
+ if @options && !@options[:pem].blank?
http.cert = OpenSSL::X509::Certificate.new(@options[:pem])
- http.key = OpenSSL::PKey::RSA.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
-
- http.post(uri.path, data, headers).body
+
+ 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