pub struct Client { /* private fields */ }Expand description
An aria2 websocket rpc client.
§Example
use aria2_ws::Client;
#[tokio::main]
async fn main() {
let client = Client::connect("ws://127.0.0.1:6800/jsonrpc", None)
.await
.unwrap();
let version = client.get_version().await.unwrap();
println!("{:?}", version);
}Implementations§
Source§impl Client
impl Client
Sourcepub async fn connect(url: &str, token: Option<&str>) -> Result<Self, Error>
pub async fn connect(url: &str, token: Option<&str>) -> Result<Self, Error>
Create a new Client that connects to the given url.
§Example
use aria2_ws::Client;
#[tokio::main]
async fn main() {
let client = Client::connect("ws://127.0.0.1:6800/jsonrpc", None)
.await
.unwrap();
let gid = client
.add_uri(
vec!["https://go.dev/dl/go1.17.6.windows-amd64.msi".to_string()],
None,
None,
None,
)
.await
.unwrap();
client.force_remove(&gid).await.unwrap();
}Source§impl Client
impl Client
pub async fn add_uri( &self, uris: Vec<String>, options: Option<TaskOptions>, position: Option<u32>, callbacks: Option<Callbacks>, ) -> Result<String, Error>
pub async fn add_torrent( &self, torrent: impl AsRef<[u8]>, uris: Option<Vec<String>>, options: Option<TaskOptions>, position: Option<u32>, callbacks: Option<Callbacks>, ) -> Result<String, Error>
pub async fn add_metalink( &self, metalink: impl AsRef<[u8]>, options: Option<TaskOptions>, position: Option<u32>, callbacks: Option<Callbacks>, ) -> Result<String, Error>
Methods from Deref<Target = InnerClient>§
Sourcepub async fn call(
&self,
id: i32,
method: &str,
params: Vec<Value>,
) -> Result<(), Error>
pub async fn call( &self, id: i32, method: &str, params: Vec<Value>, ) -> Result<(), Error>
Send a rpc request to websocket without waiting for response.
Sourcepub async fn call_and_wait<T>(
&self,
method: &str,
params: Vec<Value>,
) -> Result<T, Error>where
T: DeserializeOwned + Send,
pub async fn call_and_wait<T>(
&self,
method: &str,
params: Vec<Value>,
) -> Result<T, Error>where
T: DeserializeOwned + Send,
Send a rpc request to websocket and wait for corresponding response.
Sourcepub fn subscribe_notifications(&self) -> Receiver<Notification>
pub fn subscribe_notifications(&self) -> Receiver<Notification>
Subscribe to notifications.
Returns a instance of broadcast::Receiver which can be used to receive notifications.
pub async fn get_version(&self) -> Result<Version, Error>
pub async fn remove(&self, gid: &str) -> Result<(), Error>
pub async fn force_remove(&self, gid: &str) -> Result<(), Error>
pub async fn pause(&self, gid: &str) -> Result<(), Error>
pub async fn pause_all(&self) -> Result<(), Error>
pub async fn force_pause(&self, gid: &str) -> Result<(), Error>
pub async fn force_pause_all(&self) -> Result<(), Error>
pub async fn unpause(&self, gid: &str) -> Result<(), Error>
pub async fn unpause_all(&self) -> Result<(), Error>
pub async fn custom_tell_status( &self, gid: &str, keys: Option<Vec<String>>, ) -> Result<Map<String, Value>, Error>
pub async fn tell_status(&self, gid: &str) -> Result<Status, Error>
pub async fn get_uris(&self, gid: &str) -> Result<Vec<Uri>, Error>
pub async fn get_files(&self, gid: &str) -> Result<Vec<File>, Error>
pub async fn get_peers(&self, gid: &str) -> Result<Vec<Peer>, Error>
pub async fn get_servers( &self, gid: &str, ) -> Result<Vec<GetServersResult>, Error>
pub async fn tell_active(&self) -> Result<Vec<Status>, Error>
pub async fn tell_waiting( &self, offset: i32, num: i32, ) -> Result<Vec<Status>, Error>
pub async fn tell_stopped( &self, offset: i32, num: i32, ) -> Result<Vec<Status>, Error>
pub async fn custom_tell_active( &self, keys: Option<Vec<String>>, ) -> Result<Vec<Map<String, Value>>, Error>
pub async fn custom_tell_waiting( &self, offset: i32, num: i32, keys: Option<Vec<String>>, ) -> Result<Vec<Map<String, Value>>, Error>
pub async fn custom_tell_stopped( &self, offset: i32, num: i32, keys: Option<Vec<String>>, ) -> Result<Vec<Map<String, Value>>, Error>
pub async fn change_position( &self, gid: &str, pos: i32, how: PositionHow, ) -> Result<i32, Error>
Sourcepub async fn change_uri(
&self,
gid: &str,
file_index: i32,
del_uris: Vec<String>,
add_uris: Vec<String>,
position: Option<i32>,
) -> Result<(i32, i32), Error>
pub async fn change_uri( &self, gid: &str, file_index: i32, del_uris: Vec<String>, add_uris: Vec<String>, position: Option<i32>, ) -> Result<(i32, i32), Error>
§Returns
This method returns a list which contains two integers.
The first integer is the number of URIs deleted. The second integer is the number of URIs added.
pub async fn get_option(&self, gid: &str) -> Result<TaskOptions, Error>
pub async fn change_option( &self, gid: &str, options: TaskOptions, ) -> Result<(), Error>
pub async fn get_global_option(&self) -> Result<TaskOptions, Error>
pub async fn change_global_option( &self, options: TaskOptions, ) -> Result<(), Error>
pub async fn get_global_stat(&self) -> Result<GlobalStat, Error>
pub async fn purge_download_result(&self) -> Result<(), Error>
pub async fn remove_download_result(&self, gid: &str) -> Result<(), Error>
pub async fn get_session_info(&self) -> Result<SessionInfo, Error>
pub async fn shutdown(&self) -> Result<(), Error>
pub async fn force_shutdown(&self) -> Result<(), Error>
pub async fn save_session(&self) -> Result<(), Error>
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more