Struct Client

Source
pub struct Client { /* private fields */ }
Expand description

Abstraction to interact with the Syncthing API.

The Client has various configuration values to tweak, such as the URL which is set to localhost:8384/rest by default. To configure a Client, use Client::builder().

Implementations§

Source§

impl Client

Source

pub fn new(api_key: &str) -> Self

Creates a new HTTP client, with which the syncthing API can be used.

§Panics

This method panics if the client cannot be initialized.

Use Client::builder() if you wish to handle the failure as an Error instead of panicking.

Source

pub fn builder(api_key: impl Into<String>) -> ClientBuilder

Creates a ClientBuilder to configure a Client. This is the same as ClientBuilder::new()

The API can either be generated in the GUI of Syncthing or set in the configuration file under configuration/gui/apikey.

Source

pub async fn get_connections(&self) -> Result<Connections>

Gets all the connections

Source

pub async fn ping(&self) -> Result<()>

Returns () if the syncthing API can be reached.

Use health to do the same without the need of a valid api_key.

Source

pub async fn health(&self) -> Result<()>

Returns () if the syncthing API can be reached.

Use ping to do the same but with the requirement of a valid api_key.

Source

pub async fn get_id(&self) -> Result<String>

Returns the ID of the current device. This endpoint does not require a valid api_key.

Source

pub async fn get_events(&self, tx: Sender<Event>, skip_old: bool) -> Result<()>

Only returns if an error is encountered. Transmits every new event over tx. If skip_old, all events before the call to this function do not result in a transmission.

Source

pub async fn get_configuration(&self) -> Result<Configuration>

Returns the entire Configuration

§Errors

This method fails if the API cannot be reached, the server answers with an error code or the JSON cannot be parsed.

Source

pub async fn post_folder( &self, folder: impl Into<NewFolderConfiguration>, ) -> Result<()>

Posts a folder. If the folder already exists, it is replaced, otherwise a new one is added.

Use add_folder if the operation should fail if a folder with the same ID already exists.

Source

pub async fn add_folder( &self, folder: impl Into<NewFolderConfiguration>, ) -> Result<()>

Adds a new folder. If the folder already exists, a DuplicateFolderError is returned. This requires an additional check against the API.

Use post_folder if the operation should blindly set the folder.

Source

pub async fn get_folder(&self, folder_id: &str) -> Result<FolderConfiguration>

Gets the configuration for the folder with the ID folder_id. Explicitly returns a UnknownFolderError if no folder with folder_id exists.

Source

pub async fn delete_folder(&self, folder_id: &str) -> Result<()>

Deletes the folder with the ID folder_id.

Source

pub async fn post_device( &self, device: impl Into<NewDeviceConfiguration>, ) -> Result<()>

Posts a device. If the device already exists, it is replaced, otherwise a new one is added.

Use add_device if the operation should fail if a device with the same ID already exists.

Source

pub async fn add_device( &self, device: impl Into<NewDeviceConfiguration>, ) -> Result<()>

Adds a new device. If the device already exists, a DuplicateDeviceError is returned. This requires an additional check against the API.

Use post_device if the operation should blindly set the device.

Source

pub async fn get_device(&self, device_id: &str) -> Result<DeviceConfiguration>

Gets the configuration for the device with the ID device_id.

Source

pub async fn delete_device(&self, device_id: &str) -> Result<()>

Deletes the device with the ID device_id.

Source

pub async fn get_pending_devices(&self) -> Result<PendingDevices>

Gets a list of all pending remote devices which have tried to connect but are not in our configuration yet.

Source

pub async fn get_pending_folders(&self) -> Result<PendingFolders>

Gets all folders which remote devices have offered to us, but are not yet shared from our instance to them or are not present on our instance.

Source

pub async fn dismiss_pending_device(&self, device_id: &str) -> Result<()>

Remove record about pending remote device with ID device_id which tried to connect.

This is not permanent, use ignore_device instead.

Source

pub async fn dismiss_pending_folder( &self, folder_id: &str, device_id: Option<&str>, ) -> Result<()>

Remove record about pending remote folder with ID folder_id. An optional device_id can be passed as argument to only remove the pending remote from that device, otherwise the folder will be removed as pending for all devices.

This is not permanent, use ignore_folder instead.

Source

pub async fn get_default_device(&self) -> Result<DeviceConfiguration>

Returns a template device configuration with all default values, which only requires a unique device ID to be instantiated.

Source

pub async fn get_default_folder(&self) -> Result<FolderConfiguration>

Returns a template folder configuration with all default values, which only requires a unique folder ID to be instantiated.

Source

pub async fn get_completion( &self, folder_id: Option<&str>, device_id: Option<&str>, ) -> Result<Completion>

Calculates the data synchronization completion percentage and counts.

Returns the completion percentage (0 to 100), total bytes, and total items.

§Arguments
  • folder_id - The ID of the folder to calculate completion for. None calculates the aggregate completion across all folders.
  • device_id - The ID of the device to calculate completion for. None calculates the aggregate completion across all devices. If device_id is specified but folder_id is None, completion is calculated for all folders shared with that device.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Client

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,