Class: CongregaPlenum::HttpAdapter
- Inherits:
-
Object
- Object
- CongregaPlenum::HttpAdapter
- Defined in:
- lib/adapters/http_adapter.rb
Overview
Encapsulates Net::HTTP details and shared configuration. Centralising the HTTP wiring keeps the client implementation focused on retries and parsing.
Instance Method Summary collapse
-
#get(url) ⇒ Object
Executes a GET request and returns the raw Net::HTTPResponse.
-
#initialize(configuration: CongregaPlenum.configuration) ⇒ HttpAdapter
constructor
Creates a new adapter using the provided configuration.
Constructor Details
#initialize(configuration: CongregaPlenum.configuration) ⇒ HttpAdapter
Creates a new adapter using the provided configuration. Injecting the configuration makes it trivial to plug test doubles or tweak settings when using multiple clients simultaneously.
10 11 12 |
# File 'lib/adapters/http_adapter.rb', line 10 def initialize(configuration: CongregaPlenum.configuration) @configuration = configuration end |
Instance Method Details
#get(url) ⇒ Object
Executes a GET request and returns the raw Net::HTTPResponse. All network errors of interest are mapped to ConnectionError so upper layers can treat them uniformly.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/adapters/http_adapter.rb', line 17 def get(url) uri = URI(url) http = build_http_client(uri) request = build_http_request(uri) logger.debug("CongregaPlenum: Requisição GET para #{url}") http.request(request) rescue Timeout::Error, SocketError, Errno::ECONNRESET => e raise ConnectionError, "Connection failed for #{url}: #{e.}" end |