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