Class: Factorix::HTTP::Client
- Inherits:
-
Object
- Object
- Factorix::HTTP::Client
- Defined in:
- lib/factorix/http/client.rb
Overview
Low-level HTTP client using Net::HTTP
Responsibilities:
-
Create and configure Net::HTTP instances
-
Execute HTTP methods (GET, POST)
-
Handle redirects (up to MAX_REDIRECTS)
-
Parse response codes and raise appropriate errors
-
Stream reading/writing for large files
Instance Attribute Summary collapse
-
#masked_params ⇒ Array<String>
readonly
URL parameter names to mask in logs.
Instance Method Summary collapse
-
#get(uri, headers: {}) {|Net::HTTPResponse| ... } ⇒ Response
Execute a GET request.
-
#head(uri, headers: {}) ⇒ Response
Execute a HEAD request.
-
#initialize(masked_params: []) ⇒ Client
constructor
A new instance of Client.
-
#post(uri, body:, headers: {}, content_type: nil) ⇒ Response
Execute a POST request.
-
#request(method, uri, headers: {}, body: nil) {|Net::HTTPResponse| ... } ⇒ Response
Execute an HTTP request.
Constructor Details
#initialize(masked_params: []) ⇒ Client
Returns a new instance of Client.
27 28 29 30 |
# File 'lib/factorix/http/client.rb', line 27 def initialize(masked_params: [], **) super(**) @masked_params = masked_params.freeze end |
Instance Attribute Details
#masked_params ⇒ Array<String> (readonly)
Returns URL parameter names to mask in logs.
24 25 26 |
# File 'lib/factorix/http/client.rb', line 24 def masked_params @masked_params end |
Instance Method Details
#get(uri, headers: {}) {|Net::HTTPResponse| ... } ⇒ Response
Execute a GET request
59 |
# File 'lib/factorix/http/client.rb', line 59 def get(uri, headers: {}, &) = request(:get, uri, headers:, &) |
#head(uri, headers: {}) ⇒ Response
Execute a HEAD request
66 |
# File 'lib/factorix/http/client.rb', line 66 def head(uri, headers: {}) = request(:head, uri, headers:) |
#post(uri, body:, headers: {}, content_type: nil) ⇒ Response
Execute a POST request
75 76 77 78 |
# File 'lib/factorix/http/client.rb', line 75 def post(uri, body:, headers: {}, content_type: nil) headers = headers.merge("Content-Type" => content_type) if content_type request(:post, uri, body:, headers:) end |
#request(method, uri, headers: {}, body: nil) {|Net::HTTPResponse| ... } ⇒ Response
Execute an HTTP request
46 47 48 49 50 51 |
# File 'lib/factorix/http/client.rb', line 46 def request(method, uri, headers: {}, body: nil, &) raise URLError, "URL must be HTTPS" unless uri.is_a?(URI::HTTPS) logger.info("HTTP request", method: method.upcase, url: mask_credentials(uri)) perform_request(method, uri, redirect_count: 0, headers:, body:, &) end |