msgraph_rs/resources/users/
methods.rs

1use crate::client::GraphClient;
2use serde_json::Value;
3use std::error::Error;
4
5pub fn create_user(client: &GraphClient, body: Value) -> Result<Value, Box<dyn Error>> {
6    client.post("/users", body)
7}
8
9pub fn list_users(client: &GraphClient) -> Result<Value, Box<dyn Error>> {
10    let response = client.get("/users")?;
11    crate::pagination::fetch_all_pages(client, response)
12}
13
14pub fn get_user(client: &GraphClient, user_id: &str) -> Result<Value, Box<dyn Error>> {
15    let path = format!("/users/{}", user_id);
16    client.get(&path)
17}
18
19pub fn update_user(
20    client: &GraphClient,
21    user_id: &str,
22    body: Value,
23) -> Result<Value, Box<dyn Error>> {
24    let path = format!("/users/{}", user_id);
25    client.patch(&path, body)
26}
27
28pub fn revoke_sign_in_sessions(client: &GraphClient, user_id: &str) -> Result<Value, Box<dyn Error>> {
29    let path = format!("/users/{}/revokeSignInSessions", user_id);
30    client.post(&path, serde_json::json!({}))
31}
32
33pub fn send_mail(
34    client: &GraphClient,
35    user_id: &str,
36    body: Value,
37) -> Result<(), Box<dyn Error>> {
38    let path = format!("/users/{}/sendMail", user_id);
39
40    // Use `post_raw` to get the raw HTTP response
41    let response = client.post_raw(&path, body)?;
42
43    // Check if the response status is successful (2xx)
44    if response.status().is_success() {
45        Ok(())
46    } else {
47        Err(Box::new(std::io::Error::new(
48            std::io::ErrorKind::Other,
49            format!("Failed to send email. Status: {}", response.status()),
50        )))
51    }
52}
53