eve_esi_api/
lib.rs

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/// The main struct you will use.
20/// ```
21/// let client_id = "Your OAuth2 client id".to_string();
22/// let client_secret = "Your OAuth2 client secret".to_string();
23/// let scopes = vec![
24///         "esi-characters.read_blueprints.v1",
25///         "esi-characters.read_blueprints.v1",
26///         "esi-wallet.read_character_wallet.v1",
27///         "esi-search.search_structures.v1",
28///         "esi-markets.read_character_orders.v1",
29///         "publicData",
30///     ];
31///
32/// let eve_api = eve_esi_api::EveApi::new(client_id, client_secret, scopes).await?;
33/// let char_id = eve_api.character().character_id;
34/// eve_api.wallet.transactions();
35///
36/// ```
37///
38#[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}