sendgrid_api/
campaigns_api.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct CampaignsApi {
5    pub client: Client,
6}
7
8impl CampaignsApi {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        CampaignsApi { client }
12    }
13
14    /**
15     * Retrieve all Campaigns.
16     *
17     * This function performs a `GET` to the `/campaigns` endpoint.
18     *
19     * **This endpoint allows you to retrieve a list of all of your campaigns.**
20     *
21     * Returns campaigns in reverse order they were created (newest first).
22     *
23     * Returns an empty array if no campaigns exist.
24     *
25     * **Parameters:**
26     *
27     * * `limit: i64` -- The number of results you would like to receive at a time.
28     * * `offset: i64` -- The index of the first campaign to return, where 0 is the first campaign.
29     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
30     */
31    pub async fn get_campaigns(
32        &self,
33        limit: i64,
34        offset: i64,
35    ) -> ClientResult<crate::Response<crate::types::GetCampaignsResponse>> {
36        let mut query_args: Vec<(String, String)> = Default::default();
37        if limit > 0 {
38            query_args.push(("limit".to_string(), limit.to_string()));
39        }
40        if offset > 0 {
41            query_args.push(("offset".to_string(), offset.to_string()));
42        }
43        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
44        let url = self.client.url(&format!("/campaigns?{}", query_), None);
45        self.client
46            .get(
47                &url,
48                crate::Message {
49                    body: None,
50                    content_type: None,
51                },
52            )
53            .await
54    }
55    /**
56     * Create a Campaign.
57     *
58     * This function performs a `POST` to the `/campaigns` endpoint.
59     *
60     * **This endpoint allows you to create a campaign.**
61     *
62     * In order to send or schedule the campaign, you will be required to provide a subject, sender ID, content (we suggest both html and plain text), and at least one list or segment ID. This information is not required when you create a campaign.
63     *
64     * **Parameters:**
65     *
66     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
67     */
68    pub async fn post_campaign(
69        &self,
70        body: &crate::types::CampaignsRequest,
71    ) -> ClientResult<crate::Response<crate::types::CampaignResponseAllOf>> {
72        let url = self.client.url("/campaigns", None);
73        self.client
74            .post(
75                &url,
76                crate::Message {
77                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
78                    content_type: Some("application/json".to_string()),
79                },
80            )
81            .await
82    }
83    /**
84     * Retrieve a single campaign.
85     *
86     * This function performs a `GET` to the `/campaigns/{campaign_id}` endpoint.
87     *
88     * **This endpoint allows you to retrieve a specific campaign.**
89     *
90     * **Parameters:**
91     *
92     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
93     */
94    pub async fn get_campaigns_campaign(
95        &self,
96        campaign_id: i64,
97    ) -> ClientResult<crate::Response<crate::types::GetCampaignsCampaignResponse>> {
98        let url = self.client.url(
99            &format!(
100                "/campaigns/{}",
101                crate::progenitor_support::encode_path(&campaign_id.to_string()),
102            ),
103            None,
104        );
105        self.client
106            .get(
107                &url,
108                crate::Message {
109                    body: None,
110                    content_type: None,
111                },
112            )
113            .await
114    }
115    /**
116     * Delete a Campaign.
117     *
118     * This function performs a `DELETE` to the `/campaigns/{campaign_id}` endpoint.
119     *
120     * **This endpoint allows you to delete a specific campaign.**
121     *
122     * **Parameters:**
123     *
124     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
125     */
126    pub async fn delete_campaigns_campaign(
127        &self,
128        campaign_id: i64,
129    ) -> ClientResult<crate::Response<()>> {
130        let url = self.client.url(
131            &format!(
132                "/campaigns/{}",
133                crate::progenitor_support::encode_path(&campaign_id.to_string()),
134            ),
135            None,
136        );
137        self.client
138            .delete(
139                &url,
140                crate::Message {
141                    body: None,
142                    content_type: None,
143                },
144            )
145            .await
146    }
147    /**
148     * Update a Campaign.
149     *
150     * This function performs a `PATCH` to the `/campaigns/{campaign_id}` endpoint.
151     *
152     * **This endpoint allows you to update a specific campaign.**
153     *
154     * This is especially useful if you only set up the campaign using POST /campaigns, but didn't set many of the parameters.
155     *
156     * **Parameters:**
157     *
158     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
159     */
160    pub async fn patch_campaigns_campaign(
161        &self,
162        campaign_id: i64,
163        body: &crate::types::UpdateACampaignRequest,
164    ) -> ClientResult<crate::Response<crate::types::CampaignResponseAllOf>> {
165        let url = self.client.url(
166            &format!(
167                "/campaigns/{}",
168                crate::progenitor_support::encode_path(&campaign_id.to_string()),
169            ),
170            None,
171        );
172        self.client
173            .patch(
174                &url,
175                crate::Message {
176                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
177                    content_type: Some("application/json".to_string()),
178                },
179            )
180            .await
181    }
182    /**
183     * Send a Campaign.
184     *
185     * This function performs a `POST` to the `/campaigns/{campaign_id}/schedules/now` endpoint.
186     *
187     * **This endpoint allows you to immediately send an existing campaign.**
188     *
189     * Normally a POST request would have a body, but since this endpoint is telling us to send a resource that is already created, a request body is not needed.
190     *
191     * **Parameters:**
192     *
193     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
194     */
195    pub async fn post_campaigns_campaign_schedules_now(
196        &self,
197        campaign_id: i64,
198    ) -> ClientResult<crate::Response<crate::types::SendACampaignResponse>> {
199        let url = self.client.url(
200            &format!(
201                "/campaigns/{}/schedules/now",
202                crate::progenitor_support::encode_path(&campaign_id.to_string()),
203            ),
204            None,
205        );
206        self.client
207            .post(
208                &url,
209                crate::Message {
210                    body: None,
211                    content_type: None,
212                },
213            )
214            .await
215    }
216    /**
217     * View Scheduled Time of a Campaign.
218     *
219     * This function performs a `GET` to the `/campaigns/{campaign_id}/schedules` endpoint.
220     *
221     * **This endpoint allows you to retrieve the date and time that a campaign has been scheduled to be sent.**
222     *
223     * **Parameters:**
224     *
225     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
226     */
227    pub async fn get_campaigns_campaign_schedule(
228        &self,
229        campaign_id: i64,
230    ) -> ClientResult<crate::Response<crate::types::ScheduleACampaignRequest>> {
231        let url = self.client.url(
232            &format!(
233                "/campaigns/{}/schedules",
234                crate::progenitor_support::encode_path(&campaign_id.to_string()),
235            ),
236            None,
237        );
238        self.client
239            .get(
240                &url,
241                crate::Message {
242                    body: None,
243                    content_type: None,
244                },
245            )
246            .await
247    }
248    /**
249     * Schedule a Campaign.
250     *
251     * This function performs a `POST` to the `/campaigns/{campaign_id}/schedules` endpoint.
252     *
253     * **This endpoint allows you to schedule a specific date and time for your campaign to be sent.**
254     *
255     * If you have the flexibility, it's better to schedule mail for off-peak times. Most emails are scheduled and sent at the top of the hour or half hour. Scheduling email to avoid those times (for example, scheduling at 10:53) can result in lower deferral rates because it won't be going through our servers at the same times as everyone else's mail.
256     *
257     * **Parameters:**
258     *
259     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
260     */
261    pub async fn post_campaigns_campaign_schedule(
262        &self,
263        campaign_id: i64,
264        body: &crate::types::ScheduleACampaignRequest,
265    ) -> ClientResult<crate::Response<crate::types::ScheduleACampaignResponse>> {
266        let url = self.client.url(
267            &format!(
268                "/campaigns/{}/schedules",
269                crate::progenitor_support::encode_path(&campaign_id.to_string()),
270            ),
271            None,
272        );
273        self.client
274            .post(
275                &url,
276                crate::Message {
277                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
278                    content_type: Some("application/json".to_string()),
279                },
280            )
281            .await
282    }
283    /**
284     * Unschedule a Scheduled Campaign.
285     *
286     * This function performs a `DELETE` to the `/campaigns/{campaign_id}/schedules` endpoint.
287     *
288     * **This endpoint allows you to unschedule a campaign that has already been scheduled to be sent.**
289     *
290     * A successful unschedule will return a 204.
291     * If the specified campaign is in the process of being sent, the only option is to cancel (a different method).
292     *
293     * **Parameters:**
294     *
295     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
296     */
297    pub async fn delete_campaigns_campaign_schedules(
298        &self,
299        campaign_id: i64,
300    ) -> ClientResult<crate::Response<()>> {
301        let url = self.client.url(
302            &format!(
303                "/campaigns/{}/schedules",
304                crate::progenitor_support::encode_path(&campaign_id.to_string()),
305            ),
306            None,
307        );
308        self.client
309            .delete(
310                &url,
311                crate::Message {
312                    body: None,
313                    content_type: None,
314                },
315            )
316            .await
317    }
318    /**
319     * Update a Scheduled Campaign.
320     *
321     * This function performs a `PATCH` to the `/campaigns/{campaign_id}/schedules` endpoint.
322     *
323     * **This endpoint allows to you change the scheduled time and date for a campaign to be sent.**
324     *
325     * **Parameters:**
326     *
327     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
328     */
329    pub async fn patch_campaigns_campaign_schedules(
330        &self,
331        campaign_id: i64,
332        body: &crate::types::ScheduleACampaignRequest,
333    ) -> ClientResult<crate::Response<crate::types::UpdateAScheduledCampaignResponse>> {
334        let url = self.client.url(
335            &format!(
336                "/campaigns/{}/schedules",
337                crate::progenitor_support::encode_path(&campaign_id.to_string()),
338            ),
339            None,
340        );
341        self.client
342            .patch(
343                &url,
344                crate::Message {
345                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
346                    content_type: Some("application/json".to_string()),
347                },
348            )
349            .await
350    }
351    /**
352     * Send a Test Campaign.
353     *
354     * This function performs a `POST` to the `/campaigns/{campaign_id}/schedules/test` endpoint.
355     *
356     * **This endpoint allows you to send a test campaign.**
357     *
358     * To send to multiple addresses, use an array for the JSON "to" value ["one@address","two@address"]
359     *
360     * **Parameters:**
361     *
362     * * `on_behalf_of: &str` -- The license key provided with your New Relic account.
363     */
364    pub async fn post_campaigns_campaign_schedules_test(
365        &self,
366        campaign_id: i64,
367        body: &crate::types::SendATestCampaignRequest,
368    ) -> ClientResult<crate::Response<crate::types::SendATestCampaignRequest>> {
369        let url = self.client.url(
370            &format!(
371                "/campaigns/{}/schedules/test",
372                crate::progenitor_support::encode_path(&campaign_id.to_string()),
373            ),
374            None,
375        );
376        self.client
377            .post(
378                &url,
379                crate::Message {
380                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
381                    content_type: Some("application/json".to_string()),
382                },
383            )
384            .await
385    }
386}