diff --git a/Cargo.toml b/Cargo.toml index 3c36529..3fab193 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,11 +6,12 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +reqwest = { version = "0.11", features = ["json", "cookies"] } [[bin]] -name = "vodafone-runner" +name = "vodafone_runner" path = "src/main.rs" [lib] -name = "vodafone-api" +name = "vodafone_api" path = "src/lib.rs" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..8cd4114 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1 @@ +pub mod station; diff --git a/src/station.rs b/src/station.rs new file mode 100644 index 0000000..4a124f1 --- /dev/null +++ b/src/station.rs @@ -0,0 +1,43 @@ +pub mod station { + pub use reqwest::Client; + use reqwest::header; + use std::time::Duration; + + #[derive(Debug)] + pub struct VodafoneStation { + host: String, + client: Client, + session_id: String, + nonce: String, + csrf_nonce: String, + init_vector: String, + salt: String, + key: String, + cookie: String, + } + + impl VodafoneStation { + pub fn new(host: String) -> Self { + let mut headers = header::HeaderMap::new(); + headers.insert("X-Requested-With", header::HeaderValue::from_static("XMLHttpRequest")); + headers.insert(header::REFERER, + header::HeaderValue::from_str(&format!("http://{}/?overview", host)) + .expect("Host name is not valid ASCII!")); + headers.insert(header::ORIGIN, + header::HeaderValue::from_str(&format!("http://{}", host)) + .expect("Host name is not valid ASCII!")); + + let client = Client::builder() + .default_headers(headers) + .user_agent("Mozilla/5.0 (Windows NT 6.1; rv:91.0) Gecko/20100101 Firefox/91.0") + .cookie_store(true) + .timeout(Duration::from_secs(10)) + .build().expect("Could not construct reqwest client."); + + VodafoneStation { + host: host, + + } + } + } +}