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 CustomerSessionsApi<'a> {
    pub(crate) client: &'a Client,
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateCustomerSessionParams {
    /// 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: CreateCustomerSessionParamsBodyOneOf,
}

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

#[derive(Debug, Clone, Default, Serialize)]
pub struct RevokeCustomerSessionParams {
    /// 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> CustomerSessionsApi<'a> {
    /// Create a customer session
    ///
    /// Return a 15-minute bearer token once plus a separate single-use hosted redemption URL. Opening the URL signs the customer into this store's customer portal only. It does not sign them into the dashboard or other stores. Browser access and wallet credentials issued from it stop working when the session expires or is revoked. This response is never cached or replayed. 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 create_customer_session(
        &self,
        params: CreateCustomerSessionParams,
    ) -> Result<SdkCreateCustomerSessionResponseValue201ApplicationJson, Error> {
        self.create_customer_session_with_options(params, None)
            .await
    }

    /// Variant of [`Self::create_customer_session`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_customer_session_with_options(
        &self,
        params: CreateCustomerSessionParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkCreateCustomerSessionResponseValue201ApplicationJson, Error> {
        self.create_customer_session_raw(params, options)
            .await
            .map(|response| response.data)
    }

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

    /// Revoke a customer session
    ///
    /// Revoke immediately. 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 revoke_customer_session(
        &self,
        session: &str,
        params: RevokeCustomerSessionParams,
    ) -> Result<SdkRevokeCustomerSessionResponseValue200ApplicationJson, Error> {
        self.revoke_customer_session_with_options(session, params, None)
            .await
    }

    /// Variant of [`Self::revoke_customer_session`] that accepts per-request [`crate::RequestOptions`].
    pub async fn revoke_customer_session_with_options(
        &self,
        session: &str,
        params: RevokeCustomerSessionParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkRevokeCustomerSessionResponseValue200ApplicationJson, Error> {
        self.revoke_customer_session_raw(session, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn revoke_customer_session_raw(
        &self,
        session: &str,
        params: RevokeCustomerSessionParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkRevokeCustomerSessionResponseValue200ApplicationJson>, Error>
    {
        let session = crate::client::path_segment(session);
        let path = format!("/v2/customer-sessions/{session}");
        let method = http::Method::DELETE;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("revokeCustomerSession".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "DELETE /v2/customer-sessions/{session}",
            )
            .await
    }
}