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 {
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "type")]
pub type_: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub subject_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub subject_id: Option<String>,
#[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 {
#[serde(skip_serializing_if = "Option::is_none")]
pub cursor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
#[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> {
pub async fn list_integration_events(
&self,
params: ListIntegrationEventsParams,
) -> Result<SdkListIntegrationEventsResponseValue200ApplicationJson, Error> {
self.list_integration_events_with_options(params, None)
.await
}
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)
}
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, ¶ms, options, "GET /v2/events")
.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))
}
})
}
pub async fn list_order_events(
&self,
order: &str,
params: ListOrderEventsParams,
) -> Result<SdkListOrderEventsResponseValue200ApplicationJson, Error> {
self.list_order_events_with_options(order, params, None)
.await
}
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)
}
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,
¶ms,
options,
"GET /v2/orders/{order}/events",
)
.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))
}
})
}
}