titanium_http/
monetization.rs

1use crate::error::HttpError;
2use crate::HttpClient;
3use titanium_model::{Entitlement, Sku, Snowflake};
4
5impl HttpClient {
6    /// List SKUs for an application.
7    pub async fn list_skus(&self, application_id: Snowflake) -> Result<Vec<Sku>, HttpError> {
8        self.get(&format!("/applications/{}/skus", application_id))
9            .await
10    }
11
12    /// List entitlements for an application.
13    pub async fn list_entitlements(
14        &self,
15        application_id: Snowflake,
16        query: Option<&serde_json::Value>,
17    ) -> Result<Vec<Entitlement>, HttpError> {
18        let route = format!("/applications/{}/entitlements", application_id);
19
20        if let Some(q) = query {
21            self.get_with_query(&route, q).await
22        } else {
23            self.get(&route).await
24        }
25    }
26
27    /// Get an entitlement.
28    pub async fn get_entitlement(
29        &self,
30        application_id: Snowflake,
31        entitlement_id: Snowflake,
32    ) -> Result<Entitlement, HttpError> {
33        self.get(&format!(
34            "/applications/{}/entitlements/{}",
35            application_id, entitlement_id
36        ))
37        .await
38    }
39
40    /// Create a test entitlement.
41    pub async fn create_test_entitlement(
42        &self,
43        application_id: Snowflake,
44        payload: &serde_json::Value,
45    ) -> Result<Entitlement, HttpError> {
46        self.post(
47            &format!("/applications/{}/entitlements", application_id),
48            payload,
49        )
50        .await
51    }
52
53    /// Delete a test entitlement.
54    pub async fn delete_test_entitlement(
55        &self,
56        application_id: Snowflake,
57        entitlement_id: Snowflake,
58    ) -> Result<(), HttpError> {
59        self.delete(&format!(
60            "/applications/{}/entitlements/{}",
61            application_id, entitlement_id
62        ))
63        .await
64    }
65}