hydrafetch 0.10.0 → 0.11.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: 1f3c10b7bd158cc49a2db003b8eab826c4bb6a57c6ac713f3ffaff65c7a67df9
4
- data.tar.gz: 3c4022a5dabb9b3d0cfa4846e7ddeaaf61cd6c948af5bbdd40f3f8918a80c6ad
3
+ metadata.gz: 20ac6ec29599733df883c61e9ccea0d933ee1123b3cc825c78f94e052a48ae7d
4
+ data.tar.gz: a6a13246a75e9568564a463fe4f433172b53c8675038cf79647109789a58237f
5
5
  SHA512:
6
- metadata.gz: 8ad4443cce76d5c9666c2bf910ea51a193935b52fa662daed40c9ed41a48e670ab0b3754fb6d9fd049202417425bf519790783b3794bdf1703a7d605eeaa4bf6
7
- data.tar.gz: f33e8de021dd4ab383ec5c08f88b697911d266b322c09bc386c9aac94c3694ef11f26768d9ce7918aa1699d2024af5b9f07ed87f1d2da8cdd40d21b3257d30c7
6
+ metadata.gz: 1cace415cf57bcfb0b222864d242127549634bff54d9c04f595bf9ecbd254ee7bbc509737590afc3e21475bf90cbb9d9f8a0fb986c96192362f3a2d10f1db46a
7
+ data.tar.gz: 3100e82c047486455799a391a56afbe92d1fb98ef58913f2698332b5213c609e411d7110d84dbaa2af575a64ba4a6f4ec19d9c8c627b824d88685a5de103ef67
data/README.md CHANGED
@@ -149,6 +149,39 @@ puts acme["totals"] # {"open"=>42, "opened"=>6, "closed"=>3}
149
149
 
150
150
  A search costs 1 credit per 10 jobs returned, and an empty one is free. Hiring changes cost 1 credit per company we have jobs for; companies we do not track yet come back empty and are free.
151
151
 
152
+ ## Monitors
153
+
154
+ Watch pages, a whole site or a search on a schedule and hear about what changed. Monitors are available on paid plans.
155
+
156
+ ```ruby
157
+ monitor = hf.create_monitor(
158
+ "Competitors",
159
+ [
160
+ { type: "pages", urls: ["https://acme.com/pricing"], goal: "a plan gets cheaper" },
161
+ { type: "site", url: "https://acme.com/blog" },
162
+ { type: "search", query: "acme funding" }
163
+ ],
164
+ every: "1h",
165
+ webhook: { url: "https://your-app.com/hooks/hydrafetch" }
166
+ )
167
+ ```
168
+
169
+ A pages target reports text that changed, as a line diff, plus fields such as price and availability. A site target reports pages that appear or go away, with each new page's title and opening lines. A search target reports results it has never returned before. With a `goal`, a change only alerts when it matches, and every change keeps the verdict and a one-sentence reason.
170
+
171
+ Checks run in the background. Your webhook receives `monitor.change` for each change and `monitor.check.completed` once a check ends, or read them yourself:
172
+
173
+ ```ruby
174
+ latest = hf.list_monitor_checks(monitor["id"], limit: 1).first
175
+ hf.get_monitor_check(monitor["id"], latest["id"])["changes"].each do |c|
176
+ puts [c["status"], c["url"], c.dig("judge", "reason") || c["diff"]].join(" ")
177
+ end
178
+
179
+ hf.run_monitor(monitor["id"]) # check now, outside the schedule
180
+ hf.update_monitor(monitor["id"], status: "paused")
181
+ ```
182
+
183
+ A page read costs 1 credit, a site costs 1 per check plus 1 per new page read, and a search costs 1 per check. A goal adds 1 credit per change it checks. Pages that cannot be read are not charged.
184
+
152
185
  ## Brand data
153
186
 
154
187
  ```ruby
@@ -240,6 +273,11 @@ hf = Hydrafetch::Client.new("hf_...",
240
273
  | `start_crawl`, `start_batch` | job id `String` | 1 per page |
241
274
  | `crawl_status(id)`, `batch_status(id)` | job hash | free |
242
275
  | `cancel_crawl(id)`, `cancel_batch(id)` | job hash | free, pages not yet read are not charged |
276
+ | `create_monitor(name, targets, every:, **options)`, `update_monitor(id, **changes)` | monitor hash | free; checks are charged as they run |
277
+ | `list_monitors(limit:, offset:)`, `get_monitor(id)` | array, monitor hash | free |
278
+ | `run_monitor(id)` | check summary hash | as a scheduled check |
279
+ | `list_monitor_checks(id, limit:, offset:)`, `get_monitor_check(id, check_id)` | array, check hash | free |
280
+ | `delete_monitor(id)` | `nil` | free |
243
281
  | `submit_batch(urls, **options)` | hash with `batchId`, `status` and `invalidUrls` | 1 per page |
244
282
  | `rate_result(rating, request_id:, url:, reasons:, note:)` | rating hash | free |
245
283
 
@@ -137,6 +137,41 @@ module Hydrafetch
137
137
  request(Net::HTTP::Delete, "/v1/web/batch/#{escape(id)}")
138
138
  end
139
139
 
140
+ def create_monitor(name, targets, every:, **options)
141
+ post("/v1/web/monitors", { name: name, schedule: { every: every }, targets: targets.to_a }.merge(compact(options)))
142
+ end
143
+
144
+ def list_monitors(limit: nil, offset: nil)
145
+ get("/v1/web/monitors", { limit: limit, offset: offset })
146
+ end
147
+
148
+ def get_monitor(id)
149
+ get("/v1/web/monitors/#{escape(id)}")
150
+ end
151
+
152
+ def update_monitor(id, every: nil, **changes)
153
+ body = compact(changes)
154
+ body[:schedule] = { every: every } if every
155
+ request(Net::HTTP::Patch, "/v1/web/monitors/#{escape(id)}", body: body)
156
+ end
157
+
158
+ def delete_monitor(id)
159
+ request(Net::HTTP::Delete, "/v1/web/monitors/#{escape(id)}")
160
+ nil
161
+ end
162
+
163
+ def run_monitor(id)
164
+ post("/v1/web/monitors/#{escape(id)}/run", nil)
165
+ end
166
+
167
+ def list_monitor_checks(id, limit: nil, offset: nil)
168
+ get("/v1/web/monitors/#{escape(id)}/checks", { limit: limit, offset: offset })
169
+ end
170
+
171
+ def get_monitor_check(id, check_id)
172
+ get("/v1/web/monitors/#{escape(id)}/checks/#{escape(check_id)}")
173
+ end
174
+
140
175
  def crawl(url, poll_interval: 2, job_timeout: 300, on_progress: nil, **options)
141
176
  id = start_crawl(url, **options)
142
177
  wait(poll_interval, job_timeout, on_progress) { crawl_status(id) }
@@ -1,3 +1,3 @@
1
1
  module Hydrafetch
2
- VERSION = "0.10.0".freeze
2
+ VERSION = "0.11.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydrafetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hydrafetch