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
62
63
64
65
66
67
68
69
70
71
72
73
//! Account endpoint handler.
//!
//! <https://api.mangadex.org/swagger.html#/Account>

mod activate;
mod check_username_available;
mod complete_recovery;
mod create;
mod recover;
mod resend_activation_code;

use crate::v5::account::activate::ActivateAccountBuilder;
use crate::v5::account::check_username_available::CheckUsernameAvailableBuilder;
use crate::v5::account::complete_recovery::CompleteAccountRecoveryBuilder;
use crate::v5::account::create::CreateAccountBuilder;
use crate::v5::account::recover::RecoverAccountBuilder;
use crate::v5::account::resend_activation_code::ResendActivationCodeBuilder;
use crate::HttpClientRef;

/// Account endpoint handler builder.
#[derive(Debug)]
pub struct AccountBuilder {
    http_client: HttpClientRef,
}

impl AccountBuilder {
    #[doc(hidden)]
    pub(crate) fn new(http_client: HttpClientRef) -> Self {
        Self { http_client }
    }

    /// Create a new MangaDex account.
    ///
    /// <https://api.mangadex.org/swagger.html#/Account/post-account-create>
    pub fn create(&self) -> CreateAccountBuilder {
        CreateAccountBuilder::default().http_client(self.http_client.clone())
    }

    /// Activate a MangaDex account after creating one.
    ///
    /// <https://api.mangadex.org/swagger.html#/Account/get-account-activate-code>
    pub fn activate(&self) -> ActivateAccountBuilder {
        ActivateAccountBuilder::default().http_client(self.http_client.clone())
    }

    /// Resend the account activation code.
    ///
    /// <https://api.mangadex.org/swagger.html#/Account/post-account-activate-resend>
    pub fn resend_activation_code(&self) -> ResendActivationCodeBuilder {
        ResendActivationCodeBuilder::default().http_client(self.http_client.clone())
    }

    /// Initiate the account recovery process.
    ///
    /// <https://api.mangadex.org/swagger.html#/Account/post-account-recover>
    pub fn recover(&self) -> RecoverAccountBuilder {
        RecoverAccountBuilder::default().http_client(self.http_client.clone())
    }

    /// Complete the account recovery process.
    ///
    /// <https://api.mangadex.org/swagger.html#/Account/post-account-recover-code>
    pub fn complete_recovery(&self) -> CompleteAccountRecoveryBuilder {
        CompleteAccountRecoveryBuilder::default().http_client(self.http_client.clone())
    }

    /// Check if an account username is available.
    ///
    /// <https://api.mangadex.org/swagger.html#/Account/get-account-available>
    pub fn check_username_available(&self) -> CheckUsernameAvailableBuilder {
        CheckUsernameAvailableBuilder::default().http_client(self.http_client.clone())
    }
}