Some progress

This commit is contained in:
2022-05-21 18:18:06 +02:00
parent accf773900
commit 755acf3c34
3 changed files with 47 additions and 2 deletions

View File

@@ -6,11 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
reqwest = { version = "0.11", features = ["json", "cookies"] }
[[bin]] [[bin]]
name = "vodafone-runner" name = "vodafone_runner"
path = "src/main.rs" path = "src/main.rs"
[lib] [lib]
name = "vodafone-api" name = "vodafone_api"
path = "src/lib.rs" path = "src/lib.rs"

1
src/lib.rs Normal file
View File

@@ -0,0 +1 @@
pub mod station;

43
src/station.rs Normal file
View File

@@ -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,
}
}
}
}