Class: ScreenshotFreeAPI::Resources::Monitors

Inherits:
Object
  • Object
show all
Defined in:
lib/screenshotfreeapi/resources/monitors.rb

Overview

App monitoring — schedule recurring captures and receive diff alerts.

Monitors run on a cron schedule and alert you when an app’s screenshots change (e.g., new version, UI refresh). Requires a BUSINESS+ plan.

All methods require a management JWT passed as ‘jwt:`.

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Monitors

Returns a new instance of Monitors.



12
13
14
# File 'lib/screenshotfreeapi/resources/monitors.rb', line 12

def initialize(http)
  @http = http
end

Instance Method Details

#create(jwt:, app_name:, platform:, schedule:, webhook_url: nil, **options) ⇒ Hash

Create a new app monitor.

Parameters:

  • jwt (String)

    Management JWT

  • app_name (String)

    App display name to monitor

  • platform (String)

    “ios” | “android” | “both”

  • schedule (String)

    Cron expression, e.g. “0 9 * * *” (daily at 9 AM UTC)

  • webhook_url (String) (defaults to: nil)

    URL to notify on detected changes

  • options (Hash)

    Additional monitor options

Returns:

  • (Hash)

    Monitor object with “id”, “appName”, “platform”, “schedule”



26
27
28
29
30
31
32
33
34
35
# File 'lib/screenshotfreeapi/resources/monitors.rb', line 26

def create(jwt:, app_name:, platform:, schedule:, webhook_url: nil, **options)
  body = {
    appName:    app_name,
    platform:   platform,
    schedule:   schedule,
    webhookUrl: webhook_url
  }.compact.merge(options)

  @http.request(:post, "/monitors/app", body: body, auth_header: "Bearer #{jwt}")
end

#delete(jwt:, monitor_id:) ⇒ Hash

Delete a monitor.

Parameters:

  • jwt (String)

    Management JWT

  • monitor_id (String)

    Monitor ID

Returns:

  • (Hash)

    Confirmation object



62
63
64
# File 'lib/screenshotfreeapi/resources/monitors.rb', line 62

def delete(jwt:, monitor_id:)
  @http.request(:delete, "/monitors/app/#{monitor_id}", auth_header: "Bearer #{jwt}")
end

#get(jwt:, monitor_id:) ⇒ Hash

Get a single monitor’s details.

Parameters:

  • jwt (String)

    Management JWT

  • monitor_id (String)

    Monitor ID

Returns:

  • (Hash)

    Monitor object



52
53
54
# File 'lib/screenshotfreeapi/resources/monitors.rb', line 52

def get(jwt:, monitor_id:)
  @http.request(:get, "/monitors/app/#{monitor_id}", auth_header: "Bearer #{jwt}")
end

#history(jwt:, monitor_id:, limit: nil, offset: nil) ⇒ Hash

Retrieve the run history and diff results for a monitor.

Parameters:

  • jwt (String)

    Management JWT

  • monitor_id (String)

    Monitor ID

  • limit (Integer) (defaults to: nil)

    Number of history entries to return (optional)

  • offset (Integer) (defaults to: nil)

    Pagination offset (optional)

Returns:

  • (Hash)

    { “history” => Array of run result hashes }



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/screenshotfreeapi/resources/monitors.rb', line 74

def history(jwt:, monitor_id:, limit: nil, offset: nil)
  query = {}
  query[:limit]  = limit  if limit
  query[:offset] = offset if offset

  @http.request(
    :get,
    "/monitors/app/#{monitor_id}/history",
    query:       query,
    auth_header: "Bearer #{jwt}"
  )
end

#list(jwt:) ⇒ Array<Hash>

List all monitors for the authenticated user.

Parameters:

  • jwt (String)

    Management JWT

Returns:

  • (Array<Hash>)

    Array of monitor objects



42
43
44
# File 'lib/screenshotfreeapi/resources/monitors.rb', line 42

def list(jwt:)
  @http.request(:get, "/monitors/app", auth_header: "Bearer #{jwt}")
end