use dotenv::dotenv;
use std::env;
use serde::Deserialize;
#[derive(Deserialize)]
pub struct User {
pub id: u64,
pub slack_id: String,
pub display_name: String,
pub avatar: String,
pub project_ids: Vec<u64>,
pub cookies: Option<u64>,
pub vote_count: u64,
pub like_count: u64,
pub devlog_seconds_total: u64,
pub devlog_seconds_today: u64,
}
#[derive(Deserialize)]
pub struct Project {
pub id: u64,
pub title: String,
pub description: String,
pub repo_url: String,
pub demo_url: String,
pub readme_url: String,
pub ai_declaration: Option<String>,
pub ship_status: String,
pub devlog_ids: Vec<u64>,
pub banner_url: Option<String>,
pub created_at: String,
pub updated_at: String,
}
fn main() {
dotenv().ok();
let ft_key = env::var("FT_KEY").expect("FT_KEY must be set");
let client = reqwest::blocking::Client::new();
let user: User = client
.get("https://flavortown.hackclub.com/api/v1/users/me")
.header("Authorization", format!("Bearer {}", ft_key))
.send()
.expect("Failed to send request")
.json()
.expect("Failed to parse JSON");
let mut projects: Vec<Project> = Vec::new();
println!("Logged in as {}", user.display_name);
let cookies_display = user
.cookies
.map_or("(undeclared)".to_string(), |count| count.to_string());
println!(
"You have {} cookies and have voted {} times.",
cookies_display, user.vote_count
);
for pid in user.project_ids {
let project: Project = client
.get(format!("https://flavortown.hackclub.com/api/v1/projects/{}", pid))
.header("Authorization", format!("Bearer {}", ft_key))
.send()
.expect("Failed to send request")
.json()
.expect("Failed to parse JSON");
projects.push(project);
}
println!(
"Your projects are: {}",
projects
.iter()
.map(|p| p.title.as_str())
.collect::<Vec<_>>()
.join(", ")
);
}