Class: Html2rss::RequestService::BotasaurusContract::Success
- Inherits:
-
Object
- Object
- Html2rss::RequestService::BotasaurusContract::Success
- Defined in:
- lib/html2rss/request_service/botasaurus_contract.rb
Overview
Parsed OpenAPI ScrapeSuccess envelope (HTTP 200).
Constant Summary collapse
- MAX_XHR_BODY_BYTES =
Per-body size cap for captured XHR JSON (defense-in-depth vs upstream).
500_000- MAX_XHR_AGGREGATE_BYTES =
Aggregate size cap across all captured XHR bodies.
2_000_000
Instance Method Summary collapse
-
#final_url ⇒ String?
Final URL reported by upstream.
-
#headers ⇒ Hash{String => String}
Normalized response headers (null → {}).
-
#html ⇒ String
Rendered HTML body.
-
#initialize(payload:) ⇒ Success
constructor
A new instance of Success.
-
#status ⇒ Integer?
Document status_code when present.
-
#transport_meta ⇒ Hash{String => Object}
Diagnostics plus success-only metadata_error (frozen).
-
#xhr_responses ⇒ Array<Hash{String => Object}>
Size-capped XHR/fetch captures (absent → []).
Constructor Details
#initialize(payload:) ⇒ Success
Returns a new instance of Success.
59 60 61 62 63 |
# File 'lib/html2rss/request_service/botasaurus_contract.rb', line 59 def initialize(payload:) @payload = payload html diagnostics end |
Instance Method Details
#final_url ⇒ String?
Returns final URL reported by upstream.
88 |
# File 'lib/html2rss/request_service/botasaurus_contract.rb', line 88 def final_url = payload['final_url'] |
#headers ⇒ Hash{String => String}
Returns normalized response headers (null → {}).
74 75 76 77 78 79 |
# File 'lib/html2rss/request_service/botasaurus_contract.rb', line 74 def headers raw_headers = payload['headers'] return {} unless raw_headers.is_a?(Hash) && raw_headers.any? raw_headers.to_h { |key, value| [key.to_s, value.to_s] } end |
#html ⇒ String
Returns rendered HTML body.
66 67 68 69 70 71 |
# File 'lib/html2rss/request_service/botasaurus_contract.rb', line 66 def html value = payload['html'] raise BotasaurusServiceError, 'Botasaurus scrape success requires html' unless value.is_a?(String) value end |
#status ⇒ Integer?
Returns document status_code when present.
82 83 84 85 |
# File 'lib/html2rss/request_service/botasaurus_contract.rb', line 82 def status status_code = payload['status_code'] status_code.is_a?(Integer) ? status_code : nil end |
#transport_meta ⇒ Hash{String => Object}
Returns diagnostics plus success-only metadata_error (frozen).
91 92 93 94 95 |
# File 'lib/html2rss/request_service/botasaurus_contract.rb', line 91 def = diagnostics.dup ['metadata_error'] = if .freeze end |
#xhr_responses ⇒ Array<Hash{String => Object}>
Returns size-capped XHR/fetch captures (absent → []).
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/html2rss/request_service/botasaurus_contract.rb', line 98 def xhr_responses raw = payload['xhr_responses'] return [] unless raw.is_a?(Array) aggregate_bytes = 0 raw.filter_map do |entry| normalized = normalize_xhr_entry(entry) next unless normalized next unless (aggregate_bytes = advance_xhr_budget(normalized, aggregate_bytes)) normalized end end |