Class: Zenrows::Hooks::Context Private
- Inherits:
-
Object
- Object
- Zenrows::Hooks::Context
- Defined in:
- lib/zenrows/hooks/context.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.
Builds context hashes for hook callbacks
Provides methods to create and enrich context objects passed to hooks. Handles parsing of ZenRows-specific response headers.
Constant Summary collapse
- ZENROWS_HEADERS =
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.
ZenRows response headers to parse
{ "Concurrency-Limit" => :concurrency_limit, "Concurrency-Remaining" => :concurrency_remaining, "X-Request-Cost" => :request_cost, "X-Request-Id" => :request_id, "Zr-Final-Url" => :final_url }.freeze
Class Method Summary collapse
-
.enrich_with_response(context, response) ⇒ Hash
private
Enrich context with response data.
-
.for_request(method:, url:, options:, backend:) ⇒ Hash
private
Build context for a request.
Class Method Details
.enrich_with_response(context, response) ⇒ 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.
Enrich context with response data
Adds timing information and parses ZenRows headers from response.
52 53 54 55 56 57 58 |
# File 'lib/zenrows/hooks/context.rb', line 52 def enrich_with_response(context, response) headers = extract_headers(response) context[:zenrows_headers] = parse_zenrows_headers(headers) context[:completed_at] = Process.clock_gettime(Process::CLOCK_MONOTONIC) context[:duration] = context[:completed_at] - context[:started_at] context end |
.for_request(method:, url:, options:, backend:) ⇒ 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.
Build context for a request
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/zenrows/hooks/context.rb', line 31 def for_request(method:, url:, options:, backend:) uri = parse_uri(url) { method: method, url: url, host: uri&.host, options: .dup.freeze, started_at: Process.clock_gettime(Process::CLOCK_MONOTONIC), backend: backend, zenrows_headers: {} } end |