mirror of
https://github.com/kristoferssolo/transmission-rpc.git
synced 2025-10-21 20:10:37 +00:00
Add session-close.
This commit is contained in:
parent
d114bda4ca
commit
1e603ff839
11
.github/workflows/ci.yml
vendored
11
.github/workflows/ci.yml
vendored
@ -41,6 +41,13 @@ jobs:
|
||||
args: --release --all-features
|
||||
|
||||
- name: Cargo Test
|
||||
uses: actions-rs/cargo@v1
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
command: test
|
||||
toolchain: stable
|
||||
- run: cargo test -- --skip session_close
|
||||
|
||||
- name: Cargo Test Session Close
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
- run: cargo test -- session_close
|
||||
|
||||
@ -31,7 +31,7 @@ spec: https://github.com/transmission/transmission/blob/master/extras/rpc-spec.t
|
||||
- [X] session-stats
|
||||
- [X] blocklist-update
|
||||
- [X] port-test
|
||||
- [ ] session-close
|
||||
- [X] session-close
|
||||
- [X] free-space
|
||||
|
||||
Support the project: [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=H337RKJSC4YG4&source=url)
|
||||
|
||||
26
examples/session-close.rs
Normal file
26
examples/session-close.rs
Normal file
@ -0,0 +1,26 @@
|
||||
extern crate transmission_rpc;
|
||||
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
use transmission_rpc::types::{BasicAuth, Result, RpcResponse, SessionClose};
|
||||
use transmission_rpc::TransClient;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
dotenv().ok();
|
||||
env_logger::init();
|
||||
let url = env::var("TURL")?;
|
||||
let client;
|
||||
if let (Ok(user), Ok(password)) = (env::var("TUSER"), env::var("TPWD")) {
|
||||
client = TransClient::with_auth(&url, BasicAuth {user, password});
|
||||
} else {
|
||||
client = TransClient::new(&url);
|
||||
}
|
||||
let response: Result<RpcResponse<SessionClose>> = client.session_close().await;
|
||||
match response {
|
||||
Ok(_) => println!("Yay!"),
|
||||
Err(_) => panic!("Oh no!")
|
||||
}
|
||||
println!("Rpc response is ok: {}", response?.is_ok());
|
||||
Ok(())
|
||||
}
|
||||
37
src/lib.rs
37
src/lib.rs
@ -12,6 +12,7 @@ use types::BasicAuth;
|
||||
use types::BlocklistUpdate;
|
||||
use types::SessionGet;
|
||||
use types::SessionStats;
|
||||
use types::SessionClose;
|
||||
use types::PortTest;
|
||||
use types::FreeSpace;
|
||||
use types::TorrentAction;
|
||||
@ -151,6 +152,42 @@ impl TransClient {
|
||||
self.call(RpcRequest::session_stats()).await
|
||||
}
|
||||
|
||||
/// Performs a session close call
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Any IO Error or Deserialization error
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// extern crate transmission_rpc;
|
||||
///
|
||||
/// use std::env;
|
||||
/// use dotenv::dotenv;
|
||||
/// use transmission_rpc::TransClient;
|
||||
/// use transmission_rpc::types::{Result, RpcResponse, BasicAuth, SessionClose};
|
||||
///
|
||||
/// #[tokio::main]
|
||||
/// async fn main() -> Result<()> {
|
||||
/// dotenv().ok();
|
||||
/// env_logger::init();
|
||||
/// let url= env::var("TURL")?;
|
||||
/// let basic_auth = BasicAuth{user: env::var("TUSER")?, password: env::var("TPWD")?};
|
||||
/// let client = TransClient::with_auth(&url, basic_auth);
|
||||
/// let response: Result<RpcResponse<SessionClose>> = client.session_close().await;
|
||||
/// match response {
|
||||
/// Ok(_) => println!("Yay!"),
|
||||
/// Err(_) => panic!("Oh no!")
|
||||
/// }
|
||||
/// println!("Rpc response is ok: {}", response?.is_ok());
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn session_close(&self) -> Result<RpcResponse<SessionClose>> {
|
||||
self.call(RpcRequest::session_close()).await
|
||||
}
|
||||
|
||||
/// Performs a blocklist update call
|
||||
///
|
||||
/// # Errors
|
||||
|
||||
@ -22,6 +22,7 @@ pub use self::response::RpcResponse;
|
||||
pub(crate) use self::response::RpcResponseArgument;
|
||||
pub use self::response::SessionGet;
|
||||
pub use self::response::SessionStats;
|
||||
pub use self::response::SessionClose;
|
||||
pub use self::response::BlocklistUpdate;
|
||||
pub use self::response::PortTest;
|
||||
pub use self::response::FreeSpace;
|
||||
|
||||
@ -23,6 +23,13 @@ impl RpcRequest {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn session_close() -> RpcRequest {
|
||||
RpcRequest {
|
||||
method: String::from("session-close"),
|
||||
arguments: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn blocklist_update() -> RpcRequest {
|
||||
RpcRequest {
|
||||
method: String::from("blocklist-update"),
|
||||
|
||||
@ -46,6 +46,10 @@ pub struct SessionStats {
|
||||
}
|
||||
impl RpcResponseArgument for SessionStats {}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct SessionClose {}
|
||||
impl RpcResponseArgument for SessionClose {}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct BlocklistUpdate {
|
||||
#[serde(rename = "blocklist-size")]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user