hydrafetch 0.5.0 → 0.6.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: a2db80b66abcc7cb6948142487ea814abe860920e18eeff4e0fe288b08d82490
4
- data.tar.gz: 02bd43273da1066e14cb2f36645d7d4e127028e068ff10f372d5c1ab59d77614
3
+ metadata.gz: 23264d8a3907a60da27fd4b3829e7062fa61ac02f707347da40ab806ac516f9a
4
+ data.tar.gz: caaae0845887de2fb69f5513c70d06dd49c7924fbfe6474df489af169a531221
5
5
  SHA512:
6
- metadata.gz: bdd7d850c628a7fe035026a462aa0355bf114dc02b8cbd5b61a4a248773a4fd9097558833ec6b11c7665bda288e9f4884c015df93851271133b7dc92f60cef57
7
- data.tar.gz: 0a524dbaaf0078234d73c532c1583401de9b4d3e83b2138a12de716dc92b0a73714564d572056559b5837749af742826488c44b989db8728ab8684dc6ddffe9b
6
+ metadata.gz: f7fa04df1d3d93016af860dfebc008d53a80874dbf835a6bfdd7f02ed561824c30e7667192dbc87427b205ced3c32661ff53ef1fd0d842fe9d6a119c887e4c04
7
+ data.tar.gz: 986a972bb98493037a41a0358e18d0c18698330ed7ed866bb1529c3f8c94e27cb206335bf8256c925222f7319246e0e674dd82d873735d1179e3f0a922ec52ed
data/README.md CHANGED
@@ -84,7 +84,7 @@ Pass `prompt:` instead of, or alongside, `schema:` to describe the fields in pla
84
84
 
85
85
  ```ruby
86
86
  links = hf.map("https://example.com", limit: 1000)["links"]
87
- docs = links.select { |url| url.include?("/docs/") }
87
+ docs = links.map { |link| link["url"] }.select { |url| url.include?("/docs/") }
88
88
  ```
89
89
 
90
90
  `batch` and `crawl` submit a job and poll until it finishes.
@@ -11,6 +11,11 @@ module Hydrafetch
11
11
  DEFAULT_TIMEOUT = 120
12
12
  DEFAULT_MAX_RETRIES = 2
13
13
  TERMINAL_STATUSES = %w[completed failed cancelled].freeze
14
+ ACCEPTED = 202
15
+ CALL_JOB_TIMEOUT = 330
16
+ CALL_JOB_POLL = 2
17
+
18
+ attr_writer :call_job_poll
14
19
 
15
20
  attr_reader :base_url, :last_request_id
16
21
 
@@ -188,7 +193,9 @@ module Hydrafetch
188
193
 
189
194
  res = http_for(uri).request(req)
190
195
  @last_request_id = res["x-request-id"] || @last_request_id
191
- unwrap(res)
196
+ result = unwrap(res)
197
+ poll = res.code.to_i == ACCEPTED && result.is_a?(Hash) ? result["poll"] : nil
198
+ poll ? follow_call_job(poll) : result
192
199
  rescue Error => e
193
200
  raise unless e.retryable? && attempt < @max_retries
194
201
 
@@ -203,6 +210,32 @@ module Hydrafetch
203
210
  end
204
211
  end
205
212
 
213
+ def follow_call_job(poll)
214
+ interval = @call_job_poll || CALL_JOB_POLL
215
+ deadline = monotonic + CALL_JOB_TIMEOUT
216
+ loop do
217
+ sleep interval
218
+ job = request(Net::HTTP::Get, poll)
219
+ case job["status"]
220
+ when "completed"
221
+ result = job["result"]
222
+ return result.is_a?(Hash) && result.key?("data") ? result["data"] : result
223
+ when "failed"
224
+ error = job["error"] || {}
225
+ raise Error.new(
226
+ error["message"] || "The job failed.",
227
+ code: error["code"] || "JOB_FAILED",
228
+ status: error["status"] || 500,
229
+ request_id: job["jobId"],
230
+ details: error["details"]
231
+ )
232
+ end
233
+ if monotonic + interval > deadline
234
+ raise TimeoutError.new("The job did not finish in time; poll #{poll} for its result.")
235
+ end
236
+ end
237
+ end
238
+
206
239
  def http_for(uri)
207
240
  http = Net::HTTP.new(uri.host, uri.port)
208
241
  http.use_ssl = uri.scheme == "https"
@@ -1,3 +1,3 @@
1
1
  module Hydrafetch
2
- VERSION = "0.5.0".freeze
2
+ VERSION = "0.6.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydrafetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hydrafetch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-05 00:00:00.000000000 Z
11
+ date: 2026-11-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Turn any URL into clean Markdown and structured data. Scrape, map, search,
14
14
  extract, brand and bulk crawl through one API.