Class: Io::Flow::V0::HttpClient::DefaultHttpHandlerInstance
- Inherits:
-
HttpHandlerInstance
- Object
- HttpHandlerInstance
- Io::Flow::V0::HttpClient::DefaultHttpHandlerInstance
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#configure_ssl ⇒ Object
Called to configure SSL if the base uri requires it.
- #execute(request) ⇒ Object
- #full_uri(path) ⇒ Object
-
#initialize(base_uri) ⇒ DefaultHttpHandlerInstance
constructor
A new instance of DefaultHttpHandlerInstance.
Constructor Details
#initialize(base_uri) ⇒ DefaultHttpHandlerInstance
Returns a new instance of DefaultHttpHandlerInstance.
73095 73096 73097 73098 73099 73100 73101 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 73095 def initialize(base_uri) @base_uri = Preconditions.assert_class('base_uri', base_uri, URI) @client = Net::HTTP.new(@base_uri.host, @base_uri.port) if @base_uri.scheme == "https" configure_ssl end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
73093 73094 73095 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 73093 def client @client end |
Instance Method Details
#configure_ssl ⇒ Object
Called to configure SSL if the base uri requires it
73124 73125 73126 73127 73128 73129 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 73124 def configure_ssl @client.use_ssl = true @client.verify_mode = OpenSSL::SSL::VERIFY_PEER @client.cert_store = OpenSSL::X509::Store.new @client.cert_store.set_default_paths end |
#execute(request) ⇒ Object
73103 73104 73105 73106 73107 73108 73109 73110 73111 73112 73113 73114 73115 73116 73117 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 73103 def execute(request) response = begin @client.request(request) rescue SocketError => e raise StandardError.new("Error accessing uri[#{full_uri(request.path)}]: #{e}") end case response when Net::HTTPSuccess response.body else body = response.body rescue nil raise HttpClient::ServerError.new(response.code.to_i, response., :body => body, :uri => full_uri(request.path).to_s) end end |
#full_uri(path) ⇒ Object
73119 73120 73121 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 73119 def full_uri(path) path.start_with?(@base_uri.to_s) ? path : File.join(@base_uri.to_s, path) end |