zoom_api/phone_devices.rs
1use crate::Client;
2use crate::ClientResult;
3
4pub struct PhoneDevices {
5 pub client: Client,
6}
7
8impl PhoneDevices {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 PhoneDevices { client }
12 }
13
14 /**
15 * List devices.
16 *
17 * This function performs a `GET` to the `/phone/devices` endpoint.
18 *
19 * List all the [desk phone devices](https://support.zoom.us/hc/en-us/articles/360021119092) that are configured with Zoom Phone on an account.
20 *
21 * **Scopes:** `phone:read:admin`</br>**[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
22 *
23 * **Prerequisites:**<br>
24 * * Pro or a higher account with Zoom Phone license
25 * * Account owner or admin permissions
26 *
27 * **Parameters:**
28 *
29 * * `type_: crate::types::ListPhoneDevicesType` -- State of the device. The value should be either `assigned` to list devices that have been assigned to user(s) or `unassigned` to list devices that have not yet been assigned to any user in the Zoom account.
30 * * `next_page_token: &str` -- The next page token is used to paginate through large result sets. A next page token will be returned whenever the set of available results exceeds the current page size. The expiration period for this token is 15 minutes.
31 * * `page_size: i64` -- The number of records returned within a single API call.
32 */
33 pub async fn list(
34 &self,
35 type_: crate::types::ListPhoneDevicesType,
36 next_page_token: &str,
37 page_size: i64,
38 ) -> ClientResult<crate::Response<Vec<crate::types::ListPhoneDevicesResponse>>> {
39 let mut query_args: Vec<(String, String)> = Default::default();
40 if !next_page_token.is_empty() {
41 query_args.push(("next_page_token".to_string(), next_page_token.to_string()));
42 }
43 if page_size > 0 {
44 query_args.push(("page_size".to_string(), page_size.to_string()));
45 }
46 if !type_.to_string().is_empty() {
47 query_args.push(("type".to_string(), type_.to_string()));
48 }
49 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
50 let url = self.client.url(&format!("/phone/devices?{}", query_), None);
51 let resp: crate::Response<crate::types::ListPhoneDevicesResponseData> = self
52 .client
53 .get(
54 &url,
55 crate::Message {
56 body: None,
57 content_type: None,
58 },
59 )
60 .await?;
61
62 // Return our response data.
63 Ok(crate::Response::new(
64 resp.status,
65 resp.headers,
66 resp.body.devices.to_vec(),
67 ))
68 }
69 /**
70 * List devices.
71 *
72 * This function performs a `GET` to the `/phone/devices` endpoint.
73 *
74 * As opposed to `list`, this function returns all the pages of the request at once.
75 *
76 * List all the [desk phone devices](https://support.zoom.us/hc/en-us/articles/360021119092) that are configured with Zoom Phone on an account.
77 *
78 * **Scopes:** `phone:read:admin`</br>**[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Medium`
79 *
80 * **Prerequisites:**<br>
81 * * Pro or a higher account with Zoom Phone license
82 * * Account owner or admin permissions
83 */
84 pub async fn list_all(
85 &self,
86 type_: crate::types::ListPhoneDevicesType,
87 ) -> ClientResult<crate::Response<Vec<crate::types::ListPhoneDevicesResponse>>> {
88 let mut query_args: Vec<(String, String)> = Default::default();
89 if !type_.to_string().is_empty() {
90 query_args.push(("type".to_string(), type_.to_string()));
91 }
92 let query_ = serde_urlencoded::to_string(&query_args).unwrap();
93 let url = self.client.url(&format!("/phone/devices?{}", query_), None);
94 let crate::Response::<crate::types::ListPhoneDevicesResponseData> {
95 mut status,
96 mut headers,
97 mut body,
98 } = self
99 .client
100 .get(
101 &url,
102 crate::Message {
103 body: None,
104 content_type: None,
105 },
106 )
107 .await?;
108
109 let mut devices = body.devices;
110 let mut page = body.next_page_token;
111
112 // Paginate if we should.
113 while !page.is_empty() {
114 // Check if we already have URL params and need to concat the token.
115 if !url.contains('?') {
116 crate::Response::<crate::types::ListPhoneDevicesResponseData> {
117 status,
118 headers,
119 body,
120 } = self
121 .client
122 .get(
123 &format!("{}?next_page_token={}", url, page),
124 crate::Message {
125 body: None,
126 content_type: None,
127 },
128 )
129 .await?;
130 } else {
131 crate::Response::<crate::types::ListPhoneDevicesResponseData> {
132 status,
133 headers,
134 body,
135 } = self
136 .client
137 .get(
138 &format!("{}&next_page_token={}", url, page),
139 crate::Message {
140 body: None,
141 content_type: None,
142 },
143 )
144 .await?;
145 }
146
147 devices.append(&mut body.devices);
148
149 if !body.next_page_token.is_empty() && body.next_page_token != page {
150 page = body.next_page_token.to_string();
151 } else {
152 page = "".to_string();
153 }
154 }
155
156 // Return our response data.
157 Ok(crate::Response::new(status, headers, devices))
158 }
159 /**
160 * Add a device.
161 *
162 * This function performs a `POST` to the `/phone/devices` endpoint.
163 *
164 * By default, all Zoom Phone users can make and receive calls using the Zoom desktop and mobile applications. Additionally, if a desk phone is required, use this API to [add a desk phone and assign it](https://support.zoom.us/hc/en-us/articles/360021119092#h_5ca07504-68a8-4c3d-ad0e-c1d3594436da) to a user.
165 *
166 * **Prerequisites:**<br>
167 * * Pro or a higher account with Zoom Phone license
168 * * Account owner or admin permissions
169 * * [Supported device](https://support.zoom.us/hc/en-us/articles/360001299063-Zoom-Voice-Supported-Devices)<br>
170 * **Scopes:** `phone:write:admin`<br>
171 *
172 *
173 * **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Light`
174 */
175 pub async fn add(
176 &self,
177 body: &crate::types::AddPhoneDeviceRequest,
178 ) -> ClientResult<crate::Response<()>> {
179 let url = self.client.url("/phone/devices", None);
180 self.client
181 .post(
182 &url,
183 crate::Message {
184 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
185 content_type: Some("application/json".to_string()),
186 },
187 )
188 .await
189 }
190 /**
191 * Get device details.
192 *
193 * This function performs a `GET` to the `/phone/devices/{deviceId}` endpoint.
194 *
195 * Get detailed information about a specific [desk phone device](https://support.zoom.us/hc/en-us/articles/360021119092).
196 *
197 * **Scopes:** `phone:write:admin`<br>**[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Light`
198 *
199 * **Prerequisites:**
200 * * Pro or a higher account with Zoom Phone license
201 * * Account owner or admin permissions
202 *
203 * **Parameters:**
204 *
205 * * `device_id: &str` -- Unique Identifier of the device.
206 */
207 pub async fn get_device(
208 &self,
209 device_id: &str,
210 ) -> ClientResult<crate::Response<crate::types::GetDeviceResponse>> {
211 let url = self.client.url(
212 &format!(
213 "/phone/devices/{}",
214 crate::progenitor_support::encode_path(device_id),
215 ),
216 None,
217 );
218 self.client
219 .get(
220 &url,
221 crate::Message {
222 body: None,
223 content_type: None,
224 },
225 )
226 .await
227 }
228 /**
229 * Delete a device.
230 *
231 * This function performs a `DELETE` to the `/phone/devices/{deviceId}` endpoint.
232 *
233 * Remove a [desk phone device](https://support.zoom.us/hc/en-us/articles/360021119092) from the Zoom Phone System Management.<br><br>
234 * **Prerequisites:**<br>
235 * * Pro or a higher account with Zoom Phone license
236 * * Account owner or admin permissions
237 * * Device must not have been assigned to a user.<br>
238 * **Scopes:** `phone:write:admin`<br>
239 *
240 *
241 * **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Light`
242 *
243 * **Parameters:**
244 *
245 * * `device_id: &str` -- Unique Identifier of the device.
246 */
247 pub async fn delete_device(&self, device_id: &str) -> ClientResult<crate::Response<()>> {
248 let url = self.client.url(
249 &format!(
250 "/phone/devices/{}",
251 crate::progenitor_support::encode_path(device_id),
252 ),
253 None,
254 );
255 self.client
256 .delete(
257 &url,
258 crate::Message {
259 body: None,
260 content_type: None,
261 },
262 )
263 .await
264 }
265 /**
266 * Update a device.
267 *
268 * This function performs a `PATCH` to the `/phone/devices/{deviceId}` endpoint.
269 *
270 * Update information of a [desk phone device](https://support.zoom.us/hc/en-us/articles/360021119092).<br><br>
271 * **Prerequisites:**<br>
272 * * Pro or a higher account with Zoom Phone license
273 * * Account owner or admin permissions<br>
274 * **Scopes:** `phone:write:admin`<br>
275 *
276 *
277 * **[Rate Limit Label](https://marketplace.zoom.us/docs/api-reference/rate-limits#rate-limits):** `Light`
278 *
279 * **Parameters:**
280 *
281 * * `device_id: &str` -- Unique Identifier of the Device.
282 */
283 pub async fn update_device(
284 &self,
285 device_id: &str,
286 body: &crate::types::UpdateDeviceRequest,
287 ) -> ClientResult<crate::Response<()>> {
288 let url = self.client.url(
289 &format!(
290 "/phone/devices/{}",
291 crate::progenitor_support::encode_path(device_id),
292 ),
293 None,
294 );
295 self.client
296 .patch(
297 &url,
298 crate::Message {
299 body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
300 content_type: Some("application/json".to_string()),
301 },
302 )
303 .await
304 }
305}