sendgrid_rs/
tracking_settings.rs

1use serde::Serialize;
2
3/// Struct used for serializing the ClickTracking node into SendGrid's API format. Use
4/// `TrackingSettingsBuilder` to configure this.
5#[derive(Serialize, Debug)]
6pub struct ClickTrackingSetting {
7    enable: bool,
8    enable_text: bool,
9}
10
11/// Struct used for serializing the OpenTracking node into SendGrid's API format. Use
12/// `TrackingSettingsBuilder` to configure this.
13#[derive(Serialize, Debug)]
14pub struct OpenTrackingSetting {
15    enable: bool,
16    substitution_tag: String,
17}
18
19/// Struct used for serializing the SubscriptionTracking node into SendGrid's API format. Use
20/// `TrackingSettingsBuilder` to configure this.
21#[derive(Serialize, Debug)]
22pub struct SubscriptionTrackingSetting {
23    enable: bool,
24    text: Option<String>,
25    html: Option<String>,
26    substitution_tag: String,
27}
28
29/// Struct used for serializing the GaTracking  node into SendGrid's API format. Use
30/// `GaTrackingSettingBuilder` to construct this.
31#[derive(Serialize, Debug)]
32pub struct GaTrackingSetting {
33    enable: bool,
34    utm_source: Option<String>,
35    utm_medium: Option<String>,
36    utm_term: Option<String>,
37    utm_content: Option<String>,
38    utm_campaign: Option<String>,
39}
40
41impl Default for GaTrackingSetting {
42    fn default() -> GaTrackingSetting {
43        GaTrackingSetting {
44            enable: true,
45            utm_source: None,
46            utm_medium: None,
47            utm_term: None,
48            utm_content: None,
49            utm_campaign: None,
50        }
51    }
52}
53
54/// Builder pattern for constructing `GaTrackingSetting`. Make sure you call `build()` when done to
55/// consume this and return the underlying `GaTrackingSetting`, Construct with `default()`.
56#[derive(Default)]
57pub struct GaTrackingSettingBuilder {
58    setting: GaTrackingSetting,
59}
60
61impl GaTrackingSettingBuilder {
62    /// Sets the GA utm_source for the `GaTrackingSetting`
63    ///
64    /// # Examples
65    /// ```
66    /// # use sendgrid_rs::GaTrackingSettingBuilder;
67    ///
68    /// let builder = GaTrackingSettingBuilder::default()
69    ///               .utm_source("source");
70    /// ```
71    pub fn utm_source(mut self, source: impl Into<String>) -> Self {
72        self.setting.utm_source = Some(source.into());
73        self
74    }
75
76    /// Sets the GA utm_medium for the `GaTrackingSetting`
77    ///
78    /// # Examples
79    /// ```
80    /// # use sendgrid_rs::GaTrackingSettingBuilder;
81    ///
82    /// let builder = GaTrackingSettingBuilder::default()
83    ///               .utm_medium("medium");
84    /// ```
85    pub fn utm_medium(mut self, medium: impl Into<String>) -> Self {
86        self.setting.utm_medium = Some(medium.into());
87        self
88    }
89
90    /// Sets the GA utm_term for the `GaTrackingSetting`
91    ///
92    /// # Examples
93    /// ```
94    /// # use sendgrid_rs::GaTrackingSettingBuilder;
95    ///
96    /// let builder = GaTrackingSettingBuilder::default()
97    ///               .utm_term("term");
98    /// ```
99    pub fn utm_term(mut self, term: impl Into<String>) -> Self {
100        self.setting.utm_term = Some(term.into());
101        self
102    }
103
104    /// Sets the GA utm_content for the `GaTrackingSetting`
105    ///
106    /// # Examples
107    /// ```
108    /// # use sendgrid_rs::GaTrackingSettingBuilder;
109    ///
110    /// let builder = GaTrackingSettingBuilder::default()
111    ///               .utm_content("content");
112    /// ```
113    pub fn utm_content(mut self, content: impl Into<String>) -> Self {
114        self.setting.utm_content = Some(content.into());
115        self
116    }
117
118    /// Sets the GA utm_campaign for the `GaTrackingSetting`
119    ///
120    /// # Examples
121    /// ```
122    /// # use sendgrid_rs::GaTrackingSettingBuilder;
123    ///
124    /// let builder = GaTrackingSettingBuilder::default()
125    ///               .utm_campaign("campaign");
126    /// ```
127    pub fn utm_campaign(mut self, campaign: impl Into<String>) -> Self {
128        self.setting.utm_campaign = Some(campaign.into());
129        self
130    }
131
132    /// Consumes the builder and returns the underlying `GaTrackingSetting`
133    ///
134    /// # Examples
135    /// ```
136    /// # use sendgrid_rs::GaTrackingSettingBuilder;
137    ///
138    /// let setting = GaTrackingSettingBuilder::default().build();
139    /// ```
140    pub fn build(self) -> GaTrackingSetting {
141        self.setting
142    }
143}
144
145/// Configures the SendGrid API node for TrackingSettings. Use `TrackingSettingsBuilder` to
146/// construct this.
147#[derive(Serialize, Default, Debug)]
148pub struct TrackingSettings {
149    click_tracking: Option<ClickTrackingSetting>,
150    open_tracking: Option<OpenTrackingSetting>,
151    subscription_tracking: Option<SubscriptionTrackingSetting>,
152    ganalytics: Option<GaTrackingSetting>,
153}
154
155/// Builder pattern for `TrackingSettings`. Make sure you call `build()` to consume this and return
156/// the underlying `TrackingSetting`. Construct with default().
157#[derive(Default)]
158pub struct TrackingSettingsBuilder {
159    settings: TrackingSettings,
160}
161
162impl TrackingSettingsBuilder {
163    /// Sets the click_tracking setting enabled to be true. Pass true to this method to enable text
164    /// tracking as well.
165    ///
166    /// # Examples
167    /// ```
168    /// # use sendgrid_rs::TrackingSettingsBuilder;
169    ///
170    /// let builder = TrackingSettingsBuilder::default()
171    ///               .click_tracking(true);
172    /// ```
173    pub fn click_tracking(mut self, enable_text: bool) -> Self {
174        self.settings.click_tracking = Some(ClickTrackingSetting {
175            enable: true,
176            enable_text,
177        });
178        self
179    }
180
181    /// Sets the open_tracking stting enabled to be true. Pass in the substitution_tag to be
182    /// replaced with it.
183    ///
184    /// # Examples
185    /// ```
186    /// # use sendgrid_rs::TrackingSettingsBuilder;
187    ///
188    /// let builder = TrackingSettingsBuilder::default()
189    ///               .open_tracking("[OPEN_TAG]");
190    /// ```
191    pub fn open_tracking(mut self, substitution_tag: impl Into<String>) -> Self {
192        self.settings.open_tracking = Some(OpenTrackingSetting {
193            enable: true,
194            substitution_tag: substitution_tag.into(),
195        });
196        self
197    }
198
199    /// Sets the substitution tag and text and/or html for subscription_tracking
200    ///
201    /// # Parameters
202    /// substitution_tag: impl Intl<String>
203    /// text: Option<String>
204    /// html: Option<String>
205    /// # Examples
206    /// ```
207    /// # use sendgrid_rs::TrackingSettingsBuilder;
208    ///
209    /// let builder = TrackingSettingsBuilder::default()
210    ///               .substitution_tag("[SUBSTITUTION_TAG]", None, None);
211    /// ```
212    pub fn substitution_tag(
213        mut self,
214        substitution_tag: impl Into<String>,
215        text: Option<String>,
216        html: Option<String>,
217    ) -> Self {
218        self.settings.subscription_tracking = Some(SubscriptionTrackingSetting {
219            enable: true,
220            substitution_tag: substitution_tag.into(),
221            text,
222            html,
223        });
224        self
225    }
226
227    /// Consumes the `TrackingSettingsBuilder` and returns the underlying `TrackingSettings`
228    ///
229    /// # Examples
230    /// ```
231    /// # use sendgrid_rs::TrackingSettingsBuilder;
232    ///
233    /// let setting = TrackingSettingsBuilder::default().build();
234    /// ```
235    pub fn build(self) -> TrackingSettings {
236        self.settings
237    }
238}