File size: 3,485 Bytes
097eaf0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# frozen_string_literal: true

module Firecrawl
  module Models
    class Monitor
      attr_reader :id, :name, :status, :schedule, :next_run_at, :last_run_at,
                  :current_check_id, :targets, :webhook, :notification,
                  :retention_days, :estimated_credits_per_month,
                  :last_check_summary, :goal, :judge_enabled,
                  :created_at, :updated_at

      def initialize(data)
        @id = data["id"]
        @name = data["name"]
        @status = data["status"]
        @schedule = data["schedule"]
        @next_run_at = data["nextRunAt"]
        @last_run_at = data["lastRunAt"]
        @current_check_id = data["currentCheckId"]
        @targets = data["targets"] || []
        @webhook = data["webhook"]
        @notification = data["notification"]
        @retention_days = data["retentionDays"]
        @estimated_credits_per_month = data["estimatedCreditsPerMonth"]
        @last_check_summary = data["lastCheckSummary"]
        @goal = data["goal"]
        @judge_enabled = data["judgeEnabled"] || false
        @created_at = data["createdAt"]
        @updated_at = data["updatedAt"]
      end
    end

    class MonitorCheck
      attr_reader :id, :monitor_id, :status, :trigger, :scheduled_for,
                  :started_at, :finished_at, :estimated_credits,
                  :reserved_credits, :actual_credits, :billing_status,
                  :summary, :target_results, :notification_status, :error,
                  :created_at, :updated_at

      def initialize(data)
        @id = data["id"]
        @monitor_id = data["monitorId"]
        @status = data["status"]
        @trigger = data["trigger"]
        @scheduled_for = data["scheduledFor"]
        @started_at = data["startedAt"]
        @finished_at = data["finishedAt"]
        @estimated_credits = data["estimatedCredits"]
        @reserved_credits = data["reservedCredits"]
        @actual_credits = data["actualCredits"]
        @billing_status = data["billingStatus"]
        @summary = data["summary"] || {}
        @target_results = data["targetResults"]
        @notification_status = data["notificationStatus"]
        @error = data["error"]
        @created_at = data["createdAt"]
        @updated_at = data["updatedAt"]
      end
    end

    # A monitor check with paginated page results inlined.
    #
    # Each entry in {#pages} is a {Hash} with the standard monitor page
    # fields (id, targetId, url, status, previousScrapeId,
    # currentScrapeId, statusCode, error, metadata, createdAt) plus:
    #
    # * +"diff"+  – when the page changed. A hash with +"text"+ (markdown
    #   unified diff) and/or +"json"+ (parseDiff AST for markdown
    #   monitors, or a per-field +{ "previous", "current" }+ map for
    #   JSON-extraction monitors).
    # * +"snapshot"+ – present on JSON / mixed-mode monitors. A hash
    #   with a +"json"+ key holding the current JSON extraction at this
    #   run.
    # * +"judgment"+ – present when the monitor has a +goal+ set and
    #   judging is enabled. A hash with +"meaningful"+ (Boolean),
    #   +"confidence"+ (+"high"+ / +"medium"+ / +"low"+), +"reason"+
    #   (String), and +"fields"+ (Array of String) describing which
    #   fields the judge weighed.
    class MonitorCheckDetail < MonitorCheck
      attr_accessor :pages, :next_url

      def initialize(data)
        super
        @pages = data["pages"] || []
        @next_url = data["next"]
      end
    end
  end
end