strike_api/requests/
accounts.rs1
2use crate::errors::{LNError};
3use crate::types::{Account};
4
5use crate::requests::request::{Requestable};
6
7pub struct AccountHandleRequest<'a> {
8 pub api_key: &'a str,
9 pub handle: &'a str,
10 pub environment: &'a str,
11 pub api_version: &'a str,
12}
13
14impl<'a> Requestable for AccountHandleRequest<'a> {
15
16 fn get_api_key(&self) -> &str {
17 self.api_key
18 }
19
20 fn get_url(&self) -> String {
21 format!(
22 "https://{}/{}/accounts/handle/{}/profile",
23 self.environment, self.api_version, self.handle
24 )
25 }
26}
27
28impl<'a> From<(&'a str, &'a str)> for AccountHandleRequest<'a> {
29 fn from((api_key, handle): (&'a str, &'a str)) -> Self {
30 AccountHandleRequest {
31 api_key,
32 handle: handle,
33 environment: "api.strike.me",
34 api_version: "v1",
35 }
36 }
37}
38
39pub async fn get_account_by_handle<'a, A>(rates_request: A) -> Result<Account, LNError>
40where
41 A: Into<AccountHandleRequest<'a>>,
42{
43 let rates_request = rates_request.into();
44 rates_request.get::<Account>().await
45}
46
47
48#[cfg(test)]
49mod test {
50 use tokio;
51 use super::*;
52 use crate::test::utils::{get_api_key};
53
54 #[tokio::test]
55 async fn test_get_account_by_handel() {
56 let api_key= get_api_key();
57 let account_handle_request = get_account_by_handle((&api_key[..], "magog")).await;
58 println!("{:?}", account_handle_request);
59 assert!(account_handle_request.is_ok());
60 }
61}