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- 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) ⇒ 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) ⇒ 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.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nahook/http_client.rb', line 39 def initialize(token:, base_url: DEFAULT_BASE_URL, timeout_ms: DEFAULT_TIMEOUT_MS, retries: 0) @token = token @retries = retries @timeout_ms = timeout_ms timeout_secs = timeout_ms / 1000.0 @conn = Faraday.new(url: base_url.chomp("/")) do |f| f..timeout = timeout_secs f..open_timeout = timeout_secs f.adapter Faraday.default_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.
27 28 29 30 31 32 33 |
# File 'lib/nahook/http_client.rb', line 27 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.
62 63 64 |
# File 'lib/nahook/http_client.rb', line 62 def request(method:, path:, body: nil, query: nil) execute_with_retry(method, path, body, query) end |