extract http access to requester mod
This commit is contained in:
		
							
								
								
									
										31
									
								
								src/requester.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								src/requester.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
			
		||||
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}")
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user