Class: Nahook::HttpClient Private
- Inherits:
-
Object
- Object
- Nahook::HttpClient
- Defined in:
- lib/nahook/http_client.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Low-level HTTP client used by both Client and Management.
Handles request execution, retry logic with exponential backoff, and error parsing. Not intended for direct use.
Constant Summary collapse
- DEFAULT_BASE_URL =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"https://api.nahook.com"- DEFAULT_TIMEOUT_MS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
30_000- BASE_DELAY_MS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
500- MAX_DELAY_MS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
10_000- DEFAULT_ADAPTER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The default Faraday adapter. ‘net_http_persistent` keeps a per-thread TCP/TLS pool so back-to-back requests skip the full handshake. Callers can override via the `adapter:` kwarg, or bypass adapter selection entirely by passing a pre-built `connection:`.
:net_http_persistent- REGION_BASE_URLS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ "us" => "https://us.api.nahook.com", "eu" => "https://eu.api.nahook.com", "ap" => "https://ap.api.nahook.com", }.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(token:, base_url: DEFAULT_BASE_URL, timeout_ms: DEFAULT_TIMEOUT_MS, retries: 0, adapter: DEFAULT_ADAPTER, connection: nil) ⇒ HttpClient
constructor
private
A new instance of HttpClient.
-
#request(method:, path:, body: nil, query: nil) ⇒ Hash?
private
Execute an HTTP request with optional retry logic.
Constructor Details
#initialize(token:, base_url: DEFAULT_BASE_URL, timeout_ms: DEFAULT_TIMEOUT_MS, retries: 0, adapter: DEFAULT_ADAPTER, connection: nil) ⇒ HttpClient
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of HttpClient.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/nahook/http_client.rb', line 55 def initialize(token:, base_url: DEFAULT_BASE_URL, timeout_ms: DEFAULT_TIMEOUT_MS, retries: 0, adapter: DEFAULT_ADAPTER, connection: nil) @token = token @retries = retries if connection @conn = connection # Prefer the supplied connection's own timeout so `TimeoutError` reports # the value the caller actually configured. Faraday options.timeout is # in seconds — convert. Fall back to the constructor kwarg if unset. conn_timeout_secs = connection..timeout @timeout_ms = conn_timeout_secs ? (conn_timeout_secs * 1000).to_i : timeout_ms else @timeout_ms = timeout_ms @conn = build_default_connection(base_url, timeout_ms, adapter) end end |
Class Method Details
.resolve_base_url(token) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 37 38 39 40 |
# File 'lib/nahook/http_client.rb', line 34 def self.resolve_base_url(token) if (m = token.match(/\Anhk_([a-z]{2})_/)) REGION_BASE_URLS[m[1]] || DEFAULT_BASE_URL else DEFAULT_BASE_URL end end |
Instance Method Details
#request(method:, path:, body: nil, query: nil) ⇒ Hash?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Execute an HTTP request with optional retry logic.
83 84 85 |
# File 'lib/nahook/http_client.rb', line 83 def request(method:, path:, body: nil, query: nil) execute_with_retry(method, path, body, query) end |