Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(ruby-sdk): send the SDK origin on crawl, batch scrape and map (#5230)

Erik Engervall1597fd761d24
diff --git a/apps/ruby-sdk/lib/firecrawl/client.rb b/apps/ruby-sdk/lib/firecrawl/client.rb
index 55a7da16e..9d2233763 100644
--- a/apps/ruby-sdk/lib/firecrawl/client.rb
+++ b/apps/ruby-sdk/lib/firecrawl/client.rb
@@ -222,6 +222,7 @@ module Firecrawl
body = { "url" => url }
body.merge!(options.to_h) if options
+ body["origin"] ||= "ruby-sdk@#{Firecrawl::VERSION}"
raw = @http.post("/v2/crawl", body)
Models::CrawlResponse.new(raw)
end
@@ -296,6 +297,7 @@ module Firecrawl
body.merge!(opts_hash)
body.merge!(nested) if nested
end
+ body["origin"] ||= "ruby-sdk@#{Firecrawl::VERSION}"
raw = @http.post("/v2/batch/scrape", body, extra_headers: extra_headers)
Models::BatchScrapeResponse.new(raw)
end
@@ -347,6 +349,7 @@ module Firecrawl
body = { "url" => url }
body.merge!(options.to_h) if options
+ body["origin"] ||= "ruby-sdk@#{Firecrawl::VERSION}"
raw = @http.post("/v2/map", body)
data = raw["data"] || raw
Models::MapData.new(data)
diff --git a/apps/ruby-sdk/test/firecrawl/client_test.rb b/apps/ruby-sdk/test/firecrawl/client_test.rb
index e6098934b..5417dae85 100644
--- a/apps/ruby-sdk/test/firecrawl/client_test.rb
+++ b/apps/ruby-sdk/test/firecrawl/client_test.rb
@@ -508,6 +508,26 @@ class ClientTest < Minitest::Test
assert_equal "batch-123", response.id
end
+ def test_start_calls_send_sdk_origin
+ origin = "ruby-sdk@#{Firecrawl::VERSION}"
+ stub_request(:post, "#{BASE_URL}/v2/crawl")
+ .with(body: hash_including("origin" => origin))
+ .to_return(status: 200, body: JSON.generate(id: "crawl-origin"), headers: { "Content-Type" => "application/json" })
+ stub_request(:post, "#{BASE_URL}/v2/batch/scrape")
+ .with(body: hash_including("origin" => origin, "formats" => ["markdown"]))
+ .to_return(status: 200, body: JSON.generate(id: "batch-origin"), headers: { "Content-Type" => "application/json" })
+ stub_request(:post, "#{BASE_URL}/v2/map")
+ .with(body: hash_including("origin" => origin))
+ .to_return(status: 200, body: JSON.generate(data: { links: [] }), headers: { "Content-Type" => "application/json" })
+
+ batch_options = Firecrawl::Models::BatchScrapeOptions.new(
+ options: Firecrawl::Models::ScrapeOptions.new(formats: ["markdown"])
+ )
+ assert_equal "crawl-origin", @client.start_crawl("https://example.com").id
+ assert_equal "batch-origin", @client.start_batch_scrape(["https://a.com"], batch_options).id
+ assert_empty @client.map("https://example.com").links
+ end
+
def test_batch_scrape_with_idempotency_key
stub_request(:post, "#{BASE_URL}/v2/batch/scrape")
.with(headers: { "x-idempotency-key" => "my-key" })