nerva/clients/donki/
ips.rs1use crate::prelude::params::DefaultParams;
2use crate::prelude::*;
3use std::error::Error;
4
5pub type ISPParams<'p> = DefaultParams<'p>;
6
7#[derive(Debug, Clone)]
8pub struct ISP {}
9
10impl Default for ISP
11{
12 fn default() -> Self { Self {} }
13}
14
15impl ISP
16{
17 pub fn new() -> Self { Self::default() }
18}
19
20impl<'p, PARAMS> Client<PARAMS> for ISP
21where
22 PARAMS: Params,
23{
24 const BASE_URL: &'static str = "https://api.nasa.gov/DONKI/IPS";
25 type Response = serde_json::Value;
26
27 fn get(&self, params: PARAMS) -> Result<Self::Response, Box<dyn Error>>
28 {
29 let base_url = <ISP as Client<PARAMS>>::BASE_URL;
30 let url_with_params = format!("{}?{}", base_url, params.into());
31 let url_with_key = keys::include(&url_with_params)?;
32 let response = ureq::get(&url_with_key).call()?;
33 let json = serde_json::json!(response.into_string()?);
34 Ok(json)
35 }
36}
37
38#[cfg(test)]
39mod isp_test
40{
41 use super::*;
42
43 #[test]
44 fn test_isp()
45 {
46 let isp = ISP::new();
47 let params = ISPParams::default();
48 let response = isp.get(params).unwrap();
49 println!("{:#?}", response);
50 }
51}