rspotify_model/
device.rs

1use crate::DeviceType;
2use serde::{Deserialize, Serialize};
3
4/// Device object
5#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
6pub struct Device {
7    pub id: Option<String>,
8    pub is_active: bool,
9    pub is_private_session: bool,
10    pub is_restricted: bool,
11    pub name: String,
12    #[serde(rename = "type")]
13    pub _type: DeviceType,
14    pub volume_percent: Option<u32>,
15}
16
17/// Intermediate device payload object
18#[derive(Deserialize)]
19pub struct DevicePayload {
20    pub devices: Vec<Device>,
21}
22
23#[test]
24fn test_devices() {
25    let json_str = r#"
26        {
27            "devices" : [ {
28                "id" : "5fbb3ba6aa454b5534c4ba43a8c7e8e45a63ad0e",
29                "is_active" : false,
30                "is_private_session": true,
31                "is_restricted" : false,
32                "name" : "My fridge",
33                "type" : "Computer",
34                "volume_percent" : 100
35            } ]
36        }
37"#;
38    let payload: DevicePayload = serde_json::from_str(json_str).unwrap();
39    assert_eq!(payload.devices[0]._type, DeviceType::Computer)
40}