google_calendar/settings.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct Settings {
5 pub client: Client,
6}
7
8impl Settings {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Settings { client }
12 }
13
14 /**
15 * This function performs a `GET` to the `/users/me/settings` endpoint.
16 *
17 * Returns all user settings for the authenticated user.
18 *
19 * **Parameters:**
20 *
21 * * `max_results: i64` -- Maximum number of entries returned on one result page. By default the value is 100 entries. The page size can never be larger than 250 entries. Optional.
22 * * `page_token: &str` -- Token specifying which result page to return. Optional.
23 * * `sync_token: &str` -- Token obtained from the nextSyncToken field returned on the last page of results from the previous list request. It makes the result of this list request contain only entries that have changed since then.
24 * If the syncToken expires, the server will respond with a 410 GONE response code and the client should clear its storage and perform a full synchronization without any syncToken.
25 * Learn more about incremental synchronization.
26 * Optional. The default is to return all entries.
27 */
28 pub async fn list(
29 &self,
30 max_results: i64,
31 page_token: &str,
32 ) -> ClientResult<crate::Response<Vec<crate::types::Setting>>> {
33 let mut query_args: Vec<(String, String)> = Default::default();
34 if max_results > 0 {
35 query_args.push(("maxResults".to_string(), max_results.to_string()));
36 }
37 if !page_token.is_empty() {
38 query_args.push(("pageToken".to_string(), page_token.to_string()));
39 }
40 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
41 let url = self
42 .client
43 .url(&format!("/users/me/settings?{}", query_), None);
44 let resp: crate::Response<crate::types::Settings> = self
45 .client
46 .get(
47 &url,
48 crate::Message {
49 body: None,
50 content_type: None,
51 },
52 )
53 .await?;
54
55 // Return our response data.
56 Ok(crate::Response::new(
57 resp.status,
58 resp.headers,
59 resp.body.items.to_vec(),
60 ))
61 }
62 /**
63 * This function performs a `GET` to the `/users/me/settings` endpoint.
64 *
65 * As opposed to `list`, this function returns all the pages of the request at once.
66 *
67 * Returns all user settings for the authenticated user.
68 */
69 pub async fn list_all(&self) -> ClientResult<crate::Response<Vec<crate::types::Setting>>> {
70 let url = self.client.url("/users/me/settings", None);
71 let crate::Response::<crate::types::Settings> {
72 mut status,
73 mut headers,
74 mut body,
75 } = self
76 .client
77 .get(
78 &url,
79 crate::Message {
80 body: None,
81 content_type: None,
82 },
83 )
84 .await?;
85
86 let mut items = body.items;
87 let mut page = body.next_page_token;
88
89 // Paginate if we should.
90 while !page.is_empty() {
91 if !url.contains('?') {
92 crate::Response::<crate::types::Settings> {
93 status,
94 headers,
95 body,
96 } = self
97 .client
98 .get(
99 &format!("{}?pageToken={}", url, page),
100 crate::Message {
101 body: None,
102 content_type: None,
103 },
104 )
105 .await?;
106 } else {
107 crate::Response::<crate::types::Settings> {
108 status,
109 headers,
110 body,
111 } = self
112 .client
113 .get(
114 &format!("{}&pageToken={}", url, page),
115 crate::Message {
116 body: None,
117 content_type: None,
118 },
119 )
120 .await?;
121 }
122
123 items.append(&mut body.items);
124
125 if !body.next_page_token.is_empty() && body.next_page_token != page {
126 page = body.next_page_token.to_string();
127 } else {
128 page = "".to_string();
129 }
130 }
131
132 // Return our response data.
133 Ok(crate::Response::new(status, headers, items))
134 }
135 /**
136 * This function performs a `POST` to the `/users/me/settings/watch` endpoint.
137 *
138 * Watch for changes to Settings resources.
139 *
140 * **Parameters:**
141 *
142 * * `max_results: i64` -- Maximum number of entries returned on one result page. By default the value is 100 entries. The page size can never be larger than 250 entries. Optional.
143 * * `page_token: &str` -- Token specifying which result page to return. Optional.
144 * * `sync_token: &str` -- Token obtained from the nextSyncToken field returned on the last page of results from the previous list request. It makes the result of this list request contain only entries that have changed since then.
145 * If the syncToken expires, the server will respond with a 410 GONE response code and the client should clear its storage and perform a full synchronization without any syncToken.
146 * Learn more about incremental synchronization.
147 * Optional. The default is to return all entries.
148 */
149 pub async fn watch(
150 &self,
151 max_results: i64,
152 page_token: &str,
153 body: &crate::types::Channel,
154 ) -> ClientResult<crate::Response<crate::types::Channel>> {
155 let mut query_args: Vec<(String, String)> = Default::default();
156 if max_results > 0 {
157 query_args.push(("maxResults".to_string(), max_results.to_string()));
158 }
159 if !page_token.is_empty() {
160 query_args.push(("pageToken".to_string(), page_token.to_string()));
161 }
162 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
163 let url = self
164 .client
165 .url(&format!("/users/me/settings/watch?{}", query_), None);
166 self.client
167 .post(
168 &url,
169 crate::Message {
170 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
171 content_type: Some("application/json".to_string()),
172 },
173 )
174 .await
175 }
176 /**
177 * This function performs a `GET` to the `/users/me/settings/{setting}` endpoint.
178 *
179 * Returns a single user setting.
180 *
181 * **Parameters:**
182 *
183 * * `setting: &str` -- The id of the user setting.
184 */
185 pub async fn get(&self, setting: &str) -> ClientResult<crate::Response<crate::types::Setting>> {
186 let url = self.client.url(
187 &format!(
188 "/users/me/settings/{}",
189 crate::progenitor_support::encode_path(setting),
190 ),
191 None,
192 );
193 self.client
194 .get(
195 &url,
196 crate::Message {
197 body: None,
198 content_type: None,
199 },
200 )
201 .await
202 }
203}