Skip to main content

shopify_client/admin/cart_transform/
mod.rs

1pub mod remote;
2
3use crate::common::ServiceContext;
4
5use std::sync::Arc;
6
7use crate::{
8    common::types::{APIError, RequestCallbacks},
9    types::cart_transform::{
10        CartTransformCreateInput, CartTransformCreateResp, MetafieldsSetInput, MetafieldsSetResp,
11    },
12};
13
14pub struct CartTransform {
15    pub(crate) ctx: ServiceContext,
16}
17
18impl CartTransform {
19    pub fn new(
20        shop_url: Arc<String>,
21        version: Arc<String>,
22        access_token: Arc<String>,
23        callbacks: Arc<RequestCallbacks>,
24    ) -> Self {
25        Self::with_ctx(ServiceContext::new(
26            shop_url,
27            version,
28            access_token,
29            callbacks,
30        ))
31    }
32
33    /// Build the service from a shared `ServiceContext`. Cheaper than `new` at
34    /// construction sites that already hold a context (one `Arc` clone per service).
35    pub fn with_ctx(ctx: ServiceContext) -> Self {
36        Self { ctx }
37    }
38
39    pub async fn create(
40        &self,
41        input: &CartTransformCreateInput,
42    ) -> Result<CartTransformCreateResp, APIError> {
43        remote::create_cart_transform(&self.ctx, input).await
44    }
45
46    pub async fn set_metafields(
47        &self,
48        metafields: &[MetafieldsSetInput],
49    ) -> Result<MetafieldsSetResp, APIError> {
50        remote::set_metafields(&self.ctx, metafields).await
51    }
52}