diff --git a/src/auth/mod.rs b/src/auth/mod.rs index 4d91d4f..f19a4e5 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -19,7 +19,7 @@ const USER_AGENT: &str = "Testing the API / badbaboimbus+ubisoft@gmail.com"; /// Defines Service which is used to authenticate with the Nadeo API. #[derive(strum::Display, Debug, Clone, Copy, Serialize, Deserialize, Eq, PartialEq)] -pub enum Service { +pub enum AuthType { #[strum(to_string = "NadeoServices")] NadeoServices, #[strum(to_string = "NadeoLiveServices")] @@ -29,13 +29,13 @@ pub enum Service { #[derive(Debug, Clone, Serialize, Deserialize)] pub(crate) struct AuthInfo { - pub service: Service, + pub service: AuthType, pub access_token: AccessToken, pub refresh_token: RefreshToken, } impl AuthInfo { - pub(crate) async fn new(service: Service, ticket: &str, client: &Client) -> Result { + pub(crate) async fn new(service: AuthType, ticket: &str, client: &Client) -> Result { let mut headers = HeaderMap::new(); headers.insert("Content-Type", "application/json".parse().unwrap()); diff --git a/src/client/client_builder.rs b/src/client/client_builder.rs index 0380481..baf37d7 100644 --- a/src/client/client_builder.rs +++ b/src/client/client_builder.rs @@ -1,5 +1,5 @@ use crate::auth::o_auth::OAuthInfo; -use crate::auth::{AuthInfo, Service}; +use crate::auth::{AuthInfo, AuthType}; use crate::Result; use crate::{auth, Error, NadeoClient}; use derive_more::{Display, Error}; @@ -18,14 +18,14 @@ pub struct NadeoClientBuilder { } impl NadeoClientBuilder { - /// Adds credentials for using [`Service::NadeoServices`] and [`Service::NadeoLiveServices`]. + /// Adds credentials for using [`AuthType::NadeoServices`] and [`AuthType::NadeoLiveServices`]. pub fn with_normal_auth(mut self, email: &str, password: &str) -> Self { self.normal_auth = Some((email.to_string(), password.to_string())); self } - /// Adds credentials for using [`Service::OAuth`]. + /// Adds credentials for using [`AuthType::OAuth`]. pub fn with_oauth_auth(mut self, identifier: &str, secret: &str) -> Self { self.o_auth = Some((identifier.to_string(), secret.to_string())); @@ -46,8 +46,8 @@ impl NadeoClientBuilder { // request normal and live auth tokens if let Some(auth) = self.normal_auth { let ticket = auth::get_ubi_auth_ticket(&auth.0, &auth.1, &client).await?; - let normal_auth_fut = AuthInfo::new(Service::NadeoServices, &ticket, &client); - let live_auth_fut = AuthInfo::new(Service::NadeoLiveServices, &ticket, &client); + let normal_auth_fut = AuthInfo::new(AuthType::NadeoServices, &ticket, &client); + let live_auth_fut = AuthInfo::new(AuthType::NadeoLiveServices, &ticket, &client); // execute 2 futures concurrently let (n_auth, l_auth) = join(normal_auth_fut, live_auth_fut).await; diff --git a/src/client/mod.rs b/src/client/mod.rs index a5d5d32..10cd616 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1,6 +1,6 @@ use crate::auth::o_auth::OAuthInfo; -use crate::auth::{AuthInfo, Service}; +use crate::auth::{AuthInfo, AuthType}; use crate::request::NadeoRequest; use crate::{Error, Result}; @@ -52,7 +52,7 @@ impl NadeoClient { /// /// Gets the clubtag of a player given the *accountID*. /// ```rust - /// # use nadeo_api::auth::Service; + /// # use nadeo_api::auth::AuthType; /// # use nadeo_api::NadeoClient; /// # use nadeo_api::request::{HttpMethod, NadeoRequest}; /// @@ -62,7 +62,7 @@ impl NadeoClient { /// // build request /// let request = NadeoRequest::builder() /// .url("https://prod.trackmania.core.nadeo.online/accounts/clubTags/?accountIdList=29e75531-1a9d-4880-98da-e2acfe17c578".to_string()) - /// .service(Service::NadeoServices) + /// .service(AuthType::NadeoServices) /// .http_method(HttpMethod::Get) /// .build()?; /// @@ -75,21 +75,21 @@ impl NadeoClient { /// [`NadeoClient`]: NadeoClient pub async fn execute(&mut self, request: NadeoRequest) -> Result { match request.service { - Service::NadeoServices => { + AuthType::NadeoServices => { if let Some(auth) = &mut self.normal_auth { auth.execute(request, &self.client).await } else { Err(Error::from(ClientError::MissingNadeoAuth)) } } - Service::NadeoLiveServices => { + AuthType::NadeoLiveServices => { if let Some(auth) = &mut self.live_auth { auth.execute(request, &self.client).await } else { Err(Error::from(ClientError::MissingNadeoAuth)) } } - Service::OAuth => { + AuthType::OAuth => { if let Some(auth) = &mut self.o_auth { auth.execute(request, &self.client).await } else { diff --git a/src/request/mod.rs b/src/request/mod.rs index 5ae8545..98c7a07 100644 --- a/src/request/mod.rs +++ b/src/request/mod.rs @@ -1,4 +1,4 @@ -use crate::auth::Service; +use crate::auth::AuthType; use crate::request::request_builder::NadeoRequestBuilder; pub use reqwest::header::HeaderMap; @@ -15,14 +15,14 @@ pub mod request_builder; /// /// Gets the clubtag of a player given the *accountID*. /// ```rust -/// # use nadeo_api::auth::Service; +/// # use nadeo_api::auth::AuthType; /// # use nadeo_api::request::{HttpMethod, NadeoRequest}; /// /// let mut client = //snap; /// /// let request = NadeoRequest::builder() /// .url("https://prod.trackmania.core.nadeo.online/accounts/clubTags/?accountIdList=29e75531-1a9d-4880-98da-e2acfe17c578".to_string()) -/// .service(Service::NadeoServices) +/// .service(AuthType::NadeoServices) /// .http_method(HttpMethod::Get) /// .build()?; /// @@ -33,7 +33,7 @@ pub mod request_builder; /// [`NadeoRequestBuilder`]: NadeoRequestBuilder #[derive(Debug, Clone)] pub struct NadeoRequest { - pub(crate) service: Service, + pub(crate) service: AuthType, pub(crate) url: String, pub(crate) method: HttpMethod, pub(crate) headers: HeaderMap, diff --git a/src/request/request_builder.rs b/src/request/request_builder.rs index 5856e67..28e09e6 100644 --- a/src/request/request_builder.rs +++ b/src/request/request_builder.rs @@ -1,4 +1,4 @@ -use crate::auth::Service; +use crate::auth::AuthType; use crate::request::{HttpMethod, NadeoRequest}; use crate::{Error, Result}; use reqwest::header::{HeaderMap, IntoHeaderName}; @@ -9,9 +9,9 @@ use serde::{Deserialize, Serialize}; /// /// [`NadeoRequest`]: NadeoRequest /// [`HttpMethod`]: HttpMethod -/// [`Service`]: Service +/// [`Service`]: AuthType pub struct NadeoRequestBuilder { - service: Option, + service: Option, url: Option, method: Option, headers: HeaderMap, @@ -30,7 +30,7 @@ macro_rules! builder_fn { builder_fn!(NadeoRequestBuilder, url, url, String); builder_fn!(NadeoRequestBuilder, method, http_method, HttpMethod); -builder_fn!(NadeoRequestBuilder, service, service, Service); +builder_fn!(NadeoRequestBuilder, service, service, AuthType); impl Default for NadeoRequestBuilder { fn default() -> Self { @@ -73,7 +73,7 @@ impl NadeoRequestBuilder { /// /// [`NadeoRequest`]: NadeoRequest /// [`HttpMethod`]: HttpMethod - /// [`Service`]: Service + /// [`Service`]: AuthType pub fn build(self) -> Result { if self.url.is_none() { return Err(Error::from(RequestBuilderError::MissingUrl));