Skip to main content

egs_api/api/
account.rs

1use crate::api::error::EpicAPIError;
2use crate::api::types::account::{AccountData, AccountInfo, ExternalAuth};
3use crate::api::types::entitlement::Entitlement;
4use crate::api::types::friends::Friend;
5use crate::api::EpicAPI;
6
7impl EpicAPI {
8    /// Fetch account details for the logged-in user.
9    pub async fn account_details(&mut self) -> Result<AccountData, EpicAPIError> {
10        let id = match &self.user_data.account_id {
11            Some(id) => id,
12            None => return Err(EpicAPIError::InvalidParams),
13        };
14        let url = format!(
15            "https://account-public-service-prod03.ol.epicgames.com/account/api/public/account/{}",
16            id
17        );
18        self.authorized_get_json(&url).await
19    }
20
21    /// Fetch display names for a list of account IDs.
22    pub async fn account_ids_details(
23        &mut self,
24        ids: Vec<String>,
25    ) -> Result<Vec<AccountInfo>, EpicAPIError> {
26        if ids.is_empty() {
27            return Err(EpicAPIError::InvalidParams);
28        }
29        let url = format!(
30            "https://account-public-service-prod03.ol.epicgames.com/account/api/public/account?accountId={}",
31            ids.join("&accountId=")
32        );
33        self.authorized_get_json(&url).await
34    }
35
36    /// Fetch the friends list, optionally including pending requests.
37    pub async fn account_friends(
38        &mut self,
39        include_pending: bool,
40    ) -> Result<Vec<Friend>, EpicAPIError> {
41        let id = match &self.user_data.account_id {
42            Some(id) => id,
43            None => return Err(EpicAPIError::InvalidParams),
44        };
45        let url = format!(
46            "https://friends-public-service-prod06.ol.epicgames.com/friends/api/public/friends/{}?includePending={}",
47            id, include_pending
48        );
49        self.authorized_get_json(&url).await
50    }
51
52    /// Fetch all entitlements for the logged-in user.
53    pub async fn user_entitlements(&self) -> Result<Vec<Entitlement>, EpicAPIError> {
54        let url = match &self.user_data.account_id {
55            None => {
56                return Err(EpicAPIError::InvalidCredentials);
57            }
58            Some(id) => {
59                format!("https://entitlement-public-service-prod08.ol.epicgames.com/entitlement/api/account/{}/entitlements?start=0&count=5000",
60                        id)
61            }
62        };
63        self.authorized_get_json(&url).await
64    }
65
66    /// Fetch external auth connections for an account.
67    pub async fn external_auths(
68        &self,
69        account_id: &str,
70    ) -> Result<Vec<ExternalAuth>, EpicAPIError> {
71        let url = format!(
72            "https://account-public-service-prod03.ol.epicgames.com/account/api/public/account/{}/externalAuths",
73            account_id
74        );
75        self.authorized_get_json(&url).await
76    }
77
78    /// Fetch SSO domain list for Epic accounts.
79    pub async fn sso_domains(&self) -> Result<Vec<String>, EpicAPIError> {
80        self.authorized_get_json(
81            "https://account-public-service-prod03.ol.epicgames.com/account/api/epicdomains/ssodomains",
82        )
83        .await
84    }
85}