feat: started api wrapper

dev
Jef Roosens 2023-05-11 09:30:25 +02:00
parent 02d5446e3e
commit e8e73e9afe
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
8 changed files with 217 additions and 11 deletions

109
Cargo.lock generated
View File

@ -28,6 +28,14 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bot"
version = "0.1.0"
dependencies = [
"affluences-api",
"tokio",
]
[[package]]
name = "bumpalo"
version = "3.12.2"
@ -201,6 +209,15 @@ version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hermit-abi"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
dependencies = [
"libc",
]
[[package]]
name = "hermit-abi"
version = "0.3.1"
@ -313,7 +330,7 @@ version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220"
dependencies = [
"hermit-abi",
"hermit-abi 0.3.1",
"libc",
"windows-sys 0.48.0",
]
@ -357,6 +374,16 @@ version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f"
[[package]]
name = "lock_api"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.17"
@ -402,6 +429,16 @@ dependencies = [
"tempfile",
]
[[package]]
name = "num_cpus"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
dependencies = [
"hermit-abi 0.2.6",
"libc",
]
[[package]]
name = "once_cell"
version = "1.17.1"
@ -452,6 +489,29 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.2.16",
"smallvec",
"windows-sys 0.45.0",
]
[[package]]
name = "percent-encoding"
version = "2.2.0"
@ -494,6 +554,15 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags",
]
[[package]]
name = "redox_syscall"
version = "0.3.5"
@ -569,6 +638,12 @@ dependencies = [
"windows-sys 0.42.0",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "security-framework"
version = "2.8.2"
@ -635,6 +710,15 @@ dependencies = [
"serde",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
dependencies = [
"libc",
]
[[package]]
name = "slab"
version = "0.4.8"
@ -644,6 +728,12 @@ dependencies = [
"autocfg",
]
[[package]]
name = "smallvec"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]]
name = "socket2"
version = "0.4.9"
@ -673,7 +763,7 @@ checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998"
dependencies = [
"cfg-if",
"fastrand",
"redox_syscall",
"redox_syscall 0.3.5",
"rustix",
"windows-sys 0.45.0",
]
@ -703,11 +793,26 @@ dependencies = [
"bytes",
"libc",
"mio",
"num_cpus",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.48.0",
]
[[package]]
name = "tokio-macros"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tokio-native-tls"
version = "0.3.1"

View File

@ -2,4 +2,5 @@
members = [
"affluences-api",
"bot",
]

View File

@ -0,0 +1,26 @@
curl -L 'https://api.affluences.com/app/v3/sites/ghent-university' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0'
returnt lijst van alle bibliotheken op ugent, inclusief de uuids die dan nodig zijn om de specifieke requests te sturen naar die bib zijn stuff
curl -L 'https://api.affluences.com/app/v3/timetables/4737e57a-ee05-4f7b-901a-7bb541eeb297?offset=0' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0'
returnt de time table voor die bib
https://reservation.affluences.com/api/sites/4737e57a-ee05-4f7b-901a-7bb541eeb297
Basisinformatie voor s5 bib
https://reservation.affluences.com/api/resources/4737e57a-ee05-4f7b-901a-7bb541eeb297?type=1
returnt lijst van mogelijke lokalen voor s5
https://reservation.affluences.com/api/resources/4737e57a-ee05-4f7b-901a-7bb541eeb297/available?date=2023-05-11&type=1
returnt momenten die nog vrij zijn voor gegeven datum
pretty sure da die type 1 slaat op da et een bib is
https://api.affluences.com/app/v3/sites
body: {"selected_categories":[1],"page":0,"search_query":"university of ghent"}
zoek op alle mogelijke bibs, met een search query

View File

@ -1,14 +1,22 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
mod models;
use models::Resource;
const USER_AGENT: &str = "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0";
pub struct AffluencesClient {
client: reqwest::Client,
}
#[cfg(test)]
mod tests {
use super::*;
impl AffluencesClient {
pub fn new() -> Self {
Self {
client: reqwest::Client::builder()
.user_agent(USER_AGENT).build().unwrap(),
}
}
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
pub async fn available(&mut self) -> reqwest::Result<Vec<Resource>> {
self.client.get("https://reservation.affluences.com/api/resources/026b8caa-d310-464f-b714-4c21a2cf98ea/available?date=2023-05-11&type=1").send().await?.json::<Vec<Resource>>().await
}
}

View File

@ -0,0 +1,40 @@
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Debug)]
pub struct Hour {
pub hour: String,
pub state: u32,
// reservations
pub granularity: u32,
pub person_count: u32,
pub places_available: u32,
pub places_bookable: u32,
}
#[derive(Deserialize, Debug)]
pub struct Resource {
pub resource_id: u32,
pub resource_name: String,
pub resource_type: u32,
pub granularity: u32,
pub time_slot_count: u32,
pub static_time_slot: bool,
// reservations_by_timeslot
pub note_available: bool,
pub note_required: bool,
pub note_description: String,
pub description: String,
pub capacity: u32,
pub site_timezone: String,
pub user_name_required: bool,
pub user_phone_required: bool,
pub user_name_available: bool,
pub user_phone_available: bool,
// time_before_reservations_closed
// min_places_per_reservation
// max_places_per_reservation
pub image_url: Option<String>,
// services
pub slots_state: u32,
pub hours: Vec<Hour>,
}

10
bot/Cargo.toml 100644
View File

@ -0,0 +1,10 @@
[package]
name = "bot"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
affluences-api = { path = "../affluences-api" }
tokio = { version = "1.28.1", features = ["full"] }

8
bot/src/main.rs 100644
View File

@ -0,0 +1,8 @@
use affluences_api::AffluencesClient;
#[tokio::main]
async fn main() {
let mut client = AffluencesClient::new();
let res = client.available().await.unwrap();
println!("{:?}", res);
}

8
main.rs 100644
View File

@ -0,0 +1,8 @@
use reqwest;
type Response = Vec<Resource>;
fn main() {
let res = reqwest::blocking::get("https://reservation.affluences.com/api/resources/026b8caa-d310-464f-b714-4c21a2cf98ea/available?date=2023-05-11&type=1").unwrap().json::<Response>().unwrap();
println!("{:?}", res);
}