shopify_client/services/app_installation/
mod.rs

1pub mod remote;
2
3use std::sync::Arc;
4
5use crate::{
6    common::types::APIError,
7    types::app_installation::{
8        DeleteMetafieldResp, GetCurrentAppInstallationResp, GetMetafieldResp, ListMetafieldsResp,
9        MetafieldInput, SetMetafieldsResp,
10    },
11};
12
13pub struct AppInstallation {
14    pub shop_url: Arc<String>,
15    pub version: Arc<String>,
16    pub access_token: Arc<String>,
17}
18
19impl AppInstallation {
20    pub fn new(shop_url: Arc<String>, version: Arc<String>, access_token: Arc<String>) -> Self {
21        AppInstallation {
22            shop_url,
23            version,
24            access_token,
25        }
26    }
27
28    pub async fn get_current(&self) -> Result<GetCurrentAppInstallationResp, APIError> {
29        remote::get_current_app_installation(&self.shop_url, &self.version, &self.access_token)
30            .await
31    }
32
33    pub async fn set_metafields(
34        &self,
35        metafields: Vec<MetafieldInput>,
36    ) -> Result<SetMetafieldsResp, APIError> {
37        remote::set_metafields(
38            &self.shop_url,
39            &self.version,
40            &self.access_token,
41            metafields,
42        )
43        .await
44    }
45
46    pub async fn get_metafield(
47        &self,
48        app_installation_id: &str,
49        namespace: &str,
50        key: &str,
51    ) -> Result<GetMetafieldResp, APIError> {
52        remote::get_metafield(
53            &self.shop_url,
54            &self.version,
55            &self.access_token,
56            app_installation_id,
57            namespace,
58            key,
59        )
60        .await
61    }
62
63    pub async fn list_metafields(
64        &self,
65        app_installation_id: &str,
66        first: Option<i32>,
67    ) -> Result<ListMetafieldsResp, APIError> {
68        remote::list_metafields(
69            &self.shop_url,
70            &self.version,
71            &self.access_token,
72            app_installation_id,
73            first,
74        )
75        .await
76    }
77
78    pub async fn delete_metafield(
79        &self,
80        metafield_id: &str,
81    ) -> Result<DeleteMetafieldResp, APIError> {
82        remote::delete_metafield(
83            &self.shop_url,
84            &self.version,
85            &self.access_token,
86            metafield_id,
87        )
88        .await
89    }
90}