Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Update PostsData to support get requests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cody Fauser committed Mar 11, 2009
1 parent 3daf6e1 commit b700acf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
= ActiveMerchant CHANGELOG

* Update PostsData to support get requests [cody]
* Fix broken Quickpay remote test [cody]
* Update Quickpay gateway to v3. Add support for offsite integration for Danish Dankort cards [Lars Pind]
* Use default partner id when passed in :partner is blank with PayflowGateway [cody]
Expand Down
88 changes: 54 additions & 34 deletions lib/active_merchant/lib/posts_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,72 @@ def self.included(base)
base.read_timeout = READ_TIMEOUT
end

def ssl_get(url, headers={})
ssl_request(:get, url, nil, headers)
end

def ssl_post(url, data, headers = {})
# Ruby 1.8.4 doesn't automatically set this header
headers['Content-Type'] ||= "application/x-www-form-urlencoded"
ssl_request(:post, url, data, headers)
end

private
def retry_exceptions
retries = MAX_RETRIES
begin
yield
rescue RetriableConnectionError => e
retries -= 1
retry unless retries.zero?
raise ConnectionError, e.message
rescue ConnectionError
retries -= 1
retry if retry_safe && !retries.zero?
raise
end
end

def ssl_request(method, url, data, headers = {})
if method == :post
# Ruby 1.8.4 doesn't automatically set this header
headers['Content-Type'] ||= "application/x-www-form-urlencoded"
end

uri = URI.parse(url)

http = Net::HTTP.new(uri.host, uri.port)
http = Net::HTTP.new(uri.host, uri.port)
http.open_timeout = self.class.open_timeout
http.read_timeout = self.class.read_timeout
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 uri.scheme == "https"
http.use_ssl = true

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])
if ssl_strict
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.ca_file = File.dirname(__FILE__) + '/../../certs/cacert.pem'
else
http.key = OpenSSL::PKey::RSA.new(@options[:pem])
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
end

retry_exceptions do
begin
http.post(uri.request_uri, data, headers).body
case method
when :get
http.get(uri.request_uri, headers).body
when :post
http.post(uri.request_uri, data, headers).body
end
rescue EOFError => e
raise ConnectionError, "The remote server dropped the connection"
rescue Errno::ECONNRESET => e
Expand All @@ -69,21 +103,7 @@ def ssl_post(url, data, headers = {})
raise ConnectionError, "The connection to the remote server timed out"
end
end
end

def retry_exceptions
retries = MAX_RETRIES
begin
yield
rescue RetriableConnectionError => e
retries -= 1
retry unless retries.zero?
raise ConnectionError, e.message
rescue ConnectionError
retries -= 1
retry if retry_safe && !retries.zero?
raise
end
end

end
end
end

0 comments on commit b700acf

Please sign in to comment.