hifirs_qobuz_api/
lib.rs

1use serde::{Deserialize, Serialize};
2use snafu::prelude::*;
3
4extern crate pretty_env_logger;
5#[macro_use]
6extern crate log;
7
8pub mod client;
9
10pub const TEST_TEMP_PATH: &str = "/tmp/hifirs_test";
11
12pub type Result<T, E = Error> = std::result::Result<T, E>;
13
14#[derive(Debug, Snafu)]
15pub enum Error {
16    #[snafu(display("No username provided."))]
17    NoPassword,
18    #[snafu(display("No password provided."))]
19    NoUsername,
20    #[snafu(display("No audio quality provided."))]
21    NoQuality,
22    #[snafu(display("Failed to get a usable secret from Qobuz."))]
23    ActiveSecret,
24    #[snafu(display("Failed to get an app id from Qobuz."))]
25    AppID,
26    #[snafu(display("Failed to login."))]
27    Login,
28    #[snafu(display("Authorization missing."))]
29    Authorization,
30    #[snafu(display("Failed to create client"))]
31    Create,
32    #[snafu(display("{message}"))]
33    Api { message: String },
34    #[snafu(display("Failed to deserialize json: {message}"))]
35    DeserializeJSON { message: String },
36}
37
38impl From<reqwest::Error> for Error {
39    fn from(error: reqwest::Error) -> Self {
40        let status = error.status();
41
42        match status {
43            Some(status) => Error::Api {
44                message: status.to_string(),
45            },
46            None => Error::Api {
47                message: "Error calling the API".to_string(),
48            },
49        }
50    }
51}
52
53#[derive(Clone, Debug, Serialize, Deserialize)]
54pub struct Credentials {
55    pub username: Option<String>,
56    pub password: Option<String>,
57}