polestar_api/models/
vehicle.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct Vehicle {
8 pub vin: String,
10
11 #[serde(rename = "internalVehicleIdentifier")]
13 pub internal_vehicle_identifier: Option<String>,
14
15 #[serde(rename = "registrationNo")]
17 pub registration_number: Option<String>,
18
19 pub market: Option<String>,
21
22 pub content: VehicleContent,
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct VehicleContent {
29 pub model: ModelInfo,
31
32 pub images: Option<Images>,
34
35 pub specification: Option<VehicleSpecifications>,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct ModelInfo {
42 pub code: Option<String>,
44
45 pub name: Option<String>,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct Images {
52 pub studio: Option<StudioImages>,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct StudioImages {
59 pub url: Option<String>,
61
62 pub angles: Option<Vec<String>>,
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68pub struct VehicleSpecifications {
69 pub motor: Option<MotorSpec>,
71
72 pub battery: Option<String>,
74
75 pub torque: Option<String>,
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
81pub struct MotorSpec {
82 pub power: Option<String>,
84
85 pub torque: Option<String>,
87
88 pub acceleration: Option<String>,
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
94pub struct BatterySpec {
95 pub capacity: Option<String>,
97
98 pub range: Option<String>,
100}
101
102#[cfg(test)]
103mod tests {
104 use super::*;
105
106 #[test]
107 fn test_vehicle_deserialization() {
108 let json = r#"{
109 "vin": "TEST123",
110 "market": "US",
111 "content": {
112 "model": {
113 "code": "P2",
114 "name": "Polestar 2"
115 }
116 }
117 }"#;
118
119 let vehicle: Vehicle = serde_json::from_str(json).unwrap();
120 assert_eq!(vehicle.vin, "TEST123");
121 assert_eq!(vehicle.market, Some("US".to_string()));
122 assert_eq!(vehicle.content.model.name, Some("Polestar 2".to_string()));
123 }
124}