Class: ScreenshotFreeAPI::Resources::Jobs

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

Overview

Job polling endpoints.

All screenshot requests are asynchronous — the POST endpoints return a jobId immediately. Use these methods to check progress and retrieve results once the job reaches the “completed” state.

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Jobs

Returns a new instance of Jobs.



11
12
13
# File 'lib/screenshotfreeapi/resources/jobs.rb', line 11

def initialize(http)
  @http = http
end

Instance Method Details

#result(job_id) ⇒ Hash

Retrieve the completed result of a job.

Only available once ‘status` returns “completed”. Raises NotFoundError if the job is not yet done or was not found.

Parameters:

  • job_id (String)

Returns:

  • (Hash)

    {

    "jobId"       => String,
    "type"        => "web" | "mobile" | "html",
    "screenshots" => Array of {
      "url"        => String (presigned S3 URL, 15-min TTL),
      "format"     => "png" | "jpeg" | "webp" | "pdf",
      "width"      => Integer,
      "height"     => Integer,
      "capturedAt" => String,
      "selector"   => String | nil
    },
    "metadata"    => Hash (AI info, processingMs, etc.)
    

    }



54
55
56
# File 'lib/screenshotfreeapi/resources/jobs.rb', line 54

def result(job_id)
  @http.request(:get, "/jobs/#{job_id}/result")
end

#status(job_id) ⇒ Hash

Retrieve the current status of a job.

Parameters:

  • job_id (String)

    The jobId returned by a screenshot POST

Returns:

  • (Hash)

    "jobId"            => String,
    "status"           => "queued" | "processing" | "completed" | "failed",
    "progress"         => Integer (0-100),
    "error"            => String | nil,
    "estimatedSeconds" => Integer | nil,
    "createdAt"        => String (ISO 8601),
    "updatedAt"        => String (ISO 8601)
    



29
30
31
# File 'lib/screenshotfreeapi/resources/jobs.rb', line 29

def status(job_id)
  @http.request(:get, "/jobs/#{job_id}/status")
end