hydrafetch 0.4.1 → 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 +4 -4
- data/README.md +13 -1
- data/lib/hydrafetch/client.rb +38 -1
- data/lib/hydrafetch/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 23264d8a3907a60da27fd4b3829e7062fa61ac02f707347da40ab806ac516f9a
|
|
4
|
+
data.tar.gz: caaae0845887de2fb69f5513c70d06dd49c7924fbfe6474df489af169a531221
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
@@ -120,6 +120,17 @@ res["results"].each do |r|
|
|
|
120
120
|
end
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
+
## News
|
|
124
|
+
|
|
125
|
+
Find recent news articles about anything, newest first, each with its outlet and publish time:
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
news = hf.news("acme raises funding", timeRange: "week", limit: 10)
|
|
129
|
+
news["results"].each { |a| puts "#{a["publishedAt"]} #{a["title"]} #{a["url"]}" }
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
A news search costs 1 credit, and one that finds nothing is free. Pass `scrapeResults: true` to also read each article as clean data, at 1 extra credit per article.
|
|
133
|
+
|
|
123
134
|
## Jobs
|
|
124
135
|
|
|
125
136
|
Search open jobs collected from company career sites and hiring platforms, by the words in the job title:
|
|
@@ -213,6 +224,7 @@ hf = Hydrafetch::Client.new("hf_...",
|
|
|
213
224
|
| `markdown(url, **options)` | `String` | 1 |
|
|
214
225
|
| `map(url, **options)` | links hash | 1 |
|
|
215
226
|
| `search(query, **options)` | results hash | 1 + 1 per scraped result |
|
|
227
|
+
| `news(query, **options)` | articles, newest first | 1 + 1 per article read; free when empty |
|
|
216
228
|
| `search_jobs(query, **options)` | array of jobs | 1 per 10 jobs |
|
|
217
229
|
| `hiring_changes(domains, since, **options)` | array of companies | 1 per company with jobs |
|
|
218
230
|
| `extract(urls, **options)` | hash with `"results"` | 5 per URL |
|
data/lib/hydrafetch/client.rb
CHANGED
|
@@ -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
|
|
|
@@ -55,6 +60,10 @@ module Hydrafetch
|
|
|
55
60
|
post("/v1/web/search", { query: query }.merge(compact(options)))
|
|
56
61
|
end
|
|
57
62
|
|
|
63
|
+
def news(query, **options)
|
|
64
|
+
post("/v1/web/news", { query: query }.merge(compact(options)))
|
|
65
|
+
end
|
|
66
|
+
|
|
58
67
|
def search_jobs(query, **options)
|
|
59
68
|
post("/v1/web/index/jobs/search", { query: query }.merge(compact(options)))
|
|
60
69
|
end
|
|
@@ -184,7 +193,9 @@ module Hydrafetch
|
|
|
184
193
|
|
|
185
194
|
res = http_for(uri).request(req)
|
|
186
195
|
@last_request_id = res["x-request-id"] || @last_request_id
|
|
187
|
-
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
|
|
188
199
|
rescue Error => e
|
|
189
200
|
raise unless e.retryable? && attempt < @max_retries
|
|
190
201
|
|
|
@@ -199,6 +210,32 @@ module Hydrafetch
|
|
|
199
210
|
end
|
|
200
211
|
end
|
|
201
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
|
+
|
|
202
239
|
def http_for(uri)
|
|
203
240
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
204
241
|
http.use_ssl = uri.scheme == "https"
|
data/lib/hydrafetch/version.rb
CHANGED
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.
|
|
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-
|
|
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.
|