nadeo_api/lib.rs
1//! This crate provides an interface for working with the [Nadeo API](https://webservices.openplanet.dev/).
2//! It handles (re)authentication automatically.
3//!
4//! # Getting started
5//!
6//! At first, you need to create a [`NadeoClient`] to execute [`NadeoRequest`]s.
7//! You will need to provide credentials for at least one authentication method and a `UserAgent`.
8//!
9//! ```rust
10//! # use nadeo_api::NadeoClient;
11//!
12//! let mut client = NadeoClient::builder()
13//! .with_normal_auth("ubisoft_account_email", "ubisoft_account_password")
14//! .with_server_auth("my_username", "my_password")
15//! .with_oauth("my_identifier", "my_secret")
16//! .user_agent("Testing the API / my.email@gmail.com")
17//! .build()
18//! .await?;
19//! ```
20//!
21//! Use [`NadeoRequest::builder`] to create a `NadeoRequestBuilder`.
22//! To create a [`NadeoRequest`] you will need to supply:
23//! - an [`AuthType`]:
24//! - The depends on the API endpoint you want to make a request to.
25//! If the endpoint requires `AuthType::NadeoServices` or `AuthType::NadeoLiveServices` you need to build the [`NadeoClient`] with `NadeoClientBuilder::with_normal_auth()`.
26//! If the endpoint requires `AuthType::OAuth` you need to build the [`NadeoClient`] with `NadeoClientBuilder::with_oauth()`.
27//! - an `URL`
28//! - a [`Method`]
29//!
30//! For more information about the API endpoints look [here](https://webservices.openplanet.dev/).
31//!
32//! ```rust
33//! # use nadeo_api::{NadeoClient, NadeoRequest};
34//! # use nadeo_api::auth::AuthType;
35//! # use nadeo_api::request::Method;
36//!
37//! let mut client = NadeoClient::builder()
38//! .with_normal_auth("ubisoft_account_email", "ubisoft_account_password")
39//! .with_oauth("my_identifier", "my_secret")
40//! .user_agent("Testing the API / my.email@gmail.com")
41//! .build()
42//! .await?;
43//!
44//! let request = NadeoRequest::builder()
45//! .auth_type(AuthType::NadeoServices)
46//! .url("some_url")
47//! .method(Method::GET)
48//! .build()?;
49//! ```
50//!
51//! To execute the request use:
52//!
53//! ```rust
54//! let res = client.execute(request).await?;
55//! ```
56//!
57//! [`Method`]: request::Method
58//! [`AuthType::NadeoServices`]: auth::AuthType::NadeoServices
59//! [`AuthType::NadeoLiveServices`]: auth::AuthType::NadeoLiveServices
60//! [`AuthType::OAuth`]: auth::AuthType::OAuth
61//! [`AuthType`]: auth::AuthType
62//! [`NadeoClientBuilder::with_normal_auth()`]: client::client_builder::NadeoClientBuilder::with_normal_auth
63//! [`NadeoClientBuilder::with_oauth_auth()`]: client::client_builder::NadeoClientBuilder::with_oauth
64
65pub mod auth;
66pub mod client;
67pub mod error;
68pub mod request;
69
70pub use error::{Error, Result};
71
72pub use client::NadeoClient;
73pub use request::NadeoRequest;