1use serde_json::Value;
9
10pub struct Client {
11 base_url: String,
12 http: reqwest::blocking::Client,
13}
14
15impl Client {
16 pub fn new() -> Self {
17 Self {
18 base_url: "https://starfyi.com".to_string(),
19 http: reqwest::blocking::Client::new(),
20 }
21 }
22
23 fn get(&self, path: &str) -> Result<Value, Box<dyn std::error::Error>> {
24 let url = format!("{}{}", self.base_url, path);
25 let resp = self.http.get(&url).send()?.json()?;
26 Ok(resp)
27 }
28
29 pub fn search(&self, query: &str) -> Result<Value, Box<dyn std::error::Error>> {
30 let url = format!("{}/api/v1/search/?q={}", self.base_url, query);
31 let resp = self.http.get(&url).send()?.json()?;
32 Ok(resp)
33 }
34
35 pub fn list_comparisons(&self) -> Result<Value, Box<dyn std::error::Error>> {
37 self.get("/api/v1/comparisons/")
38 }
39
40 pub fn get_comparison(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
42 self.get(&format!("/api/v1/comparisons/{}/", slug))
43 }
44 pub fn list_constellations(&self) -> Result<Value, Box<dyn std::error::Error>> {
46 self.get("/api/v1/constellations/")
47 }
48
49 pub fn get_constellation(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
51 self.get(&format!("/api/v1/constellations/{}/", slug))
52 }
53 pub fn list_deep_sky(&self) -> Result<Value, Box<dyn std::error::Error>> {
55 self.get("/api/v1/deep-sky/")
56 }
57
58 pub fn get_deep_sky(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
60 self.get(&format!("/api/v1/deep-sky/{}/", slug))
61 }
62 pub fn list_exoplanets(&self) -> Result<Value, Box<dyn std::error::Error>> {
64 self.get("/api/v1/exoplanets/")
65 }
66
67 pub fn get_exoplanet(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
69 self.get(&format!("/api/v1/exoplanets/{}/", slug))
70 }
71 pub fn list_faqs(&self) -> Result<Value, Box<dyn std::error::Error>> {
73 self.get("/api/v1/faqs/")
74 }
75
76 pub fn get_faq(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
78 self.get(&format!("/api/v1/faqs/{}/", slug))
79 }
80 pub fn list_glossary(&self) -> Result<Value, Box<dyn std::error::Error>> {
82 self.get("/api/v1/glossary/")
83 }
84
85 pub fn get_term(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
87 self.get(&format!("/api/v1/glossary/{}/", slug))
88 }
89 pub fn list_glossary_categories(&self) -> Result<Value, Box<dyn std::error::Error>> {
91 self.get("/api/v1/glossary-categories/")
92 }
93
94 pub fn get_glossary_category(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
96 self.get(&format!("/api/v1/glossary-categories/{}/", slug))
97 }
98 pub fn list_guide_series(&self) -> Result<Value, Box<dyn std::error::Error>> {
100 self.get("/api/v1/guide-series/")
101 }
102
103 pub fn get_guide_sery(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
105 self.get(&format!("/api/v1/guide-series/{}/", slug))
106 }
107 pub fn list_guides(&self) -> Result<Value, Box<dyn std::error::Error>> {
109 self.get("/api/v1/guides/")
110 }
111
112 pub fn get_guide(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
114 self.get(&format!("/api/v1/guides/{}/", slug))
115 }
116 pub fn list_spectral_classes(&self) -> Result<Value, Box<dyn std::error::Error>> {
118 self.get("/api/v1/spectral-classes/")
119 }
120
121 pub fn get_spectral_classe(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
123 self.get(&format!("/api/v1/spectral-classes/{}/", slug))
124 }
125 pub fn list_stars(&self) -> Result<Value, Box<dyn std::error::Error>> {
127 self.get("/api/v1/stars/")
128 }
129
130 pub fn get_star(&self, slug: &str) -> Result<Value, Box<dyn std::error::Error>> {
132 self.get(&format!("/api/v1/stars/{}/", slug))
133 }
134}
135
136impl Default for Client {
137 fn default() -> Self { Self::new() }
138}