Class: CoreLibrary::HttpCallContext
- Inherits:
-
HttpCallback
- Object
- HttpCallback
- CoreLibrary::HttpCallContext
- Defined in:
- lib/apimatic-core/http/http_call_context.rb
Overview
HttpCallContext is a callback class used to capture the HTTP request and response lifecycle during an API call. It is intended to be passed to an HTTP client or controller that supports pre- and post-request hooks.
This class stores references to the request and response objects, making them accessible after the API call is completed. This can be useful for debugging, logging, or validation purposes.
Example usage:
context = CoreLibrary::HttpCallContext.new
client.execute_request(request, context)
puts context.request # Inspect the HttpRequest
puts context.response # Inspect the HttpResponse
Instance Attribute Summary collapse
-
#request ⇒ HttpRequest?
readonly
The HTTP request object that was sent.
-
#response ⇒ HttpResponse?
readonly
The HTTP response object that was received.
Instance Method Summary collapse
-
#initialize(user_provided_http_callback = nil) ⇒ HttpCallContext
constructor
Initializes a new instance of HttpCallContext.
-
#on_after_response(response) ⇒ Object
Called after receiving the HTTP response.
-
#on_before_request(request) ⇒ Object
Called before making the HTTP request.
Constructor Details
#initialize(user_provided_http_callback = nil) ⇒ HttpCallContext
Initializes a new instance of HttpCallContext.
26 27 28 29 30 |
# File 'lib/apimatic-core/http/http_call_context.rb', line 26 def initialize(user_provided_http_callback = nil) @request = nil @response = nil @http_callback = user_provided_http_callback end |
Instance Attribute Details
#request ⇒ HttpRequest? (readonly)
Returns The HTTP request object that was sent.
17 18 19 |
# File 'lib/apimatic-core/http/http_call_context.rb', line 17 def request @request end |
#response ⇒ HttpResponse? (readonly)
Returns The HTTP response object that was received.
20 21 22 |
# File 'lib/apimatic-core/http/http_call_context.rb', line 20 def response @response end |
Instance Method Details
#on_after_response(response) ⇒ Object
Called after receiving the HTTP response. Stores the response and invokes the user-provided callback, if any.
45 46 47 48 |
# File 'lib/apimatic-core/http/http_call_context.rb', line 45 def on_after_response(response) @response = response @http_callback&.on_after_response(response) end |
#on_before_request(request) ⇒ Object
Called before making the HTTP request. Stores the request and invokes the user-provided callback, if any.
36 37 38 39 |
# File 'lib/apimatic-core/http/http_call_context.rb', line 36 def on_before_request(request) @request = request @http_callback&.on_before_request(request) end |