screenshotfreeapi 1.0.0

Official Rust client for ScreenshotFreeAPI — Screenshot-as-a-Service
Documentation
use std::sync::Arc;

use crate::error::Result;
use crate::http::HttpClient;
use crate::types::{JobResult, JobStatusResponse};

/// Jobs resource — poll job status and fetch results.
///
/// All screenshot endpoints return a `job_id` immediately (HTTP 202). Use
/// these methods to track progress and retrieve the final screenshots.
///
/// For a fully automated capture-and-wait flow, see
/// [`ScreenshotsResource::capture_web_and_wait`](crate::resources::screenshots::ScreenshotsResource::capture_web_and_wait)
/// or [`ScreenshotFreeAPIClient::capture`](crate::client::ScreenshotFreeAPIClient::capture).
#[derive(Clone)]
pub struct JobsResource {
    pub(crate) http: Arc<HttpClient>,
}

impl JobsResource {
    /// Poll the current status of a job.
    ///
    /// The `status` field will be one of:
    /// - `"queued"` — waiting in the queue
    /// - `"processing"` — actively being captured
    /// - `"completed"` — finished; call [`result`](Self::result) to get screenshots
    /// - `"failed"` — terminal failure; check the `error` field
    ///
    /// Corresponds to `GET /jobs/:id/status`.
    pub async fn status(&self, job_id: &str) -> Result<JobStatusResponse> {
        self.http.get(&format!("/jobs/{job_id}/status"), None).await
    }

    /// Fetch the complete result of a finished job, including presigned screenshot URLs.
    ///
    /// This will return a [`crate::ScreenshotFreeAPIError::NotFound`] error if called
    /// before the job has completed. Check [`status`](Self::status) first, or
    /// use the `capture_*_and_wait` helpers which handle polling automatically.
    ///
    /// Presigned S3 URLs are valid for **15 minutes** from when they are generated.
    ///
    /// Corresponds to `GET /jobs/:id/result`.
    pub async fn result(&self, job_id: &str) -> Result<JobResult> {
        self.http.get(&format!("/jobs/{job_id}/result"), None).await
    }
}