Compare commits
No commits in common. "3d02ce0efb06c884fd7d0f22e205a743584a731a" and "7b5bba7ac1c751411beda8276815168fa7e3a7ce" have entirely different histories.
3d02ce0efb
...
7b5bba7ac1
32
src/main.rs
32
src/main.rs
@ -1,12 +1,40 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
mod requester;
|
use reqwest::{self, Client};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
let api_token = env::var("TANDOOR_TOKEN").expect("Token needed");
|
let api_token = env::var("TANDOOR_TOKEN").expect("Token needed");
|
||||||
let entries = requester::fetch_shopping_list_entries(&api_token).await;
|
|
||||||
|
|
||||||
|
let base_url = env::var("TANDOOR_BASE_URL").expect("Base Url needed");
|
||||||
|
|
||||||
|
let route = "/shopping-list-entry/";
|
||||||
|
let url = format!("{}{}", base_url, route);
|
||||||
|
println!("{url}");
|
||||||
|
let client = Client::new();
|
||||||
|
|
||||||
|
let req = client
|
||||||
|
.get(&url)
|
||||||
|
.query(&[("checked", "false")])
|
||||||
|
.bearer_auth(api_token);
|
||||||
|
|
||||||
|
match req.send().await {
|
||||||
|
Ok(resolved) => match resolved.status() {
|
||||||
|
reqwest::StatusCode::OK => {
|
||||||
|
//println!("Success {:#?}", resolved);
|
||||||
|
println!("{}", resolved.text().await.unwrap())
|
||||||
|
}
|
||||||
|
reqwest::StatusCode::FORBIDDEN => {
|
||||||
|
println!("Denied {:#?}", resolved)
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
println!("Fail {:#?}", resolved);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(failed) => {
|
||||||
|
println!("There was an error in the reqwest: {failed}")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
use reqwest::{self, Client};
|
|
||||||
use std::env;
|
|
||||||
pub async fn fetch_shopping_list_entries(api_token: &str) {
|
|
||||||
let base_url = env::var("TANDOOR_BASE_URL").expect("Base Url needed");
|
|
||||||
|
|
||||||
let route = "/shopping-list-entry/";
|
|
||||||
let url = format!("{}{}", base_url, route);
|
|
||||||
let client = Client::new();
|
|
||||||
let req = client
|
|
||||||
.get(&url)
|
|
||||||
.query(&[("checked", "false")])
|
|
||||||
.bearer_auth(api_token);
|
|
||||||
match req.send().await {
|
|
||||||
Ok(resolved) => match resolved.status() {
|
|
||||||
reqwest::StatusCode::OK => {
|
|
||||||
//println!("Success {:#?}", resolved);
|
|
||||||
println!("{}", resolved.text().await.unwrap());
|
|
||||||
println!("Watch me")
|
|
||||||
}
|
|
||||||
reqwest::StatusCode::FORBIDDEN => {
|
|
||||||
println!("Denied {:#?}", resolved)
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
println!("Fail {:#?}", resolved);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(failed) => {
|
|
||||||
println!("There was an error in the reqwest: {failed}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user