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
use crate::{handle_error, ErrorResponse, Result, Tarkov, PROD_ENDPOINT};

use crate::profile::Side;
use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct FriendResponse {
    #[serde(flatten)]
    error: ErrorResponse,
    data: Option<Friends>,
}

/// Friend list
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct Friends {
    /// Friends
    pub friends: Vec<Friend>,
    /// Muted friend IDs
    pub ignore: Vec<String>,
    /// ?
    pub in_ignore_list: Vec<String>,
}

/// Friend
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct Friend {
    /// Friend ID
    #[serde(rename = "_id")]
    pub id: String,
    /// Friend info
    pub info: Info,
}

/// Friend info
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct Info {
    /// Friend nickname
    pub nickname: String,
    /// Friend side
    pub side: Side,
    /// Friend level
    pub level: u64,
    /// ?
    pub member_category: String,
}

impl Tarkov {
    /// Get a list of account's friends.
    pub async fn get_friends(&self) -> Result<Friends> {
        let url = format!("{}/client/friend/list", PROD_ENDPOINT);
        let res: FriendResponse = self.post_json(&url, &{}).await?;

        handle_error(res.error, res.data)
    }
}