Class: SecApi::Client
- Inherits:
-
Object
- Object
- SecApi::Client
- Includes:
- CallbackHelper
- Defined in:
- lib/sec_api/client.rb
Overview
Client instances are thread-safe. All response objects are immutable (using Dry::Struct) and can be safely shared between threads.
Main entry point for interacting with the sec-api.io API.
The Client manages HTTP connections, configuration, and provides access to specialized proxy objects for different API endpoints. It uses a Client-Proxy architecture where the Client handles connection lifecycle and configuration, while proxy objects handle domain-specific operations.
Instance Method Summary collapse
-
#config ⇒ SecApi::Config
Returns the configuration object for this client.
-
#connection ⇒ Faraday::Connection
Returns the Faraday connection used for HTTP requests.
-
#extractor ⇒ SecApi::Extractor
Returns the Extractor proxy for document extraction functionality.
-
#initialize(config = Config.new) ⇒ SecApi::Client
constructor
Creates a new SEC API client.
-
#mapping ⇒ SecApi::Mapping
Returns the Mapping proxy for entity resolution functionality.
-
#query ⇒ SecApi::Query
Returns a fresh Query builder instance for constructing SEC filing searches.
-
#queued_requests ⇒ Integer
Returns the number of requests currently queued waiting for rate limit reset.
-
#rate_limit_state ⇒ RateLimitState?
Returns the current rate limit state from the most recent API response.
-
#rate_limit_summary ⇒ Hash
Returns a summary of the current rate limit state for debugging and monitoring.
-
#stream ⇒ SecApi::Stream
Returns the Stream proxy for real-time filing notifications via WebSocket.
-
#xbrl ⇒ SecApi::Xbrl
Returns the XBRL extraction proxy for accessing XBRL-to-JSON conversion functionality.
Methods included from CallbackHelper
Constructor Details
#initialize(config = Config.new) ⇒ SecApi::Client
Creates a new SEC API client.
84 85 86 87 88 89 90 |
# File 'lib/sec_api/client.rb', line 84 def initialize(config = Config.new) @_config = config @_config.validate! setup_default_logging if @_config.default_logging && @_config.logger setup_default_metrics if @_config.metrics_backend @_rate_limit_tracker = RateLimitTracker.new end |
Instance Method Details
#config ⇒ SecApi::Config
Returns the configuration object for this client.
101 102 103 |
# File 'lib/sec_api/client.rb', line 101 def config @_config end |
#connection ⇒ Faraday::Connection
In most cases, use the proxy objects (query, mapping, etc.) instead of making direct connection requests. The proxies provide type-safe response handling and a cleaner API.
Returns the Faraday connection used for HTTP requests.
The connection is lazily initialized on first access and includes the full middleware stack: JSON encoding/decoding, instrumentation, retry logic, rate limiting, and error handling.
121 122 123 |
# File 'lib/sec_api/client.rb', line 121 def connection @_connection ||= build_connection end |
#extractor ⇒ SecApi::Extractor
Returns the Extractor proxy for document extraction functionality.
Provides access to the sec-api.io document extraction API for extracting text and specific sections from SEC filings.
159 160 161 |
# File 'lib/sec_api/client.rb', line 159 def extractor @_extractor ||= Extractor.new(self) end |
#mapping ⇒ SecApi::Mapping
Returns the Mapping proxy for entity resolution functionality.
Provides access to the sec-api.io mapping API for resolving between different entity identifiers: ticker symbols, CIK numbers, CUSIP, and company names.
184 185 186 |
# File 'lib/sec_api/client.rb', line 184 def mapping @_mapping ||= Mapping.new(self) end |
#query ⇒ SecApi::Query
Returns a fresh Query builder instance for constructing SEC filing searches.
Unlike other proxy methods, this returns a NEW instance on each call to ensure query chains start with fresh state.
136 137 138 |
# File 'lib/sec_api/client.rb', line 136 def query Query.new(self) end |
#queued_requests ⇒ Integer
Returns the number of requests currently queued waiting for rate limit reset.
When the rate limit is exhausted (remaining = 0), incoming requests are queued until the rate limit window resets. This method returns the current count of waiting requests, useful for monitoring and debugging.
275 276 277 |
# File 'lib/sec_api/client.rb', line 275 def queued_requests @_rate_limit_tracker.queued_count end |
#rate_limit_state ⇒ RateLimitState?
Returns the current rate limit state from the most recent API response.
The state is automatically updated after each API request based on X-RateLimit-* headers returned by sec-api.io.
250 251 252 |
# File 'lib/sec_api/client.rb', line 250 def rate_limit_state @_rate_limit_tracker.current_state end |
#rate_limit_summary ⇒ Hash
Returns a summary of the current rate limit state for debugging and monitoring.
Provides a comprehensive view of the rate limit status in a single method call, useful for debugging, logging, and monitoring dashboards.
305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/sec_api/client.rb', line 305 def rate_limit_summary state = rate_limit_state { remaining: state&.remaining, limit: state&.limit, percentage: state&.percentage_remaining, reset_at: state&.reset_at, queued_count: queued_requests, exhausted: state&.exhausted? || false } end |
#stream ⇒ SecApi::Stream
The subscribe method blocks while receiving events. For non-blocking operation, run in a separate thread.
Returns the Stream proxy for real-time filing notifications via WebSocket.
217 218 219 |
# File 'lib/sec_api/client.rb', line 217 def stream @_stream ||= Stream.new(self) end |
#xbrl ⇒ SecApi::Xbrl
Returns the XBRL extraction proxy for accessing XBRL-to-JSON conversion functionality.
197 198 199 |
# File 'lib/sec_api/client.rb', line 197 def xbrl @_xbrl ||= Xbrl.new(self) end |