Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session close #37

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ jobs:
args: --release --all-features

- name: Cargo Test
uses: actions-rs/cargo@v1
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- run: cargo test -- --skip session_close

- name: Cargo Test Session Close
uses: actions-rs/toolchain@v1
with:
command: test
toolchain: stable
- run: cargo test -- session_close
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: [![Donate button](https://www.paypalobjects.com/en_US/DK/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=H337RKJSC4YG4&source=url)
26 changes: 26 additions & 0 deletions examples/session-close.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 37 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/types/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
4 changes: 4 additions & 0 deletions src/types/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down