Skip to main content

brevo_rust/api/resources/program/
program.rs

1use crate::api::*;
2use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
3use reqwest::Method;
4
5pub struct ProgramClient {
6    pub http_client: HttpClient,
7}
8
9impl ProgramClient {
10    pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
11        Ok(Self {
12            http_client: HttpClient::new(config.clone())?,
13        })
14    }
15
16    /// Returns list of loyalty programs
17    ///
18    /// # Arguments
19    ///
20    /// * `limit` - Number of documents per page
21    /// * `offset` - Index of the first document in the page
22    /// * `sort_field` - Sort documents by field
23    /// * `sort` - Sort order
24    /// * `options` - Additional request options such as headers, timeout, etc.
25    ///
26    /// # Returns
27    ///
28    /// JSON response from the API
29    ///
30    /// # Examples
31    ///
32    /// ```no_run
33    /// use brevo_rust::prelude::*;
34    ///
35    /// #[tokio::main]
36    /// async fn main() {
37    ///     let config = ClientConfig {
38    ///         api_key: Some("<value>".to_string()),
39    ///         ..Default::default()
40    ///     };
41    ///     let client = BrevoClient::new(config).expect("Failed to build client");
42    ///     client
43    ///         .program
44    ///         .get_lp_list(
45    ///             &GetLpListQueryRequest {
46    ///                 ..Default::default()
47    ///             },
48    ///             None,
49    ///         )
50    ///         .await;
51    /// }
52    /// ```
53    pub async fn get_lp_list(
54        &self,
55        request: &GetLpListQueryRequest,
56        options: Option<RequestOptions>,
57    ) -> Result<GetLpListResponse, ApiError> {
58        self.http_client
59            .execute_request(
60                Method::GET,
61                "loyalty/config/programs",
62                None,
63                QueryBuilder::new()
64                    .int("limit", request.limit.clone())
65                    .int("offset", request.offset.clone())
66                    .serialize("sort_field", request.sort_field.clone())
67                    .serialize("sort", request.sort.clone())
68                    .build(),
69                options,
70            )
71            .await
72    }
73
74    /// Creates loyalty program
75    ///
76    /// # Arguments
77    ///
78    /// * `options` - Additional request options such as headers, timeout, etc.
79    ///
80    /// # Returns
81    ///
82    /// JSON response from the API
83    ///
84    /// # Examples
85    ///
86    /// ```no_run
87    /// use brevo_rust::prelude::*;
88    ///
89    /// #[tokio::main]
90    /// async fn main() {
91    ///     let config = ClientConfig {
92    ///         api_key: Some("<value>".to_string()),
93    ///         ..Default::default()
94    ///     };
95    ///     let client = BrevoClient::new(config).expect("Failed to build client");
96    ///     client
97    ///         .program
98    ///         .create_new_lp(
99    ///             &CreateNewLpRequest {
100    ///                 name: "name".to_string(),
101    ///                 description: None,
102    ///                 document_id: None,
103    ///                 meta: None,
104    ///             },
105    ///             None,
106    ///         )
107    ///         .await;
108    /// }
109    /// ```
110    pub async fn create_new_lp(
111        &self,
112        request: &CreateNewLpRequest,
113        options: Option<RequestOptions>,
114    ) -> Result<LoyaltyProgram, ApiError> {
115        self.http_client
116            .execute_request(
117                Method::POST,
118                "loyalty/config/programs",
119                Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
120                None,
121                options,
122            )
123            .await
124    }
125
126    /// Returns loyalty program
127    ///
128    /// # Arguments
129    ///
130    /// * `pid` - Loyalty Program ID. A unique identifier for the loyalty program.
131    /// * `options` - Additional request options such as headers, timeout, etc.
132    ///
133    /// # Returns
134    ///
135    /// JSON response from the API
136    ///
137    /// # Examples
138    ///
139    /// ```no_run
140    /// use brevo_rust::prelude::*;
141    ///
142    /// #[tokio::main]
143    /// async fn main() {
144    ///     let config = ClientConfig {
145    ///         api_key: Some("<value>".to_string()),
146    ///         ..Default::default()
147    ///     };
148    ///     let client = BrevoClient::new(config).expect("Failed to build client");
149    ///     client
150    ///         .program
151    ///         .get_loyalty_program_info(&"pid".to_string(), None)
152    ///         .await;
153    /// }
154    /// ```
155    pub async fn get_loyalty_program_info(
156        &self,
157        pid: &str,
158        options: Option<RequestOptions>,
159    ) -> Result<LoyaltyProgram, ApiError> {
160        self.http_client
161            .execute_request(
162                Method::GET,
163                &format!("loyalty/config/programs/{}", pid),
164                None,
165                None,
166                options,
167            )
168            .await
169    }
170
171    /// Updates loyalty program
172    ///
173    /// # Arguments
174    ///
175    /// * `pid` - Loyalty Program ID. A unique identifier for the loyalty program.
176    /// * `options` - Additional request options such as headers, timeout, etc.
177    ///
178    /// # Returns
179    ///
180    /// JSON response from the API
181    ///
182    /// # Examples
183    ///
184    /// ```no_run
185    /// use brevo_rust::prelude::*;
186    ///
187    /// #[tokio::main]
188    /// async fn main() {
189    ///     let config = ClientConfig {
190    ///         api_key: Some("<value>".to_string()),
191    ///         ..Default::default()
192    ///     };
193    ///     let client = BrevoClient::new(config).expect("Failed to build client");
194    ///     client
195    ///         .program
196    ///         .update_loyalty_program(
197    ///             &"pid".to_string(),
198    ///             &UpdateLoyaltyProgramRequest {
199    ///                 name: "name".to_string(),
200    ///                 description: None,
201    ///                 meta: None,
202    ///             },
203    ///             None,
204    ///         )
205    ///         .await;
206    /// }
207    /// ```
208    pub async fn update_loyalty_program(
209        &self,
210        pid: &str,
211        request: &UpdateLoyaltyProgramRequest,
212        options: Option<RequestOptions>,
213    ) -> Result<LoyaltyProgram, ApiError> {
214        self.http_client
215            .execute_request(
216                Method::PUT,
217                &format!("loyalty/config/programs/{}", pid),
218                Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
219                None,
220                options,
221            )
222            .await
223    }
224
225    /// Deletes Loyalty Program
226    ///
227    /// # Arguments
228    ///
229    /// * `pid` - Loyalty Program ID. A unique identifier for the loyalty program.
230    /// * `options` - Additional request options such as headers, timeout, etc.
231    ///
232    /// # Returns
233    ///
234    /// Empty response
235    ///
236    /// # Examples
237    ///
238    /// ```no_run
239    /// use brevo_rust::prelude::*;
240    ///
241    /// #[tokio::main]
242    /// async fn main() {
243    ///     let config = ClientConfig {
244    ///         api_key: Some("<value>".to_string()),
245    ///         ..Default::default()
246    ///     };
247    ///     let client = BrevoClient::new(config).expect("Failed to build client");
248    ///     client
249    ///         .program
250    ///         .delete_loyalty_program(&"pid".to_string(), None)
251    ///         .await;
252    /// }
253    /// ```
254    pub async fn delete_loyalty_program(
255        &self,
256        pid: &str,
257        options: Option<RequestOptions>,
258    ) -> Result<(), ApiError> {
259        self.http_client
260            .execute_request(
261                Method::DELETE,
262                &format!("loyalty/config/programs/{}", pid),
263                None,
264                None,
265                options,
266            )
267            .await
268    }
269
270    /// Partially updates loyalty program
271    ///
272    /// # Arguments
273    ///
274    /// * `pid` - Loyalty Program ID. A unique identifier for the loyalty program.
275    /// * `options` - Additional request options such as headers, timeout, etc.
276    ///
277    /// # Returns
278    ///
279    /// JSON response from the API
280    ///
281    /// # Examples
282    ///
283    /// ```no_run
284    /// use brevo_rust::prelude::*;
285    ///
286    /// #[tokio::main]
287    /// async fn main() {
288    ///     let config = ClientConfig {
289    ///         api_key: Some("<value>".to_string()),
290    ///         ..Default::default()
291    ///     };
292    ///     let client = BrevoClient::new(config).expect("Failed to build client");
293    ///     client
294    ///         .program
295    ///         .partially_update_loyalty_program(
296    ///             &"pid".to_string(),
297    ///             &PartiallyUpdateLoyaltyProgramRequest {
298    ///                 ..Default::default()
299    ///             },
300    ///             None,
301    ///         )
302    ///         .await;
303    /// }
304    /// ```
305    pub async fn partially_update_loyalty_program(
306        &self,
307        pid: &str,
308        request: &PartiallyUpdateLoyaltyProgramRequest,
309        options: Option<RequestOptions>,
310    ) -> Result<LoyaltyProgram, ApiError> {
311        self.http_client
312            .execute_request(
313                Method::PATCH,
314                &format!("loyalty/config/programs/{}", pid),
315                Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
316                None,
317                options,
318            )
319            .await
320    }
321
322    /// Get Information of balances, tiers, rewards and subscription members for a subscription
323    ///
324    /// # Arguments
325    ///
326    /// * `pid` - Loyalty Program ID. A unique identifier for the loyalty program.
327    /// * `contact_id` - The contact ID to filter by.
328    /// * `params` - A list of filter parameters for querying the subscription info.
329    /// * `loyalty_subscription_id` - The loyalty subscription ID to filter by.
330    /// * `include_internal` - Include balances tied to internal definitions.
331    /// * `options` - Additional request options such as headers, timeout, etc.
332    ///
333    /// # Returns
334    ///
335    /// JSON response from the API
336    ///
337    /// # Examples
338    ///
339    /// ```no_run
340    /// use brevo_rust::prelude::*;
341    ///
342    /// #[tokio::main]
343    /// async fn main() {
344    ///     let config = ClientConfig {
345    ///         api_key: Some("<value>".to_string()),
346    ///         ..Default::default()
347    ///     };
348    ///     let client = BrevoClient::new(config).expect("Failed to build client");
349    ///     client
350    ///         .program
351    ///         .get_parameter_subscription_info(
352    ///             &"pid".to_string(),
353    ///             &GetParameterSubscriptionInfoQueryRequest {
354    ///                 ..Default::default()
355    ///             },
356    ///             None,
357    ///         )
358    ///         .await;
359    /// }
360    /// ```
361    pub async fn get_parameter_subscription_info(
362        &self,
363        pid: &str,
364        request: &GetParameterSubscriptionInfoQueryRequest,
365        options: Option<RequestOptions>,
366    ) -> Result<GetParameterSubscriptionInfoResponse, ApiError> {
367        self.http_client
368            .execute_request(
369                Method::GET,
370                &format!("loyalty/config/programs/{}/account-info", pid),
371                None,
372                QueryBuilder::new()
373                    .string("contactId", request.contact_id.clone())
374                    .string("params", request.params.clone())
375                    .string(
376                        "loyaltySubscriptionId",
377                        request.loyalty_subscription_id.clone(),
378                    )
379                    .bool("includeInternal", request.include_internal.clone())
380                    .build(),
381                options,
382            )
383            .await
384    }
385
386    /// Delete subscription for a contact
387    ///
388    /// # Arguments
389    ///
390    /// * `pid` - Loyalty Program ID. A unique identifier for the loyalty program.
391    /// * `cid` - Contact ID.
392    /// * `options` - Additional request options such as headers, timeout, etc.
393    ///
394    /// # Returns
395    ///
396    /// Empty response
397    ///
398    /// # Examples
399    ///
400    /// ```no_run
401    /// use brevo_rust::prelude::*;
402    ///
403    /// #[tokio::main]
404    /// async fn main() {
405    ///     let config = ClientConfig {
406    ///         api_key: Some("<value>".to_string()),
407    ///         ..Default::default()
408    ///     };
409    ///     let client = BrevoClient::new(config).expect("Failed to build client");
410    ///     client
411    ///         .program
412    ///         .delete_contact_subscription(&"pid".to_string(), 1, None)
413    ///         .await;
414    /// }
415    /// ```
416    pub async fn delete_contact_subscription(
417        &self,
418        pid: &str,
419        cid: i64,
420        options: Option<RequestOptions>,
421    ) -> Result<(), ApiError> {
422        self.http_client
423            .execute_request(
424                Method::DELETE,
425                &format!("loyalty/config/programs/{}/contact/{}", pid, cid),
426                None,
427                None,
428                options,
429            )
430            .await
431    }
432
433    /// Publishes loyalty program
434    ///
435    /// # Arguments
436    ///
437    /// * `pid` - Loyalty Program ID. A unique identifier for the loyalty program.
438    /// * `options` - Additional request options such as headers, timeout, etc.
439    ///
440    /// # Returns
441    ///
442    /// Empty response
443    ///
444    /// # Examples
445    ///
446    /// ```no_run
447    /// use brevo_rust::prelude::*;
448    ///
449    /// #[tokio::main]
450    /// async fn main() {
451    ///     let config = ClientConfig {
452    ///         api_key: Some("<value>".to_string()),
453    ///         ..Default::default()
454    ///     };
455    ///     let client = BrevoClient::new(config).expect("Failed to build client");
456    ///     client
457    ///         .program
458    ///         .publish_loyalty_program(&"pid".to_string(), None)
459    ///         .await;
460    /// }
461    /// ```
462    pub async fn publish_loyalty_program(
463        &self,
464        pid: &str,
465        options: Option<RequestOptions>,
466    ) -> Result<(), ApiError> {
467        self.http_client
468            .execute_request(
469                Method::POST,
470                &format!("loyalty/config/programs/{}/publish", pid),
471                None,
472                None,
473                options,
474            )
475            .await
476    }
477
478    /// Add member to a subscription
479    ///
480    /// # Arguments
481    ///
482    /// * `pid` - Loyalty Program ID. A unique identifier for the loyalty program.
483    /// * `options` - Additional request options such as headers, timeout, etc.
484    ///
485    /// # Returns
486    ///
487    /// JSON response from the API
488    ///
489    /// # Examples
490    ///
491    /// ```no_run
492    /// use brevo_rust::prelude::*;
493    ///
494    /// #[tokio::main]
495    /// async fn main() {
496    ///     let config = ClientConfig {
497    ///         api_key: Some("<value>".to_string()),
498    ///         ..Default::default()
499    ///     };
500    ///     let client = BrevoClient::new(config).expect("Failed to build client");
501    ///     client
502    ///         .program
503    ///         .subscribe_member_to_a_subscription(
504    ///             &"pid".to_string(),
505    ///             &SubscribeMemberToASubscriptionRequest {
506    ///                 member_contact_ids: vec![1],
507    ///                 contact_id: None,
508    ///                 loyalty_subscription_id: None,
509    ///             },
510    ///             None,
511    ///         )
512    ///         .await;
513    /// }
514    /// ```
515    pub async fn subscribe_member_to_a_subscription(
516        &self,
517        pid: &str,
518        request: &SubscribeMemberToASubscriptionRequest,
519        options: Option<RequestOptions>,
520    ) -> Result<SubscribeMemberToASubscriptionResponse, ApiError> {
521        self.http_client
522            .execute_request(
523                Method::POST,
524                &format!("loyalty/config/programs/{}/subscription-members", pid),
525                Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
526                None,
527                options,
528            )
529            .await
530    }
531
532    /// Deletes member from a subscription
533    ///
534    /// # Arguments
535    ///
536    /// * `pid` - Loyalty Program ID. A unique identifier for the loyalty program.
537    /// * `member_contact_ids` - Comma-separated list of member contact IDs to delete from the subscription.
538    /// * `options` - Additional request options such as headers, timeout, etc.
539    ///
540    /// # Returns
541    ///
542    /// Empty response
543    ///
544    /// # Examples
545    ///
546    /// ```no_run
547    /// use brevo_rust::prelude::*;
548    ///
549    /// #[tokio::main]
550    /// async fn main() {
551    ///     let config = ClientConfig {
552    ///         api_key: Some("<value>".to_string()),
553    ///         ..Default::default()
554    ///     };
555    ///     let client = BrevoClient::new(config).expect("Failed to build client");
556    ///     client
557    ///         .program
558    ///         .delete_contact_members(
559    ///             &"pid".to_string(),
560    ///             &DeleteContactMembersQueryRequest {
561    ///                 member_contact_ids: "memberContactIds".to_string(),
562    ///             },
563    ///             None,
564    ///         )
565    ///         .await;
566    /// }
567    /// ```
568    pub async fn delete_contact_members(
569        &self,
570        pid: &str,
571        request: &DeleteContactMembersQueryRequest,
572        options: Option<RequestOptions>,
573    ) -> Result<(), ApiError> {
574        self.http_client
575            .execute_request(
576                Method::DELETE,
577                &format!("loyalty/config/programs/{}/subscription-members", pid),
578                None,
579                QueryBuilder::new()
580                    .string("memberContactIds", request.member_contact_ids.clone())
581                    .build(),
582                options,
583            )
584            .await
585    }
586
587    /// Subscribes to a loyalty program
588    ///
589    /// # Arguments
590    ///
591    /// * `pid` - Loyalty Program ID. A unique identifier for the loyalty program.
592    /// * `options` - Additional request options such as headers, timeout, etc.
593    ///
594    /// # Returns
595    ///
596    /// JSON response from the API
597    ///
598    /// # Examples
599    ///
600    /// ```no_run
601    /// use brevo_rust::prelude::*;
602    ///
603    /// #[tokio::main]
604    /// async fn main() {
605    ///     let config = ClientConfig {
606    ///         api_key: Some("<value>".to_string()),
607    ///         ..Default::default()
608    ///     };
609    ///     let client = BrevoClient::new(config).expect("Failed to build client");
610    ///     client
611    ///         .program
612    ///         .subscribe_to_loyalty_program(
613    ///             &"pid".to_string(),
614    ///             &SubscribeToLoyaltyProgramRequest {
615    ///                 contact_id: 1000000,
616    ///                 loyalty_subscription_id: None,
617    ///                 creation_date: None,
618    ///                 meta: None,
619    ///             },
620    ///             None,
621    ///         )
622    ///         .await;
623    /// }
624    /// ```
625    pub async fn subscribe_to_loyalty_program(
626        &self,
627        pid: &str,
628        request: &SubscribeToLoyaltyProgramRequest,
629        options: Option<RequestOptions>,
630    ) -> Result<SubscribeToLoyaltyProgramResponse, ApiError> {
631        self.http_client
632            .execute_request(
633                Method::POST,
634                &format!("loyalty/config/programs/{}/subscriptions", pid),
635                Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
636                None,
637                options,
638            )
639            .await
640    }
641}