1pub use crate::core::{Client, Params};
2
3pub mod keys
5{
6 pub fn load() -> Result<String, Box<dyn std::error::Error>>
8 {
9 dotenv::dotenv()?;
10 std::env::var("NASA_API_KEY").map_err(|_| "NASA_API_KEY not found in .env file".into())
11 }
12 pub fn include(query: &str) -> Result<String, Box<dyn std::error::Error>>
14 {
15 let key = load()?;
16 return Ok(format!("{}&api_key={}", query, key));
17 }
18}
19
20pub mod params
22{
23 pub use crate::clients::apod::ApodParams;
24 pub use crate::clients::neo::{feed::NeoFeedParams, lookup::NeoLookupParams};
25
26 #[derive(Copy, Clone, PartialEq, Debug)]
27 pub enum DefaultParams<'p>
28 {
29 StartDate(&'p str),
30 EndDate(&'p str),
31 }
32
33 impl<'p> Default for DefaultParams<'p>
34 {
35 fn default() -> Self { Self::StartDate("2020-01-01") }
36 }
37
38 impl<'p> Into<String> for DefaultParams<'p>
39 {
40 fn into(self) -> String
41 {
42 match self
43 {
44 Self::StartDate(date) => format!("startDate={}", date),
45 Self::EndDate(date) => format!("endDate={}", date),
46 }
47 }
48 }
49
50 impl<'p> crate::core::Params for DefaultParams<'p> {}
51}
52
53#[cfg(test)]
54mod test
55{
56 use super::keys;
57
58 #[test]
59 fn load_key()
60 {
61 let key = keys::load();
62 assert!(key.is_ok());
63 println!("Key: {}", key.unwrap());
64 }
65}