shopify_client/services/app_installation/
mod.rs

1pub mod remote;
2
3use std::sync::Arc;
4
5use crate::{
6    common::types::{APIError, RequestCallbacks},
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    pub callbacks: Arc<RequestCallbacks>,
18}
19
20impl AppInstallation {
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        AppInstallation {
28            shop_url,
29            version,
30            access_token,
31            callbacks,
32        }
33    }
34
35    pub async fn get_current(&self) -> Result<GetCurrentAppInstallationResp, APIError> {
36        remote::get_current_app_installation(
37            &self.shop_url,
38            &self.version,
39            &self.access_token,
40            &self.callbacks,
41        )
42        .await
43    }
44
45    pub async fn set_metafields(
46        &self,
47        metafields: Vec<MetafieldInput>,
48    ) -> Result<SetMetafieldsResp, APIError> {
49        remote::set_metafields(
50            &self.shop_url,
51            &self.version,
52            &self.access_token,
53            &self.callbacks,
54            metafields,
55        )
56        .await
57    }
58
59    pub async fn get_metafield(
60        &self,
61        app_installation_id: &str,
62        namespace: &str,
63        key: &str,
64    ) -> Result<GetMetafieldResp, APIError> {
65        remote::get_metafield(
66            &self.shop_url,
67            &self.version,
68            &self.access_token,
69            &self.callbacks,
70            app_installation_id,
71            namespace,
72            key,
73        )
74        .await
75    }
76
77    pub async fn list_metafields(
78        &self,
79        app_installation_id: &str,
80        first: Option<i32>,
81    ) -> Result<ListMetafieldsResp, APIError> {
82        remote::list_metafields(
83            &self.shop_url,
84            &self.version,
85            &self.access_token,
86            &self.callbacks,
87            app_installation_id,
88            first,
89        )
90        .await
91    }
92
93    pub async fn delete_metafield(
94        &self,
95        metafield_id: &str,
96    ) -> Result<DeleteMetafieldResp, APIError> {
97        remote::delete_metafield(
98            &self.shop_url,
99            &self.version,
100            &self.access_token,
101            &self.callbacks,
102            metafield_id,
103        )
104        .await
105    }
106}