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

#[derive(Debug, Clone, Serialize)]
pub struct ListIntegrationEventsParams {
    /// Signed cursor bound to this filter set.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<String>,
    /// Maximum events to return.
    ///
    /// Defaults to `50`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Return only this event type.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "type")]
    pub type_: Option<String>,
    /// Return events for this subject type.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subject_type: Option<String>,
    /// Return events for this subject identifier.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subject_id: Option<String>,
    /// 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 Default for ListIntegrationEventsParams {
    #[allow(deprecated)]
    fn default() -> Self {
        Self {
            cursor: Default::default(),
            limit: Some(50),
            type_: Default::default(),
            subject_type: Default::default(),
            subject_id: Default::default(),
            x_store: Default::default(),
        }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct ListOrderEventsParams {
    /// Signed cursor bound to this filter set.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<String>,
    /// Maximum events to return.
    ///
    /// Defaults to `50`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// 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 Default for ListOrderEventsParams {
    #[allow(deprecated)]
    fn default() -> Self {
        Self {
            cursor: Default::default(),
            limit: Some(50),
            x_store: Default::default(),
        }
    }
}

impl<'a> EventsApi<'a> {
    /// List integration events
    ///
    /// Poll the 30-day journal with signed, filter-bound cursors. Use client-controlled backoff between ordinary requests. An expired position returns 410 cursor_expired with cursor_polling guidance. 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_integration_events(
        &self,
        params: ListIntegrationEventsParams,
    ) -> Result<SdkListIntegrationEventsResponseValue200ApplicationJson, Error> {
        self.list_integration_events_with_options(params, None)
            .await
    }

    /// Variant of [`Self::list_integration_events`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_integration_events_with_options(
        &self,
        params: ListIntegrationEventsParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkListIntegrationEventsResponseValue200ApplicationJson, Error> {
        self.list_integration_events_raw(params, options)
            .await
            .map(|response| response.data)
    }

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

    /// Returns an async [`futures_util::Stream`] that yields every `ListIntegrationEventsResponseValue200ApplicationJsonPropertyDataItem`
    /// across all pages, advancing the `cursor` cursor under the hood.
    ///
    /// ```ignore
    /// use futures_util::TryStreamExt;
    /// let all: Vec<ListIntegrationEventsResponseValue200ApplicationJsonPropertyDataItem> = self
    ///     .list_integration_events_auto_paging(params)
    ///     .try_collect()
    ///     .await?;
    /// ```
    pub fn list_integration_events_auto_paging(
        &self,
        params: ListIntegrationEventsParams,
    ) -> impl futures_util::Stream<
        Item = Result<ListIntegrationEventsResponseValue200ApplicationJsonPropertyDataItem, Error>,
    > + '_ {
        crate::pagination::auto_paginate_pages(move |after| {
            let mut params = params.clone();
            params.cursor = after;
            async move {
                let page = self.list_integration_events(params).await?;
                let next = if page.meta.has_more {
                    Some(page.meta.next_cursor)
                } else {
                    None
                };
                Ok((page.data, next))
            }
        })
    }

    /// List order events
    ///
    /// Read retained events for this order. Use the returned cursor for the next request and wait between polls. 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_order_events(
        &self,
        order: &str,
        params: ListOrderEventsParams,
    ) -> Result<SdkListOrderEventsResponseValue200ApplicationJson, Error> {
        self.list_order_events_with_options(order, params, None)
            .await
    }

    /// Variant of [`Self::list_order_events`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_order_events_with_options(
        &self,
        order: &str,
        params: ListOrderEventsParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkListOrderEventsResponseValue200ApplicationJson, Error> {
        self.list_order_events_raw(order, params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn list_order_events_raw(
        &self,
        order: &str,
        params: ListOrderEventsParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkListOrderEventsResponseValue200ApplicationJson>, Error> {
        let order = crate::client::path_segment(order);
        let path = format!("/v2/orders/{order}/events");
        let method = http::Method::GET;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("listOrderEvents".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "GET /v2/orders/{order}/events",
            )
            .await
    }

    /// Returns an async [`futures_util::Stream`] that yields every `ListOrderEventsResponseValue200ApplicationJsonPropertyDataItem`
    /// across all pages, advancing the `cursor` cursor under the hood.
    ///
    /// ```ignore
    /// use futures_util::TryStreamExt;
    /// let all: Vec<ListOrderEventsResponseValue200ApplicationJsonPropertyDataItem> = self
    ///     .list_order_events_auto_paging(order, params)
    ///     .try_collect()
    ///     .await?;
    /// ```
    pub fn list_order_events_auto_paging(
        &self,
        order: impl Into<String>,
        params: ListOrderEventsParams,
    ) -> impl futures_util::Stream<
        Item = Result<ListOrderEventsResponseValue200ApplicationJsonPropertyDataItem, Error>,
    > + '_ {
        let order: String = order.into();
        crate::pagination::auto_paginate_pages(move |after| {
            let order = order.clone();
            let mut params = params.clone();
            params.cursor = after;
            async move {
                let page = self.list_order_events(&order, params).await?;
                let next = if page.meta.has_more {
                    Some(page.meta.next_cursor)
                } else {
                    None
                };
                Ok((page.data, next))
            }
        })
    }
}