psn_rs 0.1.0

Interact with PlayStation Network API in full Rust!
Documentation
use serde::Deserialize;

use crate::constants::ACCOUNT_ENDPOINT_URL;
use crate::models::user::AccountID;
use crate::{PSNApiResult, PSNClient};

impl PSNClient {
    /// Get the account ID of the authenticated user.
    pub async fn get_own_account_id(&self) -> PSNApiResult<AccountID> {
        #[derive(Deserialize)]
        struct AccountIdResponse {
            #[serde(rename = "accountId")]
            account_id: String,
        }

        let response = self
            .get_authenticated(
                format!("{ACCOUNT_ENDPOINT_URL}/v1/devices/accounts/me"),
                None,
                Option::<()>::None,
            )
            .await?;
        let account_id_response = response.json::<AccountIdResponse>().await?;
        Ok(AccountID(account_id_response.account_id))
    }
}