From 406f329f1fe17899d57ef4e7a74c4144688ff3d7 Mon Sep 17 00:00:00 2001 From: Gil Desmarais Date: Tue, 24 Nov 2026 15:56:25 +0100 Subject: [PATCH 1/3] docs: add Ruby API reference, MCP details and network safeguards Add a Ruby API reference page with error handling, an apply example, MCP response cache and validation issue shapes, and a network safeguards section with troubleshooting entries. Co-Authored-By: Claude Opus 5.5 --- .../guides/capturing-feed-configs.mdx | 2 + .../ruby-gem/guides/managing-feed-configs.mdx | 23 ++ src/content/docs/ruby-gem/index.mdx | 2 +- .../docs/ruby-gem/reference/mcp-server.mdx | 44 +++- .../docs/ruby-gem/reference/ruby-api.mdx | 246 ++++++++++++++++++ .../docs/ruby-gem/reference/strategy.mdx | 15 ++ .../docs/troubleshooting/troubleshooting.mdx | 10 + 7 files changed, 329 insertions(+), 13 deletions(-) create mode 100644 src/content/docs/ruby-gem/reference/ruby-api.mdx diff --git a/src/content/docs/ruby-gem/guides/capturing-feed-configs.mdx b/src/content/docs/ruby-gem/guides/capturing-feed-configs.mdx index 3242e10d..9c825a6b 100644 --- a/src/content/docs/ruby-gem/guides/capturing-feed-configs.mdx +++ b/src/content/docs/ruby-gem/guides/capturing-feed-configs.mdx @@ -54,6 +54,8 @@ See the [CLI reference](/ruby-gem/reference/cli-reference/#capture) for the full ## Ruby API +All options and result types: [Ruby API Reference](/ruby-gem/reference/ruby-api/). + 12 + result.to_json_feed(feed_url: 'https://example.com/feeds/my-first-feed.json') + result.quality_report.warnings + # => [] +`} + lang="ruby" +/> + +The CLI exits 1 on an empty feed and the MCP tool returns `isError`; the Ruby method leaves that decision to you. Full method list: [Ruby API Reference](/ruby-gem/reference/ruby-api/#apply). + ### Command Line ` on the MCP process to change it. +- **Disable it** with `0`, `off` or `false`. An unusable value logs a warning and falls back to 300. +- Only initial 2xx fetches are cached. Follow-up requests and block pages always hit the network. +- Memory is bounded to 32 entries and 32 MiB of bodies; the oldest entry goes first. +- To force a refetch, wait out the TTL or restart with the cache off. +- The cache is an MCP server setting. The Ruby library and the CLI do not cache by default. + ## Client setup See [AI Agent Workflows](/ruby-gem/guides/ai-agent-workflows/) for Cursor / Claude Desktop `mcp.json` examples and the `html2rss-config` skill. diff --git a/src/content/docs/ruby-gem/reference/ruby-api.mdx b/src/content/docs/ruby-gem/reference/ruby-api.mdx new file mode 100644 index 00000000..4f5535f8 --- /dev/null +++ b/src/content/docs/ruby-gem/reference/ruby-api.mdx @@ -0,0 +1,246 @@ +--- +title: Ruby API Reference +description: Every public Html2rss method with signature, return type and examples, plus the error classes it raises. +--- + +import { Code } from "@astrojs/starlight/components"; + +All entry points are module methods on `Html2rss`. Options are keyword arguments. Method contracts in full: [YARD for `html2rss`](https://www.rubydoc.info/gems/html2rss). + +The curation verbs follow one path: `inspect`, `recon`, `capture`, `validate`, `test`, `apply`, plus `scrape` for one-shot extraction. The same verbs exist in the [CLI](/ruby-gem/reference/cli-reference/) and the [MCP server](/ruby-gem/reference/mcp-server/). + +## Overview + +| Method | Returns | +| -------------------------------------------------------------- | -------------------------------- | +| `Html2rss.inspect(url, strategy: :auto, deep: false)` | `PageRecon::Diagnostics::Report` | +| `Html2rss.recon(url, strategy: :auto)` | `Recon::Result` | +| `Html2rss.capture(url, strategy: :auto, **options)` | `Capture::CaptureResult` | +| `Html2rss.validate(config_input, feed_name = nil, params: {})` | `Config::ValidationReport` | +| `Html2rss.test(config_input, feed_name = nil, **options)` | `Test::Result` | +| `Html2rss.apply(raw_config)` | `Apply::Result` | +| `Html2rss.scrape(url, **options)` | `FeedResult` | +| `Html2rss.batch_scrape` / `batch_inspect` / `batch_recon` | `Batch::BatchResult` | +| `Html2rss.feed_result(raw_config)` | `FeedResult` | +| `Html2rss.feed(raw_config)` | `RSS::Rss` | +| `Html2rss.config_from_yaml_file(file, feed_name = nil)` | `Hash` | +| `Html2rss.schema_json(pretty: true)` | `String` | +| `Html2rss.configure` (block) | `Html2rss::Defaults` (frozen) | + +`strategy` is `:auto` (default), `:default` or `:botasaurus`. See [Strategy](/ruby-gem/reference/strategy/). + +## Curation verbs + +### `inspect` + +Cheap diagnostics for a URL: final URL, status, `rel=alternate` feeds, page surface. With `deep: true` and `strategy: :auto`, it makes one Botasaurus hop when Botasaurus is configured. + + + +### `recon` + +Adds a curation verdict (`build?`, `defer?`, `drop?`) and a native feed preference. `Recon::Result` carries `requested_url`, `final_url`, `status`, `verdict`, `native_feed`, `surface_category`, `articles_count`, `scheme_downgrade`, `notes` and `html_bytesize`. + + + +### `capture` + +Derives a reusable feed config from a URL. The result has `config` (Hash), `yaml` (String, with the schema modeline), `articles_count`, `channel_title`, `has_selectors`, `segment_strategy`, `selected_strategy`, `admission_drops`, `inferred_topics`, `native_feed`, `suggested_channel_url` and `candidates`. + +Options: + +- `items_selector` (CSS hint), `topics`, `title`, `summary`, `enhance` +- `force` (skip native feed detection) +- `limit`, `max_redirects`, `max_requests` +- `total_timeout_seconds` (positive Integer, default 30): bounds the whole request chain, including auto-fallback hops +- `local_file_path` (with `strategy: :local_file`) + +`candidates[:candidates_by_item]` lists title, link and date candidates for each of the top five item selectors. Details: [Capturing Feed Configs](/ruby-gem/guides/capturing-feed-configs/). + + + +### `validate` + +Schema-only check. `config_input` is a Hash, a YAML string or a file path. It does not fetch anything. + +`ValidationReport` responds to `success?`, `failure?`, `issues` and `to_h` (`{ success:, issues: }`). Each `ValidationIssue` has `path` (Array), `code`, `message`, `expected` and `actual`. `code` is one of `:missing_key`, `:type_mismatch`, `:unknown_value`, `:invalid_value`, `:constraint`, `:parse`. + + + +### `test` + +Validates the schema, then runs a live extraction and checks the result. + +Options: + +- `min_items` (default `1`, must be `>= 0`): fewer items fail the test +- `strict_quality` (default `false`): also fail on ship-quality audit thresholds +- `compare_enhance` (default `false`): diagnostic comparison of `enhance` off and on, using the cached HTML +- `sample_limit` (default `3`, must be `>= 0`): maximum number of `result.items` +- `params`: dynamic feed parameters; `strategy`: override the config's strategy + +`Test::Result` has `success`, `item_count`, `sample_items`, `items` (title, url, published_at, description, image, categories), `channel_title`, `channel_url`, `strategy_used`, `duration_seconds`, `validation_issues`, `error_message`, `failure_kind`, `rss`, `quality_report` and `enhance_compare`. `to_h` is the stable wire hash. On a schema failure, `validation_issues` holds the same `ValidationIssue` list as `validate`. + + + +### `apply` + +Builds the feed from a config Hash and returns an `Apply::Result`. This is the ship step. + +| Method | Returns | +| ----------------------------- | ---------------------------------------- | +| `to_rss` | the `RSS::Rss` document (built once) | +| `to_json_feed(feed_url: nil)` | JSON Feed 1.1 Hash | +| `empty?` | `true` when the feed has no items | +| `item_count` | number of items in the RSS document | +| `status` | `Html2rss::Status` scrape telemetry | +| `quality_report` | ship-quality audit of the rendered items | +| `feed_result` | the underlying `FeedResult` | + +`Html2rss.apply` does not raise on an empty feed. Check `empty?` yourself. The CLI exits 1 and the MCP tool returns `isError` on zero items. The result is not Marshal-cacheable; cache `feed_result` instead. + + + +## One-shot and batch + +### `scrape` + +Auto-source scrape from a URL, with no selectors. Returns a `FeedResult`. + +Options: `strategy`, `items_selector`, `max_redirects`, `max_requests` (default `4`), `local_file_path`, `limit` (default is the auto-source default), `keep_different_domain` and `keep_sponsored`. The last two override `auto_source.cleanup.*` when set. + + + +### `batch_scrape`, `batch_inspect`, `batch_recon` + +Run one verb over many URLs on a thread pool. Each URL is isolated: one failure does not stop the others. Results keep input order. + +- `urls`: the list of URLs +- `strategy`: default `:auto` +- `concurrency`: worker threads, `1..10`, default `5` +- `limit` (`batch_scrape` only): articles per URL, default `10` +- `cache_dir` (`batch_recon` only): optional HTML cache directory + +`Batch::BatchResult` has `total`, `successful` and `results`. + + + +## Building feeds + +### `feed_result` and `feed` + +`feed_result(raw_config)` runs the pipeline once and returns an opaque, Marshal-cacheable `FeedResult` (`to_rss`, `to_json_feed(feed_url:)`, `empty?`, `channel_title`, `status`). `feed(raw_config)` is `feed_result(raw_config).to_rss`. See [Managing Feed Configs](/ruby-gem/guides/managing-feed-configs/#ruby-api-feedresult). + +### `config_from_yaml_file` + +Loads a config Hash from a YAML file. Pass `feed_name` for a multi-feed file. + + + +### `schema_json` + +Returns the config JSON Schema as a String. `pretty: false` returns compact JSON. + +## Global defaults + +`Html2rss.configure` yields a copy of the defaults, then freezes it. Settings include `headers`, `stylesheets`, `logger` and `log_level`. See [Configuration](/ruby-gem/reference/configuration/). `default_strategy` and `min_ttl` were removed in 0.36.0 ([Backward Compatibility](/ruby-gem/guides/backward-compatibility/)). + +## Error handling + +Every error html2rss raises on purpose is an `Html2rss::Error`. Rescue that class, not `StandardError`. + + e + retry if e.retryable? && attempts < 3 + raise + end +`} + lang="ruby" +/> + +| Member | Meaning | +| -------------- | --------------------------------------------------------------------------------------------------------- | +| `#kind` | Stable failure class: `:timeout`, `:blocked`, `:connection`, `:invalid_url`, `:budget` or `:other` | +| `#retryable?` | `true` only for `:timeout` and `:connection`. Other kinds fail the same way again | +| `#diagnostics` | Sparse telemetry Hash (strategy attempts, transport metadata, timeout phase, surface category) when known | + +`#kind` and `#retryable?` exist since 0.34.0. Branch on them instead of on class names. + +Classes you will meet: + +- `Html2rss::InvalidOption`: a caller-supplied option is malformed or out of range, for example `min_items: -1` or a `concurrency` above 10. +- `Html2rss::Url::InvalidUrlError` (since 0.33.0): a string is not a valid URL. Its `kind` is `:invalid_url`. +- `Html2rss::RequestService::PrivateNetworkDenied`: the target is a private or local address. `kind` is `:blocked`. See [Network safeguards](/ruby-gem/reference/strategy/#network-safeguards). +- `Html2rss::RequestService::RequestTimedOut`: `kind` is `:timeout`. It may carry `timeout_phase`. +- `Html2rss::NoFeedItemsExtracted`: auto fallback tried every strategy and found no items. `attempts` lists each try. +- `Html2rss::ContractError`: a programmer error. Something was built from wrong parts, or a component broke its contract. It is a subclass of `Html2rss::Error`, but html2rss never swallows it in its own broad rescues. Fix the code rather than retrying. diff --git a/src/content/docs/ruby-gem/reference/strategy.mdx b/src/content/docs/ruby-gem/reference/strategy.mdx index c816ad5b..07023cef 100644 --- a/src/content/docs/ruby-gem/reference/strategy.mdx +++ b/src/content/docs/ruby-gem/reference/strategy.mdx @@ -35,6 +35,8 @@ Under `auto`, `Html2rss.feed_result(...).status` exposes scrape telemetry: `sele When no custom `User-Agent` header is supplied in `headers`, html2rss sends `html2rss/`. The shared request policy enforces redirect, request, timeout, and private-network safeguards and accepts supported compressed HTML responses. +Since 0.30.0 the default transport is HTTPX, which speaks HTTP/2 where the site offers it. Existing configs need no change. + ## `botasaurus` `botasaurus` delegates page fetching to the companion scrape API. `auto` can use it when configured; pin `strategy: botasaurus` only when you need browser-specific behavior. @@ -144,6 +146,19 @@ Because no remote network connection is established, `local_file` skips remote n lang="yml" /> +## Network safeguards + +Every strategy that makes network requests runs the same guard before it connects and again on the address it connected to. + +- **Private networks are denied.** Local hostnames, loopback, link-local, private (RFC 1918), unique-local and multicast addresses fail with `RequestService::PrivateNetworkDenied`. +- **Embedded IPv4 addresses are checked.** An IPv4-mapped IPv6 address (`::ffff:a.b.c.d`) is judged by the IPv4 address inside it. So are NAT64 (`64:ff9b::/96`) and 6to4 (`2002::/16`) addresses. +- **Teredo and local-use NAT64 are denied.** The `2001::/32` and `64:ff9b:1::/48` prefixes are never reachable. +- **IPv6-only networks work.** Sites reached through DNS64/NAT64 resolve and fetch as normal (0.35.0 and later). If the installed HTTPX version is untested for this, NAT64 support switches off and the guard denies the whole NAT64 prefix instead of loosening. +- **Hosts are validated strictly.** An IPv4 literal with a leading zero (`01.2.3.4`), a numeric pseudo-host, or an IPv6 literal with a zone id is rejected as an invalid URL. +- **Bad links are skipped.** A `javascript:` or `mailto:` pager link is not followed. A malformed link on a page is skipped, and the rest of the feed is still built. + +Rejected URLs raise `Html2rss::Url::InvalidUrlError`. Denied targets raise `PrivateNetworkDenied`, whose `kind` is `:blocked`. See [Ruby API: Error handling](/ruby-gem/reference/ruby-api/#error-handling). + ## Request Structure Use this split consistently: diff --git a/src/content/docs/troubleshooting/troubleshooting.mdx b/src/content/docs/troubleshooting/troubleshooting.mdx index f2cc4b23..a65e3b95 100644 --- a/src/content/docs/troubleshooting/troubleshooting.mdx +++ b/src/content/docs/troubleshooting/troubleshooting.mdx @@ -103,6 +103,16 @@ Common configuration-related errors: - **`stylesheet.type invalid`:** Only `text/css` and `text/xsl` are supported for stylesheets. - **`request.botasaurus` validation:** Unknown keys are rejected. Valid scroll, window size, and wait-timeout shapes are documented in [Strategy — Botasaurus](/ruby-gem/reference/strategy/#botasaurus). +### Empty Feeds On IPv6-Only Hosts + +If the host has only IPv6 connectivity (DNS64/NAT64, common on some cloud and mobile networks) and feeds from IPv4-only sites come back empty, upgrade `html2rss` to 0.35.0 or later. Earlier versions could not reach those sites through the NAT64 prefix. + +### `PrivateNetworkDenied` Or `InvalidUrlError` + +- **`PrivateNetworkDenied`:** the URL points at a local or private address, or its hostname resolves to one. html2rss refuses these by design. See [Network safeguards](/ruby-gem/reference/strategy/#network-safeguards). +- **`Url::InvalidUrlError`:** the URL is malformed. Since 0.35.0 this includes IPv4 hosts with leading zeros (`01.2.3.4`) and IPv6 hosts with a zone id. Write the address without them. +- `error.kind` and `error.retryable?` tell you whether a retry can help. See [Ruby API: Error handling](/ruby-gem/reference/ruby-api/#error-handling). + ### Missing Item Parts If parts of your items (e.g., title, link) are missing, check the following: From e3b9b188340707094adcdf4943e15a2b641b20e6 Mon Sep 17 00:00:00 2001 From: Gil Desmarais Date: Tue, 24 Nov 2026 16:00:39 +0100 Subject: [PATCH 2/3] docs: align Ruby API strategy list and network guard wording Co-Authored-By: Claude Opus 5.5 --- src/content/docs/ruby-gem/reference/ruby-api.mdx | 6 +++--- src/content/docs/ruby-gem/reference/strategy.mdx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/content/docs/ruby-gem/reference/ruby-api.mdx b/src/content/docs/ruby-gem/reference/ruby-api.mdx index 4f5535f8..01f94c6a 100644 --- a/src/content/docs/ruby-gem/reference/ruby-api.mdx +++ b/src/content/docs/ruby-gem/reference/ruby-api.mdx @@ -27,7 +27,7 @@ The curation verbs follow one path: `inspect`, `recon`, `capture`, `validate`, ` | `Html2rss.schema_json(pretty: true)` | `String` | | `Html2rss.configure` (block) | `Html2rss::Defaults` (frozen) | -`strategy` is `:auto` (default), `:default` or `:botasaurus`. See [Strategy](/ruby-gem/reference/strategy/). +`strategy` is `:auto` (default), `:default`, `:httpx` or `:botasaurus`. See [Strategy](/ruby-gem/reference/strategy/). ## Curation verbs @@ -68,7 +68,7 @@ Options: - `total_timeout_seconds` (positive Integer, default 30): bounds the whole request chain, including auto-fallback hops - `local_file_path` (with `strategy: :local_file`) -`candidates[:candidates_by_item]` lists title, link and date candidates for each of the top five item selectors. Details: [Capturing Feed Configs](/ruby-gem/guides/capturing-feed-configs/). +`candidates[:candidates_by_item]` lists title, link and published candidates for each of the top five item selectors. Details: [Capturing Feed Configs](/ruby-gem/guides/capturing-feed-configs/). Date: Tue, 24 Nov 2026 16:01:15 +0100 Subject: [PATCH 3/3] docs: scope network guard wording per strategy Co-Authored-By: Claude Opus 5.5 --- src/content/docs/ruby-gem/reference/strategy.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/docs/ruby-gem/reference/strategy.mdx b/src/content/docs/ruby-gem/reference/strategy.mdx index 2a937f5c..dfddb818 100644 --- a/src/content/docs/ruby-gem/reference/strategy.mdx +++ b/src/content/docs/ruby-gem/reference/strategy.mdx @@ -148,7 +148,7 @@ Because no remote network connection is established, `local_file` skips remote n ## Network safeguards -Every strategy that makes network requests runs the same guard before it connects and on every redirect hop. The default HTTPX transport also filters the addresses a hostname resolves to. +Every strategy that makes network requests checks the requested URL against the guard before fetching. The default HTTPX transport also checks every redirect hop and filters the addresses a hostname resolves to. With `botasaurus`, redirects happen inside the Botasaurus service, so its own network policy applies to them. `local_file` makes no network requests. - **Private networks are denied.** Local hostnames, loopback, link-local, private (RFC 1918), unique-local and multicast addresses fail with `RequestService::PrivateNetworkDenied`. - **Embedded IPv4 addresses are checked.** An IPv4-mapped IPv6 address (`::ffff:a.b.c.d`) is judged by the IPv4 address inside it. So are NAT64 (`64:ff9b::/96`) and 6to4 (`2002::/16`) addresses.