Compare commits

...

2 Commits

Author SHA1 Message Date
Jef Roosens e8e73e9afe
feat: started api wrapper 2023-05-11 09:30:25 +02:00
Jef Roosens 02d5446e3e
chore: init project 2023-05-11 08:56:26 +02:00
10 changed files with 1334 additions and 0 deletions

26
.gitignore vendored 100644
View File

@ -0,0 +1,26 @@
# Created by https://www.toptal.com/developers/gitignore/api/rust,rust-analyzer
# Edit at https://www.toptal.com/developers/gitignore?templates=rust,rust-analyzer
### Rust ###
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
# Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
### rust-analyzer ###
# Can be generated by other build systems other than cargo (ex: bazelbuild/rust_rules)
rust-project.json
# End of https://www.toptal.com/developers/gitignore/api/rust,rust-analyzer

1178
Cargo.lock generated 100644

File diff suppressed because it is too large Load Diff

6
Cargo.toml 100644
View File

@ -0,0 +1,6 @@
[workspace]
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

@ -0,0 +1,10 @@
[package]
name = "affluences-api"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "0.11.17", features = ["json"] }
serde = { version = "1.0.163", features = ["derive"] }

View File

@ -0,0 +1,22 @@
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,
}
impl AffluencesClient {
pub fn new() -> Self {
Self {
client: reqwest::Client::builder()
.user_agent(USER_AGENT).build().unwrap(),
}
}
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);
}