1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
// @generated by xtask/generate_services.py — do not edit by hand.
//! `users` — typed methods for all 7 API v2 operations
//! in this module.
//!
//! Access via [`Ghl::users`](crate::Ghl::users).
//!
//! Request and response types come from [`ghl_models::v2::users`](https://docs.rs/ghl-models/latest/ghl_models/v2/users/); every endpoint is also documented in the
//! [`users` API reference](https://github.com/Shahroz/ghl-rs/blob/main/docs/api/users.md).
//!
//! Enable with `features = ["users"]`.
#![allow(clippy::too_many_arguments)]
use crate::client::Ghl;
use crate::error::Result;
use ghl_models::v2::users as models;
/// Typed access to the `users` API v2 surface (7 operations). Obtained via
/// [`Ghl::users`](crate::Ghl::users).
#[derive(Debug, Clone)]
pub struct UsersService {
pub(crate) client: Ghl,
}
impl UsersService {
pub(crate) fn new(client: Ghl) -> Self {
Self { client }
}
}
/// Query parameters for [`UsersService::get_user_by_location`].
#[derive(Debug, Clone, Default)]
pub struct GetUserByLocationParams {
/// `locationId` query parameter.
/// Required by the API.
pub location_id: String,
}
impl GetUserByLocationParams {
/// Start from the parameters the API requires.
pub fn new(location_id: impl Into<String>) -> Self {
Self {
location_id: location_id.into(),
}
}
fn to_query(&self) -> Vec<(String, String)> {
let q: Vec<(String, String)> = vec![("locationId".into(), self.location_id.clone())];
q
}
}
/// Query parameters for [`UsersService::search_users`].
#[derive(Debug, Clone, Default)]
pub struct SearchUsersParams {
/// Company ID in which the search needs to be performed
/// Required by the API.
pub company_id: String,
/// The search term for the user is matched based on the user full name, email or phone
pub query: Option<String>,
/// No of results to be skipped before returning the result
pub skip: Option<String>,
/// No of results to be limited before returning the result
pub limit: Option<String>,
/// Location ID in which the search needs to be performed
pub location_id: Option<String>,
/// Type of the users to be filtered in the search
pub type_: Option<String>,
/// Role of the users to be filtered in the search
pub role: Option<String>,
/// List of User IDs to be filtered in the search
pub ids: Option<String>,
/// The field on which sort is applied in which the results need to be sorted. Default
/// is based on the first and last name
pub sort: Option<String>,
/// The direction in which the results need to be sorted
pub sort_direction: Option<String>,
/// `enabled2waySync` query parameter.
pub enabled2way_sync: Option<bool>,
}
impl SearchUsersParams {
/// Start from the parameters the API requires.
pub fn new(company_id: impl Into<String>) -> Self {
Self {
company_id: company_id.into(),
..Default::default()
}
}
/// The search term for the user is matched based on the user full name, email or phone
pub fn query(mut self, v: impl Into<String>) -> Self {
self.query = Some(v.into());
self
}
/// No of results to be skipped before returning the result
pub fn skip(mut self, v: impl Into<String>) -> Self {
self.skip = Some(v.into());
self
}
/// No of results to be limited before returning the result
pub fn limit(mut self, v: impl Into<String>) -> Self {
self.limit = Some(v.into());
self
}
/// Location ID in which the search needs to be performed
pub fn location_id(mut self, v: impl Into<String>) -> Self {
self.location_id = Some(v.into());
self
}
/// Type of the users to be filtered in the search
pub fn type_(mut self, v: impl Into<String>) -> Self {
self.type_ = Some(v.into());
self
}
/// Role of the users to be filtered in the search
pub fn role(mut self, v: impl Into<String>) -> Self {
self.role = Some(v.into());
self
}
/// List of User IDs to be filtered in the search
pub fn ids(mut self, v: impl Into<String>) -> Self {
self.ids = Some(v.into());
self
}
/// The field on which sort is applied in which the results need to be sorted. Default
/// is based on the first and last name
pub fn sort(mut self, v: impl Into<String>) -> Self {
self.sort = Some(v.into());
self
}
/// The direction in which the results need to be sorted
pub fn sort_direction(mut self, v: impl Into<String>) -> Self {
self.sort_direction = Some(v.into());
self
}
/// Set the `enabled2waySync` query parameter.
pub fn enabled2way_sync(mut self, v: bool) -> Self {
self.enabled2way_sync = Some(v);
self
}
fn to_query(&self) -> Vec<(String, String)> {
let mut q: Vec<(String, String)> = vec![("companyId".into(), self.company_id.clone())];
if let Some(v) = &self.query {
q.push(("query".into(), v.to_string()));
}
if let Some(v) = &self.skip {
q.push(("skip".into(), v.to_string()));
}
if let Some(v) = &self.limit {
q.push(("limit".into(), v.to_string()));
}
if let Some(v) = &self.location_id {
q.push(("locationId".into(), v.to_string()));
}
if let Some(v) = &self.type_ {
q.push(("type".into(), v.to_string()));
}
if let Some(v) = &self.role {
q.push(("role".into(), v.to_string()));
}
if let Some(v) = &self.ids {
q.push(("ids".into(), v.to_string()));
}
if let Some(v) = &self.sort {
q.push(("sort".into(), v.to_string()));
}
if let Some(v) = &self.sort_direction {
q.push(("sortDirection".into(), v.to_string()));
}
if let Some(v) = &self.enabled2way_sync {
q.push(("enabled2waySync".into(), v.to_string()));
}
q
}
}
impl UsersService {
/// Get User by Location
///
/// Deprecated. Use `GET /users/search` instead. Pass `locationId` as a query parameter
/// to filter results by location, along with the required `companyId` and other search
/// filters as needed.
///
/// `GET /users/`
///
/// Requires scope: `users.readonly`.
pub async fn get_user_by_location(
&self,
params: &GetUserByLocationParams,
) -> Result<models::LocationSuccessfulResponseDto> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
"/users/",
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Create User
///
/// `POST /users/`
///
/// Requires scope: `users.write`.
pub async fn create_user(
&self,
body: &models::CreateUserDto,
) -> Result<models::UserSuccessfulResponseDto> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
"/users/",
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
/// Search Users
///
/// `GET /users/search`
///
/// Requires scope: `users.readonly`.
pub async fn search_users(
&self,
params: &SearchUsersParams,
) -> Result<models::SearchUserSuccessfulResponseDto> {
let query = params.to_query();
self.client
.send_versioned(
reqwest::Method::GET,
"/users/search",
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Filter Users by Email
///
/// Filter users by company ID, deleted status, and email array
///
/// `POST /users/search/filter-by-email`
///
/// Requires scope: `users.readonly`.
pub async fn filter_users_by_email(
&self,
body: &models::FilterByEmailDto,
) -> Result<models::SearchUserSuccessfulResponseDto> {
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::POST,
"/users/search/filter-by-email",
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
/// Delete User
///
/// `DELETE /users/{userId}`
///
/// Requires scope: `users.write`.
pub async fn delete_user(
&self,
user_id: &str,
) -> Result<models::DeleteUserSuccessfulResponseDto> {
let path = format!("/users/{}", crate::services::encode(user_id));
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::DELETE,
&path,
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Get User
///
/// `GET /users/{userId}`
///
/// Requires scope: `users.readonly`.
pub async fn get_user(&self, user_id: &str) -> Result<models::UserSuccessfulResponseDto> {
let path = format!("/users/{}", crate::services::encode(user_id));
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::GET,
&path,
&query,
None::<&()>,
Some("2021-07-28"),
)
.await
}
/// Update User
///
/// `PUT /users/{userId}`
///
/// Requires scope: `users.write`.
pub async fn update_user(
&self,
user_id: &str,
body: &models::UpdateUserDto,
) -> Result<models::UserSuccessfulResponseDto> {
let path = format!("/users/{}", crate::services::encode(user_id));
let query = Vec::new();
self.client
.send_versioned(
reqwest::Method::PUT,
&path,
&query,
Some(body),
Some("2021-07-28"),
)
.await
}
}