Skip to main content

nerva/clients/donki/
rbe.rs

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