Skip to content

Commit

Permalink
rename Service to Authtype
Browse files Browse the repository at this point in the history
  • Loading branch information
TgZ39 committed May 3, 2024
1 parent e8531e4 commit da59634
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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<Self> {
pub(crate) async fn new(service: AuthType, ticket: &str, client: &Client) -> Result<Self> {
let mut headers = HeaderMap::new();
headers.insert("Content-Type", "application/json".parse().unwrap());

Expand Down
10 changes: 5 additions & 5 deletions src/client/client_builder.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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()));

Expand All @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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};
///
Expand All @@ -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()?;
///
Expand All @@ -75,21 +75,21 @@ impl NadeoClient {
/// [`NadeoClient`]: NadeoClient
pub async fn execute(&mut self, request: NadeoRequest) -> Result<Response> {
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 {
Expand Down
8 changes: 4 additions & 4 deletions src/request/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::auth::Service;
use crate::auth::AuthType;
use crate::request::request_builder::NadeoRequestBuilder;

pub use reqwest::header::HeaderMap;
Expand All @@ -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()?;
///
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/request/request_builder.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -9,9 +9,9 @@ use serde::{Deserialize, Serialize};
///
/// [`NadeoRequest`]: NadeoRequest
/// [`HttpMethod`]: HttpMethod
/// [`Service`]: Service
/// [`Service`]: AuthType
pub struct NadeoRequestBuilder {
service: Option<Service>,
service: Option<AuthType>,
url: Option<String>,
method: Option<HttpMethod>,
headers: HeaderMap,
Expand All @@ -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 {
Expand Down Expand Up @@ -73,7 +73,7 @@ impl NadeoRequestBuilder {
///
/// [`NadeoRequest`]: NadeoRequest
/// [`HttpMethod`]: HttpMethod
/// [`Service`]: Service
/// [`Service`]: AuthType
pub fn build(self) -> Result<NadeoRequest> {
if self.url.is_none() {
return Err(Error::from(RequestBuilderError::MissingUrl));
Expand Down

0 comments on commit da59634

Please sign in to comment.