Class: GeneratorLabs::Response
- Inherits:
-
Object
- Object
- GeneratorLabs::Response
- Defined in:
- lib/generatorlabs/response.rb
Overview
API response wrapper providing Hash-like access to response data and rate limit info.
Supports bracket notation (response) for backward compatibility with raw Hash returns, while also exposing rate_limit_info.
Instance Attribute Summary collapse
-
#rate_limit_info ⇒ RateLimitInfo?
readonly
Rate limit information from response headers.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Access response data by key (Hash-like access).
-
#dig(*keys) ⇒ Object
Dig into nested response data.
-
#initialize(data, rate_limit_info = nil) ⇒ Response
constructor
A new instance of Response.
-
#is_a?(klass) ⇒ Boolean
Check if the response data is a Hash (for type compatibility).
-
#key?(key) ⇒ Boolean
Check if a key exists in the response data.
-
#to_h ⇒ Hash
Convert to a plain Hash.
Constructor Details
#initialize(data, rate_limit_info = nil) ⇒ Response
Returns a new instance of Response.
23 24 25 26 |
# File 'lib/generatorlabs/response.rb', line 23 def initialize(data, rate_limit_info = nil) @data = data @rate_limit_info = rate_limit_info end |
Instance Attribute Details
#rate_limit_info ⇒ RateLimitInfo? (readonly)
Returns Rate limit information from response headers.
19 20 21 |
# File 'lib/generatorlabs/response.rb', line 19 def rate_limit_info @rate_limit_info end |
Instance Method Details
#[](key) ⇒ Object
Access response data by key (Hash-like access).
31 32 33 |
# File 'lib/generatorlabs/response.rb', line 31 def [](key) @data[key] end |
#dig(*keys) ⇒ Object
Dig into nested response data.
38 39 40 |
# File 'lib/generatorlabs/response.rb', line 38 def dig(*keys) @data.dig(*keys) end |
#is_a?(klass) ⇒ Boolean
Check if the response data is a Hash (for type compatibility).
58 59 60 |
# File 'lib/generatorlabs/response.rb', line 58 def is_a?(klass) klass == Hash ? true : super end |
#key?(key) ⇒ Boolean
Check if a key exists in the response data.
45 46 47 |
# File 'lib/generatorlabs/response.rb', line 45 def key?(key) @data.key?(key) end |
#to_h ⇒ Hash
Convert to a plain Hash.
51 52 53 |
# File 'lib/generatorlabs/response.rb', line 51 def to_h @data end |