sendgrid_api/query.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Query {
5 pub client: Client,
6}
7
8impl Query {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Query { client }
12 }
13
14 /**
15 * Filter all messages.
16 *
17 * This function performs a `GET` to the `/messages` endpoint.
18 *
19 * This is **BETA** functionality. You may not have access, and we reserve the right to change functionality without notice.
20 *
21 * Filter all messages to search your Email Activity. All queries need to be [URL encoded](https://meyerweb.com/eric/tools/dencoder/), and have this format:
22 *
23 * `query={query_type}="{query_content}"`
24 *
25 * encoded, this would look like this:
26 *
27 * `query=type%3D%22query_content%22`
28 *
29 * for example:
30 *
31 * Filter by a specific email - `query=to_email%3D%22example%40example.com%22`
32 *
33 * Filter by subject line - `query=subject%3d%22A%20Great%20Subject%22`
34 *
35 * **Full list of basic query types and examples:**
36 *
37 *
38 * | **Filter query** | **Unencoded Example** (put this one into the try it out query - it'll automatically encode it for you) | **Encoded Example** (use this one in your code) |
39 * |-----------------|----------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------|
40 * | msg_id | msg_id=“filter0307p1las1-16816-5A023E36-1.0” | msg_id%3D%22filter0307p1las1-16816-5A023E36-1.0%22 |
41 * | from_email | from_email=“testing@sendgrid.net” | from_email%3D%22testing%40sendgrid.net%22 |
42 * | subject | subject="This is a subject test" | subject%22This%20is%20a%20subject%20test%22 |
43 * | to_email | to_email="example@example.com" | to_email%3D%22example%40example.com%22 |
44 * | status | | status%22processed%22 |
45 * | template_id | | |
46 * | asm_group_id | | |
47 * | api_key_id | | |
48 * | events | status="processed" | status%3D%22processed%22 |
49 * | originating_ip | | |
50 * | categories | | |
51 * | unique_args | | |
52 * | outbound_ip | | |
53 * | last_event_time | last_event_time=“2017-11-07T23:13:58Z” | last_event_time%3D%E2%80%9C2017-11-07T23%3A13%3A58Z%E2%80%9D |
54 * | clicks | clicks="0" | clicks%3D%220%22 |
55 *
56 * For information about building compound queries, and for the full query language functionality, see the [query language reference](https://docs.google.com/a/sendgrid.com/document/d/1fWoKTFNfg5UUsB6t9KuIcSo9CetKF_T0bGfWJ_gdPCs/edit?usp=sharing).
57 *
58 * Coming soon, example compound queries: limit + to email + date
59 *
60 * **Parameters:**
61 *
62 * * `query: &str` -- The license key provided with your New Relic account.
63 * * `limit: f64` -- The number of messages returned. This parameter must be greater than 0 and less than or equal to 1000.
64 * * `x_query_id: &str` -- The license key provided with your New Relic account.
65 * * `x_cursor: &str` -- The license key provided with your New Relic account.
66 * * `authorization: &str` -- The license key provided with your New Relic account.
67 */
68 pub async fn get_messages(
69 &self,
70 query: &str,
71 limit: f64,
72 ) -> ClientResult<crate::Response<crate::types::GetMessagesResponse>> {
73 let mut query_args: Vec<(String, String)> = Default::default();
74 if !limit.to_string().is_empty() {
75 query_args.push(("limit".to_string(), limit.to_string()));
76 }
77 if !query.is_empty() {
78 query_args.push(("query".to_string(), query.to_string()));
79 }
80 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
81 let url = self.client.url(&format!("/messages?{}", query_), None);
82 self.client
83 .get(
84 &url,
85 crate::Message {
86 body: None,
87 content_type: None,
88 },
89 )
90 .await
91 }
92 /**
93 * Filter messages by message ID.
94 *
95 * This function performs a `GET` to the `/messages/{msg_id}` endpoint.
96 *
97 * This is BETA functionality. You may not have access, and we reserve the right to change functionality without notice.
98 *
99 * Get all of the details about the specified message.
100 *
101 * **Parameters:**
102 *
103 * * `authorization: &str` -- The license key provided with your New Relic account.
104 */
105 pub async fn get_messages_msg(
106 &self,
107 msg_id: &str,
108 ) -> ClientResult<crate::Response<crate::types::Message>> {
109 let url = self.client.url(
110 &format!(
111 "/messages/{}",
112 crate::progenitor_support::encode_path(msg_id),
113 ),
114 None,
115 );
116 self.client
117 .get(
118 &url,
119 crate::Message {
120 body: None,
121 content_type: None,
122 },
123 )
124 .await
125 }
126}