Skip to main content

shopify_client/admin/shop/
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::shop::{GetShopResp, GetShopStatusResp},
10};
11
12pub struct Shop {
13    pub(crate) ctx: ServiceContext,
14}
15
16impl Shop {
17    pub fn new(
18        shop_url: Arc<String>,
19        version: Arc<String>,
20        access_token: Arc<String>,
21        callbacks: Arc<RequestCallbacks>,
22    ) -> Self {
23        Self::with_ctx(ServiceContext::new(
24            shop_url,
25            version,
26            access_token,
27            callbacks,
28        ))
29    }
30
31    /// Build the service from a shared `ServiceContext`. Cheaper than `new` at
32    /// construction sites that already hold a context (one `Arc` clone per service).
33    pub fn with_ctx(ctx: ServiceContext) -> Self {
34        Self { ctx }
35    }
36
37    pub async fn get(&self) -> Result<GetShopResp, APIError> {
38        remote::get_shop(&self.ctx).await
39    }
40
41    pub async fn get_status(&self) -> Result<GetShopStatusResp, APIError> {
42        remote::get_shop_status(&self.ctx).await
43    }
44}