firecrawl-sdk 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 925d1d1e2e21f65f6ff043a07d8689f5e29b41d72b1b8791334af47d76153819
4
- data.tar.gz: 8e70053a8eabd4d2ff100386c4bb7c4fd2bea7ec119dedf2151d21c404e41e31
3
+ metadata.gz: 60a3360b0facad41a4d3c0a1a94e520f675ce5b6f72487665ead37f1b988de50
4
+ data.tar.gz: 51ced5462346c81d02327786e5022cd5789fed14940346e231c8619eb5b686b6
5
5
  SHA512:
6
- metadata.gz: ce98788dd3a379d575f97962b597224115463b28adf19870b0820c2a6e60c4fa44ce4b58d039843022e38d0027254e8808f3704552bc401994497c040f752233
7
- data.tar.gz: 7349d8f5d5a63d54364b7b1c1afef54b0d16930d6b107b97bb3ba933fc404ec45559ec8ab4a0e0551f142c108fb70e24ea30bfecf2562d01e0b182163e0e9eea
6
+ metadata.gz: 2e7a56e1fc2bd3b56b88337047f7c655c7ac78e6d43de94f4ee89c9b67701be95b45232d17ce6383023bd3d59199388012257c32d36c10c61823b02f5574f931
7
+ data.tar.gz: f2be762f47550bfa3bda7e7d8e7833b404b30d5447558893bc36ffe5de13953cc02bc00efe09d51f91eec9c1715701275e50336d154d2c47f4d5121a424aeb87
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
+ require "uri"
4
5
 
5
6
  module Firecrawl
6
7
  # Client for the Firecrawl v2 API.
@@ -280,6 +281,83 @@ module Firecrawl
280
281
  Models::MapData.new(data)
281
282
  end
282
283
 
284
+ # ================================================================
285
+ # MONITOR
286
+ # ================================================================
287
+
288
+ def create_monitor(name:, schedule:, targets:, webhook: nil, notification: nil, retention_days: nil)
289
+ body = {
290
+ "name" => name,
291
+ "schedule" => schedule,
292
+ "targets" => targets,
293
+ "webhook" => webhook,
294
+ "notification" => notification,
295
+ "retentionDays" => retention_days,
296
+ }.compact
297
+ raw = @http.post("/v2/monitor", body)
298
+ Models::Monitor.new(raw["data"] || raw)
299
+ end
300
+
301
+ def list_monitors(limit: nil, offset: nil)
302
+ raw = @http.get("/v2/monitor#{query(limit: limit, offset: offset)}")
303
+ (raw["data"] || []).map { |item| Models::Monitor.new(item) }
304
+ end
305
+
306
+ def get_monitor(monitor_id)
307
+ raise ArgumentError, "Monitor ID is required" if monitor_id.nil?
308
+
309
+ raw = @http.get("/v2/monitor/#{monitor_id}")
310
+ Models::Monitor.new(raw["data"] || raw)
311
+ end
312
+
313
+ def update_monitor(monitor_id, **attrs)
314
+ raise ArgumentError, "Monitor ID is required" if monitor_id.nil?
315
+
316
+ body = {
317
+ "name" => attrs[:name],
318
+ "status" => attrs[:status],
319
+ "schedule" => attrs[:schedule],
320
+ "webhook" => attrs[:webhook],
321
+ "notification" => attrs[:notification],
322
+ "targets" => attrs[:targets],
323
+ "retentionDays" => attrs[:retention_days],
324
+ }.compact
325
+ raw = @http.patch("/v2/monitor/#{monitor_id}", body)
326
+ Models::Monitor.new(raw["data"] || raw)
327
+ end
328
+
329
+ def delete_monitor(monitor_id)
330
+ raise ArgumentError, "Monitor ID is required" if monitor_id.nil?
331
+
332
+ @http.delete("/v2/monitor/#{monitor_id}")["success"] == true
333
+ end
334
+
335
+ def run_monitor(monitor_id)
336
+ raise ArgumentError, "Monitor ID is required" if monitor_id.nil?
337
+
338
+ raw = @http.post("/v2/monitor/#{monitor_id}/run", {})
339
+ Models::MonitorCheck.new(raw["data"] || raw)
340
+ end
341
+
342
+ def list_monitor_checks(monitor_id, limit: nil, offset: nil)
343
+ raise ArgumentError, "Monitor ID is required" if monitor_id.nil?
344
+
345
+ raw = @http.get("/v2/monitor/#{monitor_id}/checks#{query(limit: limit, offset: offset)}")
346
+ (raw["data"] || []).map { |item| Models::MonitorCheck.new(item) }
347
+ end
348
+
349
+ def get_monitor_check(monitor_id, check_id, limit: nil, skip: nil, status: nil, auto_paginate: true)
350
+ raise ArgumentError, "Monitor ID is required" if monitor_id.nil?
351
+ raise ArgumentError, "Check ID is required" if check_id.nil?
352
+
353
+ params = query(limit: limit, skip: skip, status: status)
354
+ raw = @http.get("/v2/monitor/#{monitor_id}/checks/#{check_id}#{params}")
355
+ data = raw["data"] || raw
356
+ data["next"] = raw["next"] if raw["next"]
357
+ check = Models::MonitorCheckDetail.new(data)
358
+ auto_paginate ? paginate_monitor_check(check) : check
359
+ end
360
+
283
361
  # ================================================================
284
362
  # SEARCH
285
363
  # ================================================================
@@ -378,6 +456,11 @@ module Firecrawl
378
456
 
379
457
  private
380
458
 
459
+ def query(**params)
460
+ compact = params.compact
461
+ compact.empty? ? "" : "?#{URI.encode_www_form(compact)}"
462
+ end
463
+
381
464
  def poll_crawl(job_id, poll_interval, timeout)
382
465
  deadline = Time.now + timeout
383
466
  while Time.now < deadline
@@ -423,5 +506,20 @@ module Firecrawl
423
506
  end
424
507
  job
425
508
  end
509
+
510
+ def paginate_monitor_check(check)
511
+ check.pages ||= []
512
+ current = check
513
+ while current.next_url && !current.next_url.empty?
514
+ raw = @http.get_absolute(current.next_url)
515
+ data = raw["data"] || raw
516
+ data["next"] = raw["next"] if raw["next"]
517
+ next_page = Models::MonitorCheckDetail.new(data)
518
+ check.pages.concat(next_page.pages) unless next_page.pages.empty?
519
+ current = next_page
520
+ end
521
+ check.next_url = nil
522
+ check
523
+ end
426
524
  end
427
525
  end
@@ -59,6 +59,16 @@ module Firecrawl
59
59
  execute_with_retry(uri, request)
60
60
  end
61
61
 
62
+ # Sends a PATCH request with JSON body.
63
+ def patch(path, body)
64
+ uri = URI("#{@base_url}#{path}")
65
+ request = Net::HTTP::Patch.new(uri)
66
+ request["Authorization"] = "Bearer #{@api_key}"
67
+ request["Content-Type"] = "application/json"
68
+ request.body = JSON.generate(body)
69
+ execute_with_retry(uri, request)
70
+ end
71
+
62
72
  # Sends a POST request with a multipart/form-data body.
63
73
  #
64
74
  # @param path [String] API path
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Firecrawl
4
+ module Models
5
+ class Monitor
6
+ attr_reader :id, :name, :status, :schedule, :next_run_at, :last_run_at,
7
+ :current_check_id, :targets, :webhook, :notification,
8
+ :retention_days, :estimated_credits_per_month,
9
+ :last_check_summary, :created_at, :updated_at
10
+
11
+ def initialize(data)
12
+ @id = data["id"]
13
+ @name = data["name"]
14
+ @status = data["status"]
15
+ @schedule = data["schedule"]
16
+ @next_run_at = data["nextRunAt"]
17
+ @last_run_at = data["lastRunAt"]
18
+ @current_check_id = data["currentCheckId"]
19
+ @targets = data["targets"] || []
20
+ @webhook = data["webhook"]
21
+ @notification = data["notification"]
22
+ @retention_days = data["retentionDays"]
23
+ @estimated_credits_per_month = data["estimatedCreditsPerMonth"]
24
+ @last_check_summary = data["lastCheckSummary"]
25
+ @created_at = data["createdAt"]
26
+ @updated_at = data["updatedAt"]
27
+ end
28
+ end
29
+
30
+ class MonitorCheck
31
+ attr_reader :id, :monitor_id, :status, :trigger, :scheduled_for,
32
+ :started_at, :finished_at, :estimated_credits,
33
+ :reserved_credits, :actual_credits, :billing_status,
34
+ :summary, :target_results, :notification_status, :error,
35
+ :created_at, :updated_at
36
+
37
+ def initialize(data)
38
+ @id = data["id"]
39
+ @monitor_id = data["monitorId"]
40
+ @status = data["status"]
41
+ @trigger = data["trigger"]
42
+ @scheduled_for = data["scheduledFor"]
43
+ @started_at = data["startedAt"]
44
+ @finished_at = data["finishedAt"]
45
+ @estimated_credits = data["estimatedCredits"]
46
+ @reserved_credits = data["reservedCredits"]
47
+ @actual_credits = data["actualCredits"]
48
+ @billing_status = data["billingStatus"]
49
+ @summary = data["summary"] || {}
50
+ @target_results = data["targetResults"]
51
+ @notification_status = data["notificationStatus"]
52
+ @error = data["error"]
53
+ @created_at = data["createdAt"]
54
+ @updated_at = data["updatedAt"]
55
+ end
56
+ end
57
+
58
+ class MonitorCheckDetail < MonitorCheck
59
+ attr_accessor :pages, :next_url
60
+
61
+ def initialize(data)
62
+ super
63
+ @pages = data["pages"] || []
64
+ @next_url = data["next"]
65
+ end
66
+ end
67
+ end
68
+ end
@@ -26,7 +26,7 @@ module Firecrawl
26
26
 
27
27
  def to_h
28
28
  {
29
- "formats" => formats,
29
+ "formats" => formats&.map { |fmt| format_value(fmt) },
30
30
  "headers" => headers,
31
31
  "includeTags" => include_tags,
32
32
  "excludeTags" => exclude_tags,
@@ -69,6 +69,10 @@ module Firecrawl
69
69
  fmt.respond_to?(:type) ? fmt.type : nil
70
70
  end
71
71
  end
72
+
73
+ def format_value(fmt)
74
+ fmt.respond_to?(:to_h) ? fmt.to_h : fmt
75
+ end
72
76
  end
73
77
  end
74
78
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Firecrawl
4
+ module Models
5
+ # Query format for asking a question about page content.
6
+ class QueryFormat
7
+ MODE_FREEFORM = "freeform"
8
+ MODE_DIRECT_QUOTE = "directQuote"
9
+
10
+ attr_reader :prompt, :mode
11
+
12
+ def initialize(prompt:, mode: nil)
13
+ unless mode.nil? || [MODE_FREEFORM, MODE_DIRECT_QUOTE].include?(mode)
14
+ raise ArgumentError, "query mode must be 'freeform' or 'directQuote'"
15
+ end
16
+
17
+ @prompt = prompt
18
+ @mode = mode
19
+ end
20
+
21
+ def to_h
22
+ {
23
+ "type" => "query",
24
+ "prompt" => prompt,
25
+ "mode" => mode,
26
+ }.compact
27
+ end
28
+
29
+ def type
30
+ "query"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -20,7 +20,7 @@ module Firecrawl
20
20
 
21
21
  def to_h
22
22
  {
23
- "formats" => formats,
23
+ "formats" => formats&.map { |fmt| format_value(fmt) },
24
24
  "headers" => headers,
25
25
  "includeTags" => include_tags,
26
26
  "excludeTags" => exclude_tags,
@@ -41,6 +41,12 @@ module Firecrawl
41
41
  "integration" => integration,
42
42
  }.compact
43
43
  end
44
+
45
+ private
46
+
47
+ def format_value(fmt)
48
+ fmt.respond_to?(:to_h) ? fmt.to_h : fmt
49
+ end
44
50
  end
45
51
  end
46
52
  end
@@ -5,8 +5,8 @@ module Firecrawl
5
5
  # Options for a web search request.
6
6
  class SearchOptions
7
7
  FIELDS = %i[
8
- sources categories limit tbs location ignore_invalid_urls
9
- timeout scrape_options integration
8
+ sources categories include_domains exclude_domains limit tbs location
9
+ ignore_invalid_urls timeout scrape_options integration
10
10
  ].freeze
11
11
 
12
12
  attr_reader(*FIELDS)
@@ -19,6 +19,8 @@ module Firecrawl
19
19
  {
20
20
  "sources" => sources,
21
21
  "categories" => categories,
22
+ "includeDomains" => include_domains,
23
+ "excludeDomains" => exclude_domains,
22
24
  "limit" => limit,
23
25
  "tbs" => tbs,
24
26
  "location" => location,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Firecrawl
4
- VERSION = "1.3.0"
4
+ VERSION = "1.4.0"
5
5
  end
data/lib/firecrawl.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require_relative "firecrawl/version"
4
4
  require_relative "firecrawl/errors"
5
5
  require_relative "firecrawl/http_client"
6
+ require_relative "firecrawl/models/query_format"
6
7
  require_relative "firecrawl/models/document"
7
8
  require_relative "firecrawl/models/scrape_options"
8
9
  require_relative "firecrawl/models/crawl_options"
@@ -22,4 +23,5 @@ require_relative "firecrawl/models/agent_response"
22
23
  require_relative "firecrawl/models/agent_status_response"
23
24
  require_relative "firecrawl/models/concurrency_check"
24
25
  require_relative "firecrawl/models/credit_usage"
26
+ require_relative "firecrawl/models/monitor"
25
27
  require_relative "firecrawl/client"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firecrawl-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firecrawl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-30 00:00:00.000000000 Z
11
+ date: 2026-05-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A type-safe Ruby client for the Firecrawl v2 API. Supports scraping,
14
14
  crawling, batch scraping, URL mapping, web search, and AI agent operations.
@@ -38,8 +38,10 @@ files:
38
38
  - lib/firecrawl/models/document.rb
39
39
  - lib/firecrawl/models/map_data.rb
40
40
  - lib/firecrawl/models/map_options.rb
41
+ - lib/firecrawl/models/monitor.rb
41
42
  - lib/firecrawl/models/parse_file.rb
42
43
  - lib/firecrawl/models/parse_options.rb
44
+ - lib/firecrawl/models/query_format.rb
43
45
  - lib/firecrawl/models/scrape_options.rb
44
46
  - lib/firecrawl/models/search_data.rb
45
47
  - lib/firecrawl/models/search_options.rb