sellapp-sdk 0.1.1

Official Rust SDK for the SellApp API: manage products, orders, subscriptions, and customers.
// This file is auto-generated by oagen. Do not edit.

use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
#[allow(unused_imports)]
use serde::Serialize;

pub struct StoreCustomDomainsApi<'a> {
    pub(crate) client: &'a Client,
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct ListParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "X-STORE")]
    pub x_store: Option<String>,
}

#[derive(Debug, Clone, Serialize)]
pub struct ConnectParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "X-STORE")]
    pub x_store: Option<String>,
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: SdkConnectCustomDomainRequestApplicationJson,
}

impl ConnectParams {
    /// Construct a new `ConnectParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: SdkConnectCustomDomainRequestApplicationJson) -> Self {
        Self {
            x_store: Default::default(),
            body,
        }
    }
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct GetParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "X-STORE")]
    pub x_store: Option<String>,
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct DisconnectParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "X-STORE")]
    pub x_store: Option<String>,
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct RefreshParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "X-STORE")]
    pub x_store: Option<String>,
}

impl<'a> StoreCustomDomainsApi<'a> {
    /// List custom domains
    ///
    /// List the current store's custom-domain connection states and DNS verification records. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
    pub async fn list(
        &self,
        params: ListParams,
    ) -> Result<SdkListCustomDomainsResponseValue200ApplicationJson, Error> {
        self.list_with_options(params, None).await
    }

    /// Variant of [`Self::list`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_with_options(
        &self,
        params: ListParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkListCustomDomainsResponseValue200ApplicationJson, Error> {
        self.list_raw(params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn list_raw(
        &self,
        params: ListParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkListCustomDomainsResponseValue200ApplicationJson>, Error>
    {
        let path = "/v2/store/custom-domains".to_string();
        let method = http::Method::GET;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("listCustomDomains".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "GET /v2/store/custom-domains",
            )
            .await
    }

    /// Connect a custom domain
    ///
    /// Connect a hostname through SellApp's managed Cloudflare custom-hostname flow. IP addresses, wildcard domains, credentials, ports, queries, and fragments are rejected. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
    pub async fn connect(
        &self,
        params: ConnectParams,
    ) -> Result<SdkConnectCustomDomainResponseValue201ApplicationJson, Error> {
        self.connect_with_options(params, None).await
    }

    /// Variant of [`Self::connect`] that accepts per-request [`crate::RequestOptions`].
    pub async fn connect_with_options(
        &self,
        params: ConnectParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkConnectCustomDomainResponseValue201ApplicationJson, Error> {
        self.connect_raw(params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn connect_raw(
        &self,
        params: ConnectParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkConnectCustomDomainResponseValue201ApplicationJson>, Error>
    {
        let path = "/v2/store/custom-domains".to_string();
        let method = http::Method::POST;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("connectCustomDomain".to_string());
        let options = Some(&merged);
        self.client
            .request_with_body_schema_opts_raw(
                method,
                &path,
                &params,
                Some(&params.body),
                options,
                "POST /v2/store/custom-domains",
            )
            .await
    }

    /// Retrieve a custom domain
    ///
    /// Retrieve a custom domain. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
    pub async fn get(
        &self,
        custom_domain: &str,
        params: GetParams,
    ) -> Result<SdkGetCustomDomainResponseValue200ApplicationJson, Error> {
        self.get_with_options(custom_domain, params, None).await
    }

    /// Variant of [`Self::get`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_with_options(
        &self,
        custom_domain: &str,
        params: GetParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkGetCustomDomainResponseValue200ApplicationJson, Error> {
        self.get_raw(custom_domain, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn get_raw(
        &self,
        custom_domain: &str,
        params: GetParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkGetCustomDomainResponseValue200ApplicationJson>, Error> {
        let custom_domain = crate::client::path_segment(custom_domain);
        let path = format!("/v2/store/custom-domains/{custom_domain}");
        let method = http::Method::GET;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("getCustomDomain".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "GET /v2/store/custom-domains/{customDomain}",
            )
            .await
    }

    /// Disconnect a custom domain
    ///
    /// Disconnect a custom domain. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
    pub async fn disconnect(
        &self,
        custom_domain: &str,
        params: DisconnectParams,
    ) -> Result<SdkDisconnectCustomDomainResponseValue200ApplicationJson, Error> {
        self.disconnect_with_options(custom_domain, params, None)
            .await
    }

    /// Variant of [`Self::disconnect`] that accepts per-request [`crate::RequestOptions`].
    pub async fn disconnect_with_options(
        &self,
        custom_domain: &str,
        params: DisconnectParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkDisconnectCustomDomainResponseValue200ApplicationJson, Error> {
        self.disconnect_raw(custom_domain, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn disconnect_raw(
        &self,
        custom_domain: &str,
        params: DisconnectParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkDisconnectCustomDomainResponseValue200ApplicationJson>, Error>
    {
        let custom_domain = crate::client::path_segment(custom_domain);
        let path = format!("/v2/store/custom-domains/{custom_domain}");
        let method = http::Method::DELETE;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("disconnectCustomDomain".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "DELETE /v2/store/custom-domains/{customDomain}",
            )
            .await
    }

    /// Refresh custom domain status
    ///
    /// Ask Cloudflare to re-run custom-hostname validation and persist the latest DNS and SSL state. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
    pub async fn refresh(
        &self,
        custom_domain: &str,
        params: RefreshParams,
    ) -> Result<SdkRefreshCustomDomainStatusResponseValue200ApplicationJson, Error> {
        self.refresh_with_options(custom_domain, params, None).await
    }

    /// Variant of [`Self::refresh`] that accepts per-request [`crate::RequestOptions`].
    pub async fn refresh_with_options(
        &self,
        custom_domain: &str,
        params: RefreshParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkRefreshCustomDomainStatusResponseValue200ApplicationJson, Error> {
        self.refresh_raw(custom_domain, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn refresh_raw(
        &self,
        custom_domain: &str,
        params: RefreshParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<
        crate::RawResponse<SdkRefreshCustomDomainStatusResponseValue200ApplicationJson>,
        Error,
    > {
        let custom_domain = crate::client::path_segment(custom_domain);
        let path = format!("/v2/store/custom-domains/{custom_domain}/refresh");
        let method = http::Method::POST;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("refreshCustomDomainStatus".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "POST /v2/store/custom-domains/{customDomain}/refresh",
            )
            .await
    }
}