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::{
    ZapierSubscribeRequest, ZapierSubscribeResponse, ZapierTriggerSample, ZapierUnsubscribeResponse,
};

/// Integrations resource — Zapier REST Hooks.
///
/// These endpoints use your **API key** (not a JWT).
///
/// # Example
///
/// ```rust,no_run
/// use screenshotfreeapi::{ScreenshotFreeAPIClient, ZapierSubscribeRequest};
///
/// #[tokio::main]
/// async fn main() -> screenshotfreeapi::Result<()> {
///     let client = ScreenshotFreeAPIClient::new("sfa_your_api_key");
///
///     let sub = client.integrations.zapier_subscribe(ZapierSubscribeRequest {
///         trigger_event: "job.completed".into(),
///         target_url: "https://hooks.zapier.com/hooks/catch/...".into(),
///     }).await?;
///     println!("Subscription created: {}", sub.id);
///     Ok(())
/// }
/// ```
#[derive(Clone)]
pub struct IntegrationsResource {
    pub(crate) http: Arc<HttpClient>,
}

impl IntegrationsResource {
    /// Register a Zapier webhook subscription.
    ///
    /// Corresponds to `POST /integrations/zapier/subscribe`.
    pub async fn zapier_subscribe(
        &self,
        request: ZapierSubscribeRequest,
    ) -> Result<ZapierSubscribeResponse> {
        self.http
            .post("/integrations/zapier/subscribe", &request, None)
            .await
    }

    /// Unregister a Zapier webhook subscription by its ID.
    ///
    /// Corresponds to `DELETE /integrations/zapier/unsubscribe/:id`.
    pub async fn zapier_unsubscribe(
        &self,
        subscription_id: &str,
    ) -> Result<ZapierUnsubscribeResponse> {
        self.http
            .delete(
                &format!("/integrations/zapier/unsubscribe/{subscription_id}"),
                None,
            )
            .await
    }

    /// Fetch a sample trigger payload for a given event type.
    ///
    /// Useful when building a Zapier integration to show Zapier what shape of
    /// data your trigger produces.
    ///
    /// Corresponds to `GET /integrations/zapier/triggers/:event`.
    pub async fn zapier_trigger_sample(&self, event: &str) -> Result<ZapierTriggerSample> {
        self.http
            .get(
                &format!("/integrations/zapier/triggers/{event}"),
                None,
            )
            .await
    }
}