pub struct WattpadClient {
pub user: UserClient,
pub story: StoryClient,
/* private fields */
}
Expand description
The main asynchronous client for interacting with the Wattpad API.
This client holds the HTTP connection, manages authentication state, and provides access to categorized sub-clients for different parts of the API.
Fields§
§user: UserClient
Provides access to user-related API endpoints.
story: StoryClient
Provides access to story and part-related API endpoints.
Implementations§
Source§impl WattpadClient
impl WattpadClient
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new WattpadClient
with default settings.
This is now a convenience method that uses the builder.
Sourcepub fn builder() -> WattpadClientBuilder
pub fn builder() -> WattpadClientBuilder
Creates a new builder for configuring a WattpadClient
.
This is the new entry point for custom client creation.
Sourcepub async fn authenticate(
&self,
username: &str,
password: &str,
) -> Result<(), WattpadError>
pub async fn authenticate( &self, username: &str, password: &str, ) -> Result<(), WattpadError>
Authenticates the client using a username and password.
On a successful login, the API returns session cookies which are automatically stored in the client’s cookie store for use in subsequent requests.
§Arguments
username
- The Wattpad username.password
- The Wattpad password.
§Returns
An empty Ok(())
on successful authentication.
§Errors
Returns WattpadError::AuthenticationFailed
if login is unsuccessful.
Sourcepub async fn deauthenticate(&self) -> Result<(), WattpadError>
pub async fn deauthenticate(&self) -> Result<(), WattpadError>
Deauthenticates the client by logging out from Wattpad.
This method sends a request to the logout endpoint, which invalidates the session
cookies. It then sets the client’s internal authentication state to false
.
§Returns
An empty Ok(())
on successful logout.
§Errors
Returns a WattpadError
if the HTTP request fails.
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Checks if the client has been successfully authenticated.
§Returns
true
if authenticate
has been called successfully, false
otherwise.