Class: OFX::HTTPClient
- Inherits:
-
Object
- Object
- OFX::HTTPClient
- Defined in:
- lib/ofx/http/ofx_http_client.rb
Instance Method Summary collapse
-
#initialize(ofx_uri) ⇒ HTTPClient
constructor
A new instance of HTTPClient.
- #send(ofx_body, ssl_version = nil, do_print_request = false, do_print_response = false) ⇒ Object
Constructor Details
#initialize(ofx_uri) ⇒ HTTPClient
Returns a new instance of HTTPClient.
26 27 28 |
# File 'lib/ofx/http/ofx_http_client.rb', line 26 def initialize(ofx_uri) @ofx_uri = ofx_uri end |
Instance Method Details
#send(ofx_body, ssl_version = nil, do_print_request = false, do_print_response = false) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ofx/http/ofx_http_client.rb', line 30 def send(ofx_body, ssl_version=nil, do_print_request=false, do_print_response=false) http_request = Net::HTTP::Post.new(@ofx_uri.request_uri) http_request['User-Agent'] = "OFX for Ruby #{OFX::VERSION.to_dotted_s}" http_request['Content-Type'] = 'application/x-ofx' http_request['Accept'] = "*/*, application/x-ofx" http_request['Content-Length'] = ofx_body.length.to_s http_request.body = ofx_body.gsub("\n", "\r\n") if (do_print_request) print_request http_request end http = Net::HTTP.new(@ofx_uri.host, @ofx_uri.port) if (ssl_version) # supported in Ruby 1.9 or patched into 1.8 if (Net::HTTP.method_defined?(:ssl_version=)) http.ssl_version=ssl_version end end http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.ca_file = File.join(File.dirname(__FILE__), "cacert.pem") http.use_ssl = true http_response = http.start do |http| http.request(http_request) end case http_response when Net::HTTPSuccess print_response http_response if do_print_response http_response.body else print_response http_response http_response.error! end end |