pandora_api/json/
test.rs

1/*!
2Test methods.
3*/
4// SPDX-License-Identifier: MIT AND WTFPL
5
6use pandora_api_derive::PandoraJsonRequest;
7use serde::{Deserialize, Serialize};
8
9use crate::errors::Error;
10use crate::json::{PandoraJsonApiRequest, PandoraSession};
11
12/// Check whether Pandora is available in the connecting client’s country,
13/// based on geoip database.  This is not strictly required since Partner
14/// login enforces this restriction. The request has no parameters.
15#[derive(Debug, Clone, Default, Serialize, PandoraJsonRequest)]
16#[serde(rename_all = "camelCase")]
17pub struct CheckLicensing {}
18
19impl CheckLicensing {
20    /// Create a new CheckLicensing.
21    pub fn new() -> Self {
22        Self::default()
23    }
24}
25
26///
27/// | Name    | Type  |   Description |
28/// | isAllowed |   bool     | |
29#[derive(Debug, Clone, Deserialize)]
30#[serde(rename_all = "camelCase")]
31pub struct CheckLicensingResponse {
32    /// Whether the Pandora service is available to the requesting client.
33    pub is_allowed: bool,
34}
35
36/// Convenience function to check geographic licensing restrictions.
37pub async fn check_licensing(
38    session: &mut PandoraSession,
39) -> Result<CheckLicensingResponse, Error> {
40    CheckLicensing::default().response(session).await
41}
42
43/// **Unsupported!**
44/// Undocumented method
45/// [test.echo()](https://6xq.net/pandora-apidoc/json/methods/)
46pub struct EchoUnsupported {}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51    use crate::json::{tests::session_login, Partner};
52
53    #[tokio::test]
54    async fn licensing_check_test() {
55        /*
56        flexi_logger::Logger::try_with_str("info, pandora_api=debug")
57            .expect("Failed to set logging configuration")
58            .start()
59            .expect("Failed to start logger");
60        */
61
62        let partner = Partner::default();
63        let mut session = session_login(&partner)
64            .await
65            .expect("Failed initializing login session");
66
67        let check_licensing_response = check_licensing(&mut session)
68            .await
69            .expect("Error making test.checkLicensing request");
70        log::debug!("test.checkLicensing() => {:?}", check_licensing_response);
71    }
72}