Class: Pago::HTTP::NetHTTPAdapter
- Inherits:
-
Object
- Object
- Pago::HTTP::NetHTTPAdapter
- Defined in:
- lib/pago/http.rb
Overview
The default adapter, backed by the net/http standard library.
Instance Method Summary collapse
- #call(request) ⇒ Pago::HTTP::Response
-
#initialize(open_timeout: 10, read_timeout: 60) ⇒ NetHTTPAdapter
constructor
A new instance of NetHTTPAdapter.
Constructor Details
#initialize(open_timeout: 10, read_timeout: 60) ⇒ NetHTTPAdapter
Returns a new instance of NetHTTPAdapter.
31 32 33 34 |
# File 'lib/pago/http.rb', line 31 def initialize(open_timeout: 10, read_timeout: 60) @open_timeout = open_timeout @read_timeout = read_timeout end |
Instance Method Details
#call(request) ⇒ Pago::HTTP::Response
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pago/http.rb', line 38 def call(request) uri = URI.parse(request.url) net_request = build_request(uri, request) response = start(uri) { |http| http.request(net_request) } Response.new( status: response.code.to_i, headers: response.each_header.to_h, body: response.body || "" ) rescue Net::OpenTimeout, Net::ReadTimeout, Timeout::Error => e raise ::Pago::TimeoutError, "Pago API request timed out: #{e.}" rescue SocketError, SystemCallError, OpenSSL::SSL::SSLError, IOError, EOFError => e raise ::Pago::NetworkError, "Pago API network error: #{e.}" end |