Skip to main content

shopify_client/admin/storefront_access_token/
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::storefront_access_token::{
10        ListStorefrontAccessTokensResp, StorefrontAccessTokenCreateInput,
11        StorefrontAccessTokenCreateResp, StorefrontAccessTokenDeleteInput,
12        StorefrontAccessTokenDeleteResp,
13    },
14};
15
16pub struct StorefrontAccessToken {
17    pub(crate) ctx: ServiceContext,
18}
19
20impl StorefrontAccessToken {
21    pub fn new(
22        shop_url: Arc<String>,
23        version: Arc<String>,
24        access_token: Arc<String>,
25        callbacks: Arc<RequestCallbacks>,
26    ) -> Self {
27        Self::with_ctx(ServiceContext::new(
28            shop_url,
29            version,
30            access_token,
31            callbacks,
32        ))
33    }
34
35    /// Build the service from a shared `ServiceContext`. Cheaper than `new` at
36    /// construction sites that already hold a context (one `Arc` clone per service).
37    pub fn with_ctx(ctx: ServiceContext) -> Self {
38        Self { ctx }
39    }
40
41    pub async fn list(&self) -> Result<ListStorefrontAccessTokensResp, APIError> {
42        remote::list_storefront_access_tokens(&self.ctx).await
43    }
44
45    pub async fn create(
46        &self,
47        input: &StorefrontAccessTokenCreateInput,
48    ) -> Result<StorefrontAccessTokenCreateResp, APIError> {
49        remote::create_storefront_access_token(&self.ctx, input).await
50    }
51
52    pub async fn delete(
53        &self,
54        input: &StorefrontAccessTokenDeleteInput,
55    ) -> Result<StorefrontAccessTokenDeleteResp, APIError> {
56        remote::delete_storefront_access_token(&self.ctx, input).await
57    }
58}