nerva/clients/epic/
epic_client.rs1use crate::core::Client;
2use std::error::Error;
3
4#[doc = "EPIC API client"]
5#[derive(Debug, Clone)]
6pub struct EPIC {}
7
8impl Default for EPIC
9{
10 fn default() -> Self { EPIC {} }
11}
12
13#[allow(missing_docs)]
14impl EPIC
15{
16 pub fn new() -> Self { EPIC::default() }
17}
18
19impl<'p, P> Client<P> for EPIC
20where
21 P: crate::core::Params,
22{
23 const BASE_URL: &'static str = "https://api.nasa.gov/EPIC/api";
24 type Response = serde_json::Value;
25
26 fn get(&self, params: P) -> Result<Self::Response, Box<dyn Error>>
27 {
28 let base_url = <EPIC as Client<P>>::BASE_URL;
29 let url_with_params = format!("{}/{}", base_url, params.into());
30 let url_with_key = crate::prelude::keys::include(&url_with_params)?;
31 let response = ureq::get(&url_with_key).call()?;
32 let json = serde_json::json!(response.into_string()?);
33 return Ok(json);
34 }
35}
36
37#[cfg(test)]
38mod epic_tests
39{
40 use super::*;
41 use crate::clients::epic::epic_parameters::EPICParams as EpicParams;
42
43 #[test]
44 fn test_epic_client()
45 {
46 let epic = EPIC::default();
47 let params = EpicParams::NaturalAll;
48 let response = epic.get(params);
49 match response
50 {
51 Ok(json) => println!("{:#?}", json),
52 Err(e) =>
53 {
54 println!("{:#?}", e);
55 panic!()
56 }
57 }
58 }
59}