diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9cc400..047c765 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,7 +39,7 @@ jobs: with: command: build - - name: Setup Test Enviroment + - name: Setup Test Environment run: docker-compose up -d - name: Cargo Test diff --git a/Cargo.toml b/Cargo.toml index 82aebdf..6c1ec50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ reqwest = { version = "0.11.11", features = [ "rustls-tls", ], default-features = false } serde = { version = "1.0.144", features = ["derive"] } -enum-iterator = "1.2.0" +enum-iterator = "0.8.1" dotenv = "0.15.0" log = "0.4.17" diff --git a/src/lib.rs b/src/lib.rs index ad02749..62c61af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,8 @@ pub mod types; use types::{ BasicAuth, BlocklistUpdate, FreeSpace, Id, Nothing, PortTest, Result, RpcRequest, RpcResponse, RpcResponseArgument, SessionClose, SessionGet, SessionStats, Torrent, TorrentAction, - TorrentAddArgs, TorrentAddedOrDuplicate, TorrentGetField, TorrentRenamePath, Torrents, + TorrentAddArgs, TorrentAddedOrDuplicate, TorrentGetField, TorrentRenamePath, TorrentSetArgs, + Torrents, }; const MAX_RETRIES: usize = 5; @@ -381,9 +382,9 @@ impl TransClient { /// /// let args = TorrentSetArgs { /// labels: Some(vec![String::from("blue")]), - /// ..Default::default(), + /// ..Default::default() /// }; - /// assert!(client.torrent_set(args, vec![Id::Id(0)]).await?.is_ok()) + /// assert!(client.torrent_set(args, Some(vec![Id::Id(0)])).await?.is_ok()); /// /// Ok(()) /// } @@ -636,12 +637,12 @@ impl TransClient { let rsp: reqwest::Response = rq.send().await?; if matches!(rsp.status(), StatusCode::CONFLICT) { - let session_id = rsp - .headers() - .get("X-Transmission-Session-Id") - .ok_or(TransError::NoSessionIdReceived)? - .to_str()?; - self.session_id = Some(String::from(session_id)); + let session_id = rsp + .headers() + .get("X-Transmission-Session-Id") + .ok_or(TransError::NoSessionIdReceived)? + .to_str()?; + self.session_id = Some(String::from(session_id)); info!("Got new session_id: {}. Retrying request.", session_id); } else { diff --git a/src/types/mod.rs b/src/types/mod.rs index 00ec0dd..4ef6cf7 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -12,6 +12,7 @@ pub struct BasicAuth { pub(crate) use self::request::RpcRequest; pub use self::request::{ ArgumentFields, Id, TorrentAction, TorrentAddArgs, TorrentGetField, TorrentRenamePathArgs, + TorrentSetArgs, }; pub(crate) use self::response::RpcResponseArgument; diff --git a/src/types/request.rs b/src/types/request.rs index 0edb572..61357c1 100644 --- a/src/types/request.rs +++ b/src/types/request.rs @@ -1,4 +1,4 @@ -use enum_iterator::{all, Sequence}; +use enum_iterator::IntoEnumIterator; use serde::Serialize; #[derive(Serialize, Debug)] @@ -53,7 +53,7 @@ impl RpcRequest { pub fn torrent_get(fields: Option>, ids: Option>) -> RpcRequest { let string_fields = fields - .unwrap_or(all::().collect()) + .unwrap_or(TorrentGetField::all()) .iter() .map(TorrentGetField::to_str) .collect(); @@ -70,7 +70,7 @@ impl RpcRequest { args.ids = ids; RpcRequest { method: String::from("torrent-set"), - arguments: Some(Args::TorrentSetArgs(args)), + arguments: Some(Args::TorrentSet(args)), } } @@ -135,6 +135,7 @@ pub enum Args { TorrentAction(TorrentActionArgs), TorrentRemove(TorrentRemoveArgs), TorrentAdd(TorrentAddArgs), + TorrentSet(TorrentSetArgs), TorrentSetLocation(TorrentSetLocationArgs), TorrentRenamePath(TorrentRenamePathArgs), } @@ -154,7 +155,9 @@ pub struct TorrentGetArgs { impl Default for TorrentGetArgs { fn default() -> Self { - let all_fields = all::().map(|it| it.to_str()).collect(); + let all_fields = TorrentGetField::into_enum_iter() + .map(|it| it.to_str()) + .collect(); TorrentGetArgs { fields: Some(all_fields), ids: None, @@ -195,7 +198,7 @@ pub enum Id { Hash(String), } -#[derive(Serialize, Debug, Default, Clone, Default)] +#[derive(Serialize, Debug, Clone, Default)] pub struct TorrentAddArgs { #[serde(skip_serializing_if = "Option::is_none")] pub cookies: Option, @@ -236,7 +239,7 @@ pub struct TorrentAddArgs { pub labels: Option>, } -#[derive(Clone, Sequence)] +#[derive(Clone, Copy, IntoEnumIterator)] pub enum TorrentGetField { ActivityDate, AddedDate, @@ -280,6 +283,10 @@ pub enum TorrentGetField { } impl TorrentGetField { + pub fn all() -> Vec { + TorrentGetField::into_enum_iter().collect() + } + #[must_use] pub fn to_str(&self) -> String { match self {