use std::collections::HashMap; use reqwest::header::HeaderMap; use crate::{ constants::{app_version, web_user_agent}, locker::LockerServiceUUID, }; use super::{crypto::CustomerKeySeed, LockerDevice}; use serde::{self, Deserialize, Serialize}; pub struct LockerClient { client: reqwest::Client, } pub struct LockerSession { api_client: reqwest::Client, } impl LockerClient { pub async fn new() -> Self { LockerClient { client: reqwest::ClientBuilder::new() .default_headers(headers()) .user_agent(user_agent()) .build() .unwrap(), } } pub async fn open_session( &self, device: LockerDevice, seed: &CustomerKeySeed, ) -> LockerSession { let request = LoginCustomerRequest { device_id: seed.device_id.as_ref().unwrap().clone(), firmware_version: todo!(), postnumber: seed.postnumber.clone(), signature: todo!(), tlv_message: todo!(), uuid: todo!(), }; } } fn user_agent() -> String { format!("LPS Consumer SDK/2.1.0 okhttp/4.9.1 {}", web_user_agent()) } fn headers() -> HeaderMap { let aaa = vec![ /* ("accept", "application/json") */ ("app-version", app_version()), ("device-os", "Android"), ("device-key", ""), /* is the android id... */ ]; let mut map = HeaderMap::new(); for bbb in aaa { map.append(bbb.0, bbb.1.parse().unwrap()); } map } fn endpoint_auth_login_customer() -> &'static str { "https://packstation.de/lpsAuth/auth/loginCustomer" } fn endpoint_service_session(locker_uuid: &str) -> String { format!( "https://packstation.de/lpsService/customer/v31/locker/{}/session", locker_uuid ) } #[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct LoginCustomerRequest { device_id: String, firmware_version: String, postnumber: String, signature: String, tlv_message: String, uuid: String, } #[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct LoginCustomerResponse { access_token: String, refresh_token: String, } #[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct LockerMetadata { firmware_version: String, } #[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct Command { lps_command_string: String, } #[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct SessionRequest { locker: LockerMetadata, } #[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct LpsState { open_compartments: Vec, opened_compartments: Vec, } #[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct SessionResponse { lps_command_string: String, lps_state: LpsState, response_required: bool, }