mailjet_api_wrapper/requests/
message_information_request.rs

1// This file is part of rust-mailjet <https://github.com/nevermille/rust-mailjet>
2// Copyright (C) 2023 Camille Nevermind
3//
4// This program is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 3 of the License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12// Lesser General Public License for more details.
13//
14// You should have received a copy of the GNU Lesser General Public License
15// along with this program; if not, write to the Free Software Foundation,
16// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18use crate::traits::UrlEncodedRequest;
19use url_builder::URLBuilder;
20
21/// The message information searching request
22#[derive(Default)]
23pub struct MessageInformationRequest {
24    /// Retrieves information only about messages that are part of this campaign
25    pub campaign_id: Option<i128>,
26
27    /// Retrieves information only about messages that were sent to this contact list
28    pub contacts_list: Option<i128>,
29
30    /// Retrieves information only about messages that are part of a campaign with the specified Custom ID
31    pub custom_campaign: Option<String>,
32
33    /// Retrieves information only about messages sent from the specified sender email address
34    pub from: Option<String>,
35
36    /// Retrieves information only about messages sent from the specified sender domain
37    pub from_domain: Option<String>,
38
39    /// Retrieves information only about messages sent from the specified sender ID
40    pub from_id: Option<i128>,
41
42    /// Retrieves information only about messages sent after the specified timestamp
43    ///
44    /// Both Unix timestamp (e.g. 1514764800) and RFC3339 (2018-01-01T00:00:00) formats are accepted
45    pub from_ts: Option<String>,
46
47    /// Retrieves information only for a specific type of messages
48    ///
49    /// See <https://dev.mailjet.com/email/reference/messages/#v3_get_messageinformation>
50    pub from_type: Option<i64>,
51
52    /// When true, will retrieve information only for messages that are part of deleted campaigns.
53    /// When false, messages from deleted campaigns will be excluded from the response.
54    pub is_deleted: Option<bool>,
55
56    /// When true, will retrieve information only for campaigns created with the Legacy template builder.
57    /// When false, campaigns created with the Legacy builder will be excluded from the response.
58    pub is_newsletter_tool: Option<bool>,
59
60    /// When true, will retrieve information only for messages that are part of starred campaigns.
61    /// When false, messages from starred campaigns will be excluded from the response.
62    pub is_starred: Option<bool>,
63
64    /// Retrieves information only for messages with the specified status
65    ///
66    /// See <https://dev.mailjet.com/email/reference/messages/#v3_get_messageinformation>
67    pub message_status: Option<i64>,
68
69    /// Retrieves information only for messages sent between the start of the selected period
70    /// and the current timestamp
71    pub period: Option<String>,
72
73    /// Retrieves information only for messages sent before the specified timestamp
74    ///
75    /// Both Unix timestamp (e.g. 1514764800) and RFC3339 (2018-01-01T00:00:00) formats are accepted
76    pub to_ts: Option<String>,
77
78    /// Limit the response to a select number of returned objects
79    pub limit: Option<i64>,
80
81    /// Retrieve a list of objects starting from a certain offset
82    pub offset: Option<i64>,
83
84    /// Set the value of this query parameter to 1 to retrieve the overall number of objects
85    /// returned by this request for your API Key
86    pub count_only: Option<i64>,
87
88    /// Specify a property name for this query parameter to sort the objects in `Data`
89    pub sort: Option<String>,
90}
91
92impl UrlEncodedRequest for MessageInformationRequest {
93    /// Adds parameter to a URL builder
94    ///
95    /// # Parameters
96    ///
97    /// * `url_builder`: The URL builder
98    fn add_parameters_to_url(&self, url_builder: &mut URLBuilder) {
99        if let Some(v) = self.campaign_id {
100            url_builder.add_param("CampaignID", &v.to_string());
101        }
102
103        if let Some(v) = self.contacts_list {
104            url_builder.add_param("ContactsList", &v.to_string());
105        }
106
107        if let Some(v) = &self.custom_campaign {
108            url_builder.add_param("CustomCampaign", v);
109        }
110
111        if let Some(v) = &self.from {
112            url_builder.add_param("From", v);
113        }
114
115        if let Some(v) = &self.from_domain {
116            url_builder.add_param("FromDomain", v);
117        }
118
119        if let Some(v) = self.from_id {
120            url_builder.add_param("FromID", &v.to_string());
121        }
122
123        if let Some(v) = &self.from_ts {
124            url_builder.add_param("FromTS", v);
125        }
126
127        if let Some(v) = self.from_type {
128            url_builder.add_param("FromType", &v.to_string());
129        }
130
131        if let Some(v) = self.is_deleted {
132            url_builder.add_param("IsDeleted", &v.to_string());
133        }
134
135        if let Some(v) = self.is_newsletter_tool {
136            url_builder.add_param("IsNewsletterTool", &v.to_string());
137        }
138
139        if let Some(v) = self.is_starred {
140            url_builder.add_param("IsStarred", &v.to_string());
141        }
142
143        if let Some(v) = self.message_status {
144            url_builder.add_param("MessageStatus", &v.to_string());
145        }
146
147        if let Some(v) = &self.period {
148            url_builder.add_param("Period", v);
149        }
150
151        if let Some(v) = &self.to_ts {
152            url_builder.add_param("ToTS", v);
153        }
154
155        if let Some(v) = self.limit {
156            url_builder.add_param("Limit", &v.to_string());
157        }
158
159        if let Some(v) = self.offset {
160            url_builder.add_param("Offset", &v.to_string());
161        }
162
163        if let Some(v) = self.count_only {
164            url_builder.add_param("countOnly", &v.to_string());
165        }
166
167        if let Some(v) = &self.sort {
168            url_builder.add_param("Sort", v);
169        }
170    }
171}