Class: ContextDev::Resources::Web

Inherits:
Object
  • Object
show all
Defined in:
lib/context_dev/resources/web.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Web

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.

Returns a new instance of Web.

Parameters:



270
271
272
# File 'lib/context_dev/resources/web.rb', line 270

def initialize(client:)
  @client = client
end

Instance Method Details

#extract_fonts(direct_url: nil, domain: nil, timeout_ms: nil, request_options: {}) ⇒ ContextDev::Models::WebExtractFontsResponse

Some parameter documentations has been truncated, see Models::WebExtractFontsParams for more details.

Scrape font information from a website including font families, usage statistics, fallbacks, and element/word counts.

Parameters:

  • direct_url (String)

    A specific URL to fetch fonts from directly, bypassing domain resolution (e.g.,

  • domain (String)

    Domain name to extract fonts from (e.g., ‘example.com’, ‘google.com’). The domai

  • timeout_ms (Integer)

    Optional timeout in milliseconds for the request. If the request takes longer th

  • request_options (ContextDev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/context_dev/resources/web.rb', line 25

def extract_fonts(params = {})
  parsed, options = ContextDev::WebExtractFontsParams.dump_request(params)
  query = ContextDev::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "web/fonts",
    query: query.transform_keys(direct_url: "directUrl", timeout_ms: "timeoutMS"),
    model: ContextDev::Models::WebExtractFontsResponse,
    options: options
  )
end

#extract_styleguide(direct_url: nil, domain: nil, timeout_ms: nil, request_options: {}) ⇒ ContextDev::Models::WebExtractStyleguideResponse

Some parameter documentations has been truncated, see Models::WebExtractStyleguideParams for more details.

Extract a comprehensive design system from a website including colors, typography, spacing, shadows, and UI components.

Parameters:

  • direct_url (String)

    A specific URL to fetch the styleguide from directly, bypassing domain resolutio

  • domain (String)

    Domain name to extract styleguide from (e.g., ‘example.com’, ‘google.com’). The

  • timeout_ms (Integer)

    Optional timeout in milliseconds for the request. If the request takes longer th

  • request_options (ContextDev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/context_dev/resources/web.rb', line 56

def extract_styleguide(params = {})
  parsed, options = ContextDev::WebExtractStyleguideParams.dump_request(params)
  query = ContextDev::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "web/styleguide",
    query: query.transform_keys(direct_url: "directUrl", timeout_ms: "timeoutMS"),
    model: ContextDev::Models::WebExtractStyleguideResponse,
    options: options
  )
end

#screenshot(direct_url: nil, domain: nil, full_screenshot: nil, page: nil, prioritize: nil, request_options: {}) ⇒ ContextDev::Models::WebScreenshotResponse

Some parameter documentations has been truncated, see Models::WebScreenshotParams for more details.

Capture a screenshot of a website.

Parameters:

Returns:

See Also:



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/context_dev/resources/web.rb', line 90

def screenshot(params = {})
  parsed, options = ContextDev::WebScreenshotParams.dump_request(params)
  query = ContextDev::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "web/screenshot",
    query: query.transform_keys(direct_url: "directUrl", full_screenshot: "fullScreenshot"),
    model: ContextDev::Models::WebScreenshotResponse,
    options: options
  )
end

#web_crawl_md(url:, follow_subdomains: nil, include_images: nil, include_links: nil, max_depth: nil, max_pages: nil, shorten_base64_images: nil, url_regex: nil, use_main_content_only: nil, request_options: {}) ⇒ ContextDev::Models::WebWebCrawlMdResponse

Some parameter documentations has been truncated, see Models::WebWebCrawlMdParams for more details.

Performs a crawl starting from a given URL, extracts page content as Markdown, and returns results for all crawled pages.

Parameters:

  • url (String)

    The starting URL for the crawl (must include http:// or https:// protocol)

  • follow_subdomains (Boolean)

    When true, follow links on subdomains of the starting URL’s domain (e.g. docs.ex

  • include_images (Boolean)

    Include image references in the Markdown output

  • include_links (Boolean)

    Preserve hyperlinks in the Markdown output

  • max_depth (Integer)

    Maximum link depth from the starting URL (0 = only the starting page)

  • max_pages (Integer)

    Maximum number of pages to crawl. Hard cap: 500.

  • shorten_base64_images (Boolean)

    Truncate base64-encoded image data in the Markdown output

  • url_regex (String)

    Regex pattern. Only URLs matching this pattern will be followed and scraped.

  • use_main_content_only (Boolean)

    Extract only the main content, stripping headers, footers, sidebars, and navigat

  • request_options (ContextDev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



133
134
135
136
137
138
139
140
141
142
# File 'lib/context_dev/resources/web.rb', line 133

def web_crawl_md(params)
  parsed, options = ContextDev::WebWebCrawlMdParams.dump_request(params)
  @client.request(
    method: :post,
    path: "web/crawl",
    body: parsed,
    model: ContextDev::Models::WebWebCrawlMdResponse,
    options: options
  )
end

#web_scrape_html(url:, max_age_ms: nil, request_options: {}) ⇒ ContextDev::Models::WebWebScrapeHTMLResponse

Some parameter documentations has been truncated, see Models::WebWebScrapeHTMLParams for more details.

Scrapes the given URL and returns the raw HTML content of the page.

Parameters:

  • url (String)

    Full URL to scrape (must include http:// or https:// protocol)

  • max_age_ms (Integer)

    Return a cached result if a prior scrape for the same parameters exists and is y

  • request_options (ContextDev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/context_dev/resources/web.rb', line 160

def web_scrape_html(params)
  parsed, options = ContextDev::WebWebScrapeHTMLParams.dump_request(params)
  query = ContextDev::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "web/scrape/html",
    query: query.transform_keys(max_age_ms: "maxAgeMs"),
    model: ContextDev::Models::WebWebScrapeHTMLResponse,
    options: options
  )
end

#web_scrape_images(url:, request_options: {}) ⇒ ContextDev::Models::WebWebScrapeImagesResponse

Scrapes all images from the given URL. Extracts images from img, svg, picture/source, link, and video elements including inline SVGs, base64 data URIs, and standard URLs.

Parameters:

  • url (String)

    Full URL to scrape images from (must include http:// or https:// protocol)

  • request_options (ContextDev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



185
186
187
188
189
190
191
192
193
194
195
# File 'lib/context_dev/resources/web.rb', line 185

def web_scrape_images(params)
  parsed, options = ContextDev::WebWebScrapeImagesParams.dump_request(params)
  query = ContextDev::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "web/scrape/images",
    query: query,
    model: ContextDev::Models::WebWebScrapeImagesResponse,
    options: options
  )
end

#web_scrape_md(url:, include_images: nil, include_links: nil, max_age_ms: nil, shorten_base64_images: nil, use_main_content_only: nil, request_options: {}) ⇒ ContextDev::Models::WebWebScrapeMdResponse

Some parameter documentations has been truncated, see Models::WebWebScrapeMdParams for more details.

Scrapes the given URL into LLM usable Markdown.

Parameters:

  • url (String)

    Full URL to scrape into LLM usable Markdown (must include http:// or https:// pr

  • include_images (Boolean)

    Include image references in Markdown output

  • include_links (Boolean)

    Preserve hyperlinks in Markdown output

  • max_age_ms (Integer)

    Return a cached result if a prior scrape for the same parameters exists and is y

  • shorten_base64_images (Boolean)

    Shorten base64-encoded image data in the Markdown output

  • use_main_content_only (Boolean)

    Extract only the main content of the page, excluding headers, footers, sidebars,

  • request_options (ContextDev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/context_dev/resources/web.rb', line 221

def web_scrape_md(params)
  parsed, options = ContextDev::WebWebScrapeMdParams.dump_request(params)
  query = ContextDev::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "web/scrape/markdown",
    query: query.transform_keys(
      include_images: "includeImages",
      include_links: "includeLinks",
      max_age_ms: "maxAgeMs",
      shorten_base64_images: "shortenBase64Images",
      use_main_content_only: "useMainContentOnly"
    ),
    model: ContextDev::Models::WebWebScrapeMdResponse,
    options: options
  )
end

#web_scrape_sitemap(domain:, max_links: nil, request_options: {}) ⇒ ContextDev::Models::WebWebScrapeSitemapResponse

Some parameter documentations has been truncated, see Models::WebWebScrapeSitemapParams for more details.

Crawl an entire website’s sitemap and return all discovered page URLs.

Parameters:

  • domain (String)

    Domain to build a sitemap for

  • max_links (Integer)

    Maximum number of links to return from the sitemap crawl. Defaults to 10,000. Mi

  • request_options (ContextDev::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



255
256
257
258
259
260
261
262
263
264
265
# File 'lib/context_dev/resources/web.rb', line 255

def web_scrape_sitemap(params)
  parsed, options = ContextDev::WebWebScrapeSitemapParams.dump_request(params)
  query = ContextDev::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "web/scrape/sitemap",
    query: query.transform_keys(max_links: "maxLinks"),
    model: ContextDev::Models::WebWebScrapeSitemapResponse,
    options: options
  )
end