1mod api;
2pub mod domain;
3mod errors;
4
5use api::authent::builder::Oauth2AuthentBuilder;
6pub use api::authent::oauth2::{Authent, Verify};
7pub(crate) type Result<T> = std::result::Result<T, EveEsiError>;
8
9pub use api::client::ApiClient;
10
11pub use api::characters;
12pub use api::market;
13pub use api::search;
14pub use api::universe;
15pub use api::wallet;
16pub use domain::typedef::*;
17pub use errors::EveEsiError;
18
19#[derive(Clone)]
39pub struct EveApi {
40 client: ApiClient,
41 character: Verify,
42}
43
44pub struct EveApiParam<'a> {
45 pub client_id: String,
46 pub client_secret: String,
47 pub scopes: Vec<&'a str>,
48 pub token_path: Option<String>,
49}
50
51impl EveApi {
52 pub async fn new(params: EveApiParam<'_>) -> Result<Self> {
53 let mut auth_builder = Oauth2AuthentBuilder::new(params.client_id, params.client_secret)
54 .with_scopes(params.scopes);
55 if let Some(token) = params.token_path {
56 auth_builder = auth_builder.with_token_path(&token);
57 }
58
59 let mut auth = auth_builder.build();
60
61 auth.authenticate().await?;
62 let character = auth.verify().await?;
63 let client = ApiClient::new(auth.get_authent()?);
64
65 Ok(EveApi { client, character })
66 }
67
68 pub fn client(&self) -> &ApiClient {
69 &self.client
70 }
71
72 pub fn character(&self) -> &Verify {
73 &self.character
74 }
75}