get_telescope/
get_telescope.rs1use lemonaid::CitraClient;
2use lemonaid::TaskStatus;
3use std::env;
4
5#[tokio::main]
6async fn main() {
7 let api_key = env::var("CITRA_PAT")
9 .expect("CITRA_PAT environment variable not set");
10
11 let client = CitraClient::new(&api_key, true);
13
14 let args: Vec<String> = env::args().collect();
16 if args.len() < 2 {
17 eprintln!("Usage: cargo run --example get_telescope <telescope-id>");
18 std::process::exit(1);
19 }
20 let telescope_id = &args[1];
21
22 println!("Fetching telescope: {}", telescope_id);
24 match client.get_telescope(telescope_id).await {
25 Ok(telescope) => {
26 println!("\n✓ Success!");
27 println!("{:#?}", telescope);
28 }
29 Err(e) => {
30 eprintln!("\n✗ Error: {}", e);
31 std::process::exit(1);
32 }
33 }
34
35 println!("\n\nFetching tasks for telescope: {}", telescope_id);
37 match client.list_tasks_for_telescope(telescope_id).await {
38 Ok(tasks) => {
39 println!("\n✓ Found {} task(s) for telescope {}", tasks.len(), telescope_id);
40 for task in tasks {
41 println!(" - Task ID: {}, Status: {:?}", task.id, task.status);
42 }
43 }
44 Err(e) => {
45 eprintln!("\n✗ Error fetching tasks for telescope: {}", e);
46 }
47 }
48
49 let status_filter = vec![TaskStatus::Pending];
51 println!("\n\nFetching tasks for telescope: {} with status: {:?}", telescope_id, status_filter);
52 match client.get_telescope_tasks_by_status(telescope_id, status_filter).await {
53 Ok(tasks) => {
54 for task in tasks {
55 println!(" - Task ID: {}, Status: {:?}", task.id, task.status);
56 }
57 }
58 Err(e) => {
59 eprintln!("\n✗ Error fetching tasks for telescope by status: {}", e);
60 }
61 }
62
63 println!("\n\nFetching all telescopes...");
65 match client.list_telescopes().await {
66 Ok(telescopes) => {
67 println!("\n✓ Found {} telescope(s)", telescopes.len());
68 for telescope in telescopes {
69 println!(" - {} ({})", telescope.name.as_deref().unwrap_or("Unknown"), telescope.id);
70 }
71 }
72 Err(e) => {
73 eprintln!("\n✗ Error listing telescopes: {}", e);
74 }
75 }
76}