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
//! # Remote.it API Wrapper

// Enable all features for the documentation tests
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, doc(cfg(all())))]

use crate::credentials::Credentials;
use bon::builder;

#[cfg(feature = "async")]
pub mod api_async;
#[cfg(feature = "blocking")]
pub mod api_blocking;

// If neither the `async` nor `blocking` features are enabled, then the `auth` module is not needed.
#[cfg(any(feature = "async", feature = "blocking"))]
mod auth;
pub mod credentials;
#[cfg(feature = "credentials_loader")]
mod credentials_loader;
pub mod operations;

/// Base path for the remote.it API.
pub const BASE_URL: &str = "https://api.remote.it";

/// Path for the GraphQL API. Append this to [`BASE_URL`] to get the full URL.
pub const GRAPHQL_PATH: &str = "/graphql/v1";

/// Path for file uploads. Append this to [`BASE_URL`] to get the full URL.
pub const FILE_UPLOAD_PATH: &str = "/graphql/v1/file/upload";

/// A client for the remote.it API.
/// 
/// # Example
/// You can instantiate a new [`R3Client`] using the builder pattern:
/// ```
/// # use remoteit_api::R3Client;
/// # use remoteit_api::credentials::Credentials;
///
/// let credentials = Credentials::load_from_disk().call().unwrap().take_profile("default").unwrap().unwrap();
/// let client = R3Client::builder().credentials(credentials).build();
/// // Start making API calls
/// let devices = client.get_devices().call().unwrap();
/// ```
#[builder]
pub struct R3Client {
    credentials: Credentials,
}

impl R3Client {
    /// # Returns
    /// A reference to the credentials used by the client.
    #[must_use]
    pub fn credentials(&self) -> &Credentials {
        &self.credentials
    }
}