subsonic-types 0.2.0

Types for the Subsonic API
Documentation
use subsonic_types::{
    common::{MediaType, Seconds, Version},
    response::{Child, Playlist, PlaylistWithSongs, Response, ResponseBody},
};

#[test]
fn get_playlist() {
    let response = Response::from_json(include_str!("get-playlist.json")).unwrap();
    let expected = Response::ok(
        Version::V1_16_1,
        ResponseBody::Playlist(PlaylistWithSongs {
            playlist: Playlist {
                id: "2402328c-2c31-4475-ad3a-a698884edefb".into(),
                name: "2023-02-27".into(),
                comment: None,
                owner: Some("admin".into()),
                public: Some(false),
                song_count: 2,
                duration: Seconds::new(522),
                created: "2023-02-27T16:00:43.404089728Z".parse().unwrap(),
                changed: "2023-02-27T16:00:43Z".parse().unwrap(),
                cover_art: Some("pl-2402328c-2c31-4475-ad3a-a698884edefb_63fcd3ab".into()),
                allowed_user: vec![],
            },
            entry: vec![
                Child {
                    id: "928838508700ef99318e42dff9407eee".into(),
                    parent: Some("67b96a9d6611f9765bd11db4ffa42a28".into()),
                    is_dir: false,
                    title: "Draw the Line".into(),
                    album: Some("Draw the Line".into()),
                    artist: Some("Haywyre".into()),
                    track: Some(1),
                    year: Some(2012),
                    genre: None,
                    cover_art: Some("al-67b96a9d6611f9765bd11db4ffa42a28_0".into()),
                    size: Some(10303833),
                    content_type: Some("audio/mpeg".into()),
                    suffix: Some("mp3".into()),
                    transcoded_content_type: None,
                    transcoded_suffix: None,
                    duration: Some(Seconds::new(257)),
                    bit_rate: Some(320),
                    path: Some("Haywyre/Draw the Line/01 - Draw the Line.mp3".into()),
                    is_video: Some(false),
                    user_rating: None,
                    average_rating: None,
                    play_count: None,
                    disc_number: Some(1),
                    created: Some("2023-02-19T14:06:49.266174771Z".parse().unwrap()),
                    starred: None,
                    album_id: Some("67b96a9d6611f9765bd11db4ffa42a28".into()),
                    artist_id: Some("57fd6b271014d8b0a2fcb9124b143b53".into()),
                    media_type: Some(MediaType::Music),
                    bookmark_position: None,
                    original_width: None,
                    original_height: None,
                },
                Child {
                    id: "c523795f3a0af45a94c9d99f34b76603".into(),
                    parent: Some("67b96a9d6611f9765bd11db4ffa42a28".into()),
                    is_dir: false,
                    title: "Erase It".into(),
                    album: Some("Draw the Line".into()),
                    artist: Some("Haywyre".into()),
                    track: Some(2),
                    year: Some(2012),
                    genre: None,
                    cover_art: Some("al-67b96a9d6611f9765bd11db4ffa42a28_0".into()),
                    size: Some(10647261),
                    content_type: Some("audio/mpeg".into()),
                    suffix: Some("mp3".into()),
                    transcoded_content_type: None,
                    transcoded_suffix: None,
                    duration: Some(Seconds::new(265)),
                    bit_rate: Some(320),
                    path: Some("Haywyre/Draw the Line/02 - Erase It.mp3".into()),
                    is_video: Some(false),
                    user_rating: None,
                    average_rating: None,
                    play_count: None,
                    disc_number: Some(1),
                    created: Some("2023-02-19T14:06:49.26620826Z".parse().unwrap()),
                    starred: None,
                    album_id: Some("67b96a9d6611f9765bd11db4ffa42a28".into()),
                    artist_id: Some("57fd6b271014d8b0a2fcb9124b143b53".into()),
                    media_type: Some(MediaType::Music),
                    bookmark_position: None,
                    original_width: None,
                    original_height: None,
                },
            ],
        }),
    );
    assert_eq!(response, expected);
}