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
impl Client
Sourcepub fn new(api_key: &str) -> Self
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.
Sourcepub fn builder(api_key: impl Into<String>) -> ClientBuilder
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.
Sourcepub async fn ping(&self) -> Result<()>
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.
Sourcepub async fn health(&self) -> Result<()>
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.
Sourcepub async fn get_id(&self) -> Result<String>
pub async fn get_id(&self) -> Result<String>
Returns the ID of the current device. This endpoint
does not require a valid api_key.
Sourcepub async fn get_events(&self, tx: Sender<Event>, skip_old: bool) -> Result<()>
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.
Sourcepub async fn get_configuration(&self) -> Result<Configuration>
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.
Sourcepub async fn post_folder(
&self,
folder: impl Into<NewFolderConfiguration>,
) -> Result<()>
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.
Sourcepub async fn add_folder(
&self,
folder: impl Into<NewFolderConfiguration>,
) -> Result<()>
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.
Sourcepub async fn get_folder(&self, folder_id: &str) -> Result<FolderConfiguration>
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.
Sourcepub async fn post_device(
&self,
device: impl Into<NewDeviceConfiguration>,
) -> Result<()>
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.
Sourcepub async fn add_device(
&self,
device: impl Into<NewDeviceConfiguration>,
) -> Result<()>
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.
Sourcepub async fn get_device(&self, device_id: &str) -> Result<DeviceConfiguration>
pub async fn get_device(&self, device_id: &str) -> Result<DeviceConfiguration>
Gets the configuration for the device with the ID device_id.
Sourcepub async fn get_pending_devices(&self) -> Result<PendingDevices>
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.
Sourcepub async fn get_pending_folders(&self) -> Result<PendingFolders>
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.
Sourcepub async fn delete_pending_device(&self, device_id: &str) -> Result<()>
pub async fn delete_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.
Sourcepub async fn delete_pending_folder(
&self,
folder_id: &str,
device_id: Option<&str>,
) -> Result<()>
pub async fn delete_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.
Sourcepub async fn get_default_device(&self) -> Result<DeviceConfiguration>
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.
Sourcepub async fn get_default_folder(&self) -> Result<FolderConfiguration>
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.