diff --git a/.woodpecker/clippy.yml b/.woodpecker/clippy.yml index 92851e5..c100904 100644 --- a/.woodpecker/clippy.yml +++ b/.woodpecker/clippy.yml @@ -7,5 +7,4 @@ pipeline: clippy: image: 'rust:1.69' commands: - - rustup component add clippy - cargo clippy -- --no-deps -Dwarnings diff --git a/.woodpecker/lint.yml b/.woodpecker/lint.yml index ad2b612..01065f8 100644 --- a/.woodpecker/lint.yml +++ b/.woodpecker/lint.yml @@ -7,5 +7,4 @@ pipeline: lint: image: 'rust:1.69' commands: - - rustup component add rustfmt - cargo fmt -- --check diff --git a/Cargo.lock b/Cargo.lock index 5d0a985..afa86eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,16 +18,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "affluences-cli" -version = "0.1.0" -dependencies = [ - "affluences-api", - "clap", - "serde_json", - "tokio", -] - [[package]] name = "affy" version = "0.1.0" @@ -48,55 +38,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anstream" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is-terminal", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" - -[[package]] -name = "anstyle-parse" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" -dependencies = [ - "windows-sys 0.48.0", -] - -[[package]] -name = "anstyle-wincon" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" -dependencies = [ - "anstyle", - "windows-sys 0.48.0", -] - [[package]] name = "async-trait" version = "0.1.68" @@ -203,48 +144,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "clap" -version = "4.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34d21f9bf1b425d2968943631ec91202fe5e837264063503708b83013f8fc938" -dependencies = [ - "clap_builder", - "clap_derive", - "once_cell", -] - -[[package]] -name = "clap_builder" -version = "4.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "914c8c79fb560f238ef6429439a30023c862f7a28e688c58f7203f12b29970bd" -dependencies = [ - "anstream", - "anstyle", - "bitflags", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 2.0.15", -] - -[[package]] -name = "clap_lex" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" - [[package]] name = "codespan-reporting" version = "0.11.1" @@ -255,12 +154,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "colorchoice" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" - [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -418,27 +311,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "errno" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" -dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "flate2" version = "1.0.26" @@ -587,12 +459,6 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "hermit-abi" version = "0.2.6" @@ -602,12 +468,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hermit-abi" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" - [[package]] name = "http" version = "0.2.9" @@ -729,35 +589,12 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "io-lifetimes" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" -dependencies = [ - "hermit-abi 0.3.1", - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "ipnet" version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" -[[package]] -name = "is-terminal" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" -dependencies = [ - "hermit-abi 0.3.1", - "io-lifetimes", - "rustix", - "windows-sys 0.48.0", -] - [[package]] name = "itoa" version = "1.0.6" @@ -788,12 +625,6 @@ dependencies = [ "cc", ] -[[package]] -name = "linux-raw-sys" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f" - [[package]] name = "lock_api" version = "0.4.9" @@ -881,7 +712,7 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi", "libc", ] @@ -1107,20 +938,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "rustix" -version = "0.37.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" -dependencies = [ - "bitflags", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys", - "windows-sys 0.48.0", -] - [[package]] name = "rustls" version = "0.20.8" @@ -1615,12 +1432,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - [[package]] name = "uuid" version = "1.3.2" diff --git a/Cargo.toml b/Cargo.toml index eea9b1e..e07b19a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,5 @@ members = [ "affluences-api", - "affluences-cli", "bot", ] diff --git a/affluences-api/API.md b/affluences-api/API.md index 708641e..fc0ecd0 100644 --- a/affluences-api/API.md +++ b/affluences-api/API.md @@ -1,45 +1,3 @@ -# Affluences API Reference - -## Terminology - -* `site` - * General name for a location/institution - * Defined by a UUID and a slug, e.g. `ghent-university` - * Can contain one more or more sites, e.g. - `ghent-university-library-book-tower` is a child of `ghent-university` - -## Notes - -The API checks for browser user agents, so your requests should include a valid -user agent of a modern browser. - -## API Routes - -### Search for sites - -`GET https://api.affluences.com/app/v3/sites` - -**Body format** - -```json -{ - "selected_categories": [ - 1 - ], - "page": 0, - "search_query": "university of ghent" -} -``` - -**Response format** - -`Data>` - -### Retrieve time table for a given site - -`GET https://reservation.affluences.com/api/sites/4737e57a-ee05-4f7b-901a-7bb541eeb297` - - 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 diff --git a/affluences-api/src/lib.rs b/affluences-api/src/lib.rs index 3e11326..17c7ace 100644 --- a/affluences-api/src/lib.rs +++ b/affluences-api/src/lib.rs @@ -20,15 +20,6 @@ impl AffluencesClient { } } - pub async fn search(&self, query: String) -> reqwest::Result { - let url = "https://api.affluences.com/app/v3/sites"; - let body = SiteSearch{ - search_query: query - }; - - Ok(self.client.post(url).json(&body).send().await?.json::>().await?.data) - } - pub async fn available( &self, site_id: uuid::Uuid, diff --git a/affluences-api/src/models/site_data.rs b/affluences-api/src/models/site_data.rs index c2a7d98..1d13a22 100644 --- a/affluences-api/src/models/site_data.rs +++ b/affluences-api/src/models/site_data.rs @@ -1,24 +1,24 @@ -use serde::{Serialize, Deserialize}; +use serde::Deserialize; -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct Data { pub data: T, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct SiteDataCategory { pub id: u32, pub name: String, pub name_plural: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct SiteDataLocationCoordinates { pub latitude: f64, pub longitude: f64, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct SiteDataLocationAddress { pub route: String, pub city: String, @@ -27,47 +27,47 @@ pub struct SiteDataLocationAddress { pub country_code: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct SiteDataLocation { pub coordinates: SiteDataLocationCoordinates, pub address: SiteDataLocationAddress, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct SiteDataForecast { pub opened: bool, - pub occupancy: Option, + pub occupancy: u32, // waiting_time pub waiting_time_overflow: bool, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct SiteDataNotice { pub message: String, pub url: Option, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct SiteDataService { pub id: u32, pub name: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct SiteDataInfo { pub title: String, pub description: String, pub url: Option, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct SiteDataStatus { pub state: String, pub text: String, pub color: String, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Deserialize, Debug)] pub struct SiteData { pub id: uuid::Uuid, pub slug: String, @@ -104,15 +104,3 @@ pub struct SiteData { #[serde(rename = "publicationStatus")] pub publication_status: String, } - -#[derive(Serialize, Debug)] -pub struct SiteSearch { - pub search_query: String -} - -#[derive(Serialize, Deserialize, Debug)] -pub struct SiteSearchResponse { - pub page: u32, - pub max_size: u32, - pub results: Vec -} diff --git a/affluences-cli/Cargo.toml b/affluences-cli/Cargo.toml deleted file mode 100644 index f46a340..0000000 --- a/affluences-cli/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "affluences-cli" -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" } -clap = { version = "4.2.7", features = ["derive"] } -serde_json = "1.0.96" -tokio = { version = "1.28.1", features = ["full"] } diff --git a/affluences-cli/src/main.rs b/affluences-cli/src/main.rs deleted file mode 100644 index 3b31cb5..0000000 --- a/affluences-cli/src/main.rs +++ /dev/null @@ -1,30 +0,0 @@ -use affluences_api::AffluencesClient; -use clap::{Parser, Subcommand}; - -#[derive(Parser)] -#[command(author, version, about, long_about = None)] -struct Cli { - #[command(subcommand)] - command: Option, -} - -#[derive(Subcommand)] -enum Commands { - /// does testing things - SearchSite { query: String }, -} - -#[tokio::main] -async fn main() { - let cli = Cli::parse(); - let client = AffluencesClient::new(); - - match &cli.command { - Some(Commands::SearchSite { query }) => { - let res = client.search(query.to_string()).await.unwrap(); - let s = serde_json::to_string_pretty(&res).unwrap(); - println!("{}", s); - } - None => {} - } -} diff --git a/bot/src/commands.rs b/bot/src/commands.rs index 6a2c548..60d82d5 100644 --- a/bot/src/commands.rs +++ b/bot/src/commands.rs @@ -158,5 +158,3 @@ pub async fn available(ctx: Context<'_>, date: NaiveDate) -> Result<(), Error> { // ctx: Context<'_>, // date: NaiveDate, // ) -> Result<(), Error> { - -// }