Some progress
This commit is contained in:
@@ -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"
|
||||
|
||||
1
src/lib.rs
Normal file
1
src/lib.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod station;
|
||||
43
src/station.rs
Normal file
43
src/station.rs
Normal 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,
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user