Skip to main content

shopify_client/services/discount/
mod.rs

1pub mod remote;
2
3use std::sync::Arc;
4
5use crate::{
6    common::types::{APIError, RequestCallbacks},
7    types::discount::{
8        DiscountAutomaticAppCreateResp, DiscountAutomaticAppInput, DiscountAutomaticAppUpdateInput,
9        DiscountAutomaticAppUpdateResp, DiscountNodesResp, GetDiscountMetafieldResp,
10        GetDiscountNodeResp,
11    },
12};
13
14pub struct Discount {
15    pub shop_url: Arc<String>,
16    pub version: Arc<String>,
17    pub access_token: Arc<String>,
18    pub callbacks: Arc<RequestCallbacks>,
19}
20
21impl Discount {
22    pub fn new(
23        shop_url: Arc<String>,
24        version: Arc<String>,
25        access_token: Arc<String>,
26        callbacks: Arc<RequestCallbacks>,
27    ) -> Self {
28        Discount {
29            shop_url,
30            version,
31            access_token,
32            callbacks,
33        }
34    }
35
36    pub async fn create_automatic_app_discount(
37        &self,
38        input: &DiscountAutomaticAppInput,
39    ) -> Result<DiscountAutomaticAppCreateResp, APIError> {
40        remote::create_automatic_app_discount(
41            &self.shop_url,
42            &self.version,
43            &self.access_token,
44            &self.callbacks,
45            input,
46        )
47        .await
48    }
49
50    pub async fn update_automatic_app_discount(
51        &self,
52        input: &DiscountAutomaticAppUpdateInput,
53    ) -> Result<DiscountAutomaticAppUpdateResp, APIError> {
54        remote::update_automatic_app_discount(
55            &self.shop_url,
56            &self.version,
57            &self.access_token,
58            &self.callbacks,
59            input,
60        )
61        .await
62    }
63
64    pub async fn list_discounts(
65        &self,
66        first: Option<i32>,
67        after: Option<String>,
68        query: Option<String>,
69    ) -> Result<DiscountNodesResp, APIError> {
70        remote::list_discounts(
71            &self.shop_url,
72            &self.version,
73            &self.access_token,
74            &self.callbacks,
75            first,
76            after,
77            query,
78        )
79        .await
80    }
81
82    pub async fn get_discount_by_id(
83        &self,
84        id: &str,
85        first: Option<i32>,
86        after: Option<String>,
87    ) -> Result<GetDiscountNodeResp, APIError> {
88        remote::get_discount_by_id(
89            &self.shop_url,
90            &self.version,
91            &self.access_token,
92            &self.callbacks,
93            id,
94            first,
95            after,
96        )
97        .await
98    }
99
100    pub async fn get_discount_metafield(
101        &self,
102        id: &str,
103        namespace: &str,
104        key: &str,
105    ) -> Result<GetDiscountMetafieldResp, APIError> {
106        remote::get_discount_metafield(
107            &self.shop_url,
108            &self.version,
109            &self.access_token,
110            &self.callbacks,
111            id,
112            namespace,
113            key,
114        )
115        .await
116    }
117}