Skip to main content

egs_api/facade/
cosmos.rs

1use crate::EpicGames;
2use crate::api::error::EpicAPIError;
3use crate::api::types::cosmos;
4
5impl EpicGames {
6    /// Set up a Cosmos cookie session from an exchange code.
7    /// Typically called with a code from `game_token()`.
8    pub async fn cosmos_session_setup(
9        &self,
10        exchange_code: &str,
11    ) -> Result<cosmos::CosmosAuthResponse, EpicAPIError> {
12        self.egs.cosmos_session_setup(exchange_code).await
13    }
14
15    /// Upgrade bearer token to Cosmos session (step 5 of session setup).
16    pub async fn cosmos_auth_upgrade(&self) -> Result<cosmos::CosmosAuthResponse, EpicAPIError> {
17        self.egs.cosmos_auth_upgrade().await
18    }
19
20    /// Check if a EULA has been accepted. Returns `None` on error.
21    pub async fn cosmos_eula_check(&self, eula_id: &str, locale: &str) -> Option<bool> {
22        self.egs
23            .cosmos_eula_check(eula_id, locale)
24            .await
25            .ok()
26            .map(|r| r.accepted)
27    }
28
29    /// Check if a EULA has been accepted. Returns full `Result`.
30    pub async fn try_cosmos_eula_check(
31        &self,
32        eula_id: &str,
33        locale: &str,
34    ) -> Result<cosmos::CosmosEulaResponse, EpicAPIError> {
35        self.egs.cosmos_eula_check(eula_id, locale).await
36    }
37
38    /// Accept a EULA. Returns `None` on error.
39    pub async fn cosmos_eula_accept(
40        &self,
41        eula_id: &str,
42        locale: &str,
43        version: u32,
44    ) -> Option<bool> {
45        self.egs
46            .cosmos_eula_accept(eula_id, locale, version)
47            .await
48            .ok()
49            .map(|r| r.accepted)
50    }
51
52    /// Accept a EULA. Returns full `Result`.
53    pub async fn try_cosmos_eula_accept(
54        &self,
55        eula_id: &str,
56        locale: &str,
57        version: u32,
58    ) -> Result<cosmos::CosmosEulaResponse, EpicAPIError> {
59        self.egs.cosmos_eula_accept(eula_id, locale, version).await
60    }
61
62    /// Get Cosmos account details. Returns `None` on error.
63    pub async fn cosmos_account(&self) -> Option<cosmos::CosmosAccount> {
64        self.egs.cosmos_account().await.ok()
65    }
66
67    /// Get Cosmos account details. Returns full `Result`.
68    pub async fn try_cosmos_account(&self) -> Result<cosmos::CosmosAccount, EpicAPIError> {
69        self.egs.cosmos_account().await
70    }
71
72    /// Check Age of Digital Consent policy. Returns `None` on error.
73    pub async fn cosmos_policy_aodc(&self) -> Option<cosmos::CosmosPolicyAodc> {
74        self.egs.cosmos_policy_aodc().await.ok()
75    }
76
77    /// Check Age of Digital Consent policy. Returns full `Result`.
78    pub async fn try_cosmos_policy_aodc(&self) -> Result<cosmos::CosmosPolicyAodc, EpicAPIError> {
79        self.egs.cosmos_policy_aodc().await
80    }
81
82    /// Check communication opt-in status. Returns `None` on error.
83    pub async fn cosmos_comm_opt_in(&self, setting: &str) -> Option<cosmos::CosmosCommOptIn> {
84        self.egs.cosmos_comm_opt_in(setting).await.ok()
85    }
86
87    /// Check communication opt-in status. Returns full `Result`.
88    pub async fn try_cosmos_comm_opt_in(
89        &self,
90        setting: &str,
91    ) -> Result<cosmos::CosmosCommOptIn, EpicAPIError> {
92        self.egs.cosmos_comm_opt_in(setting).await
93    }
94
95    /// Search unrealengine.com content. Requires an active Cosmos session.
96    ///
97    /// Returns `None` on any error.
98    pub async fn cosmos_search(
99        &self,
100        query: &str,
101        slug: Option<&str>,
102        locale: Option<&str>,
103        filter: Option<&str>,
104    ) -> Option<cosmos::CosmosSearchResults> {
105        self.try_cosmos_search(query, slug, locale, filter)
106            .await
107            .ok()
108    }
109
110    /// Like [`cosmos_search`](Self::cosmos_search), but returns a `Result` instead of swallowing errors.
111    pub async fn try_cosmos_search(
112        &self,
113        query: &str,
114        slug: Option<&str>,
115        locale: Option<&str>,
116        filter: Option<&str>,
117    ) -> Result<cosmos::CosmosSearchResults, EpicAPIError> {
118        self.egs.cosmos_search(query, slug, locale, filter).await
119    }
120}