mirror of
https://github.com/kristoferssolo/transmission-rpc.git
synced 2025-10-21 20:10:37 +00:00
Add blocklist-update.
This commit is contained in:
parent
bf0cb365d9
commit
301a0c43c1
@ -29,7 +29,7 @@ spec: https://github.com/transmission/transmission/blob/master/extras/rpc-spec.t
|
|||||||
- [ ] session-set
|
- [ ] session-set
|
||||||
- [X] session-get
|
- [X] session-get
|
||||||
- [X] session-stats
|
- [X] session-stats
|
||||||
- [ ] blocklist-update
|
- [X] blocklist-update
|
||||||
- [ ] port-test
|
- [ ] port-test
|
||||||
- [ ] session-close
|
- [ ] session-close
|
||||||
- [ ] free-space
|
- [ ] free-space
|
||||||
|
|||||||
26
examples/blocklist-update.rs
Normal file
26
examples/blocklist-update.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
extern crate transmission_rpc;
|
||||||
|
|
||||||
|
use dotenv::dotenv;
|
||||||
|
use std::env;
|
||||||
|
use transmission_rpc::types::{BasicAuth, BlocklistUpdate, Result, RpcResponse};
|
||||||
|
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<BlocklistUpdate>> = client.blocklist_update().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
@ -9,6 +9,7 @@ use serde::de::DeserializeOwned;
|
|||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
use types::BasicAuth;
|
use types::BasicAuth;
|
||||||
|
use types::BlocklistUpdate;
|
||||||
use types::SessionGet;
|
use types::SessionGet;
|
||||||
use types::SessionStats;
|
use types::SessionStats;
|
||||||
use types::TorrentAction;
|
use types::TorrentAction;
|
||||||
@ -148,6 +149,42 @@ impl TransClient {
|
|||||||
self.call(RpcRequest::session_stats()).await
|
self.call(RpcRequest::session_stats()).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Performs a blocklist update 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, BlockListUpdate, RpcResponse, BasicAuth};
|
||||||
|
///
|
||||||
|
/// #[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<BlockListUpdate>> = client.blocklist_update().await;
|
||||||
|
/// match response {
|
||||||
|
/// Ok(_) => println!("Yay!"),
|
||||||
|
/// Err(_) => panic!("Oh no!")
|
||||||
|
/// }
|
||||||
|
/// println!("Rpc reqsponse is ok: {}", response?.is_ok());
|
||||||
|
/// Ok(())
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub async fn blocklist_update(&self) -> Result<RpcResponse<BlocklistUpdate>> {
|
||||||
|
self.call(RpcRequest::blocklist_update()).await
|
||||||
|
}
|
||||||
|
|
||||||
/// Performs a torrent get call
|
/// Performs a torrent get call
|
||||||
/// fileds - if None then ALL fields
|
/// fileds - if None then ALL fields
|
||||||
/// ids - if None then All items
|
/// ids - if None then All items
|
||||||
|
|||||||
@ -22,6 +22,7 @@ pub use self::response::RpcResponse;
|
|||||||
pub(crate) use self::response::RpcResponseArgument;
|
pub(crate) use self::response::RpcResponseArgument;
|
||||||
pub use self::response::SessionGet;
|
pub use self::response::SessionGet;
|
||||||
pub use self::response::SessionStats;
|
pub use self::response::SessionStats;
|
||||||
|
pub use self::response::BlocklistUpdate;
|
||||||
pub use self::response::Torrent;
|
pub use self::response::Torrent;
|
||||||
pub use self::response::TorrentAdded;
|
pub use self::response::TorrentAdded;
|
||||||
pub use self::response::Torrents;
|
pub use self::response::Torrents;
|
||||||
|
|||||||
@ -23,6 +23,13 @@ impl RpcRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn blocklist_update() -> RpcRequest {
|
||||||
|
RpcRequest {
|
||||||
|
method: String::from("blocklist-update"),
|
||||||
|
arguments: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn torrent_get(fields: Option<Vec<TorrentGetField>>, ids: Option<Vec<Id>>) -> RpcRequest {
|
pub fn torrent_get(fields: Option<Vec<TorrentGetField>>, ids: Option<Vec<Id>>) -> RpcRequest {
|
||||||
let string_fields = fields
|
let string_fields = fields
|
||||||
.unwrap_or(TorrentGetField::all())
|
.unwrap_or(TorrentGetField::all())
|
||||||
|
|||||||
@ -46,6 +46,13 @@ pub struct SessionStats {
|
|||||||
}
|
}
|
||||||
impl RpcResponseArgument for SessionStats {}
|
impl RpcResponseArgument for SessionStats {}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
pub struct BlocklistUpdate {
|
||||||
|
#[serde(rename = "blocklist-size")]
|
||||||
|
pub blocklist_size: Option<i32>,
|
||||||
|
}
|
||||||
|
impl RpcResponseArgument for BlocklistUpdate {}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, RustcEncodable, Clone)]
|
#[derive(Deserialize, Debug, RustcEncodable, Clone)]
|
||||||
pub struct Torrent {
|
pub struct Torrent {
|
||||||
#[serde(rename = "addedDate")]
|
#[serde(rename = "addedDate")]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user