feat(network): Support for updating all series in Sonarr
This commit is contained in:
@@ -76,6 +76,7 @@ pub enum SonarrEvent {
|
|||||||
TriggerAutomaticEpisodeSearch(Option<i64>),
|
TriggerAutomaticEpisodeSearch(Option<i64>),
|
||||||
TriggerAutomaticSeasonSearch(Option<(i64, i64)>),
|
TriggerAutomaticSeasonSearch(Option<(i64, i64)>),
|
||||||
TriggerAutomaticSeriesSearch(Option<i64>),
|
TriggerAutomaticSeriesSearch(Option<i64>),
|
||||||
|
UpdateAllSeries,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NetworkResource for SonarrEvent {
|
impl NetworkResource for SonarrEvent {
|
||||||
@@ -98,7 +99,8 @@ impl NetworkResource for SonarrEvent {
|
|||||||
| SonarrEvent::StartTask(_)
|
| SonarrEvent::StartTask(_)
|
||||||
| SonarrEvent::TriggerAutomaticSeriesSearch(_)
|
| SonarrEvent::TriggerAutomaticSeriesSearch(_)
|
||||||
| SonarrEvent::TriggerAutomaticSeasonSearch(_)
|
| SonarrEvent::TriggerAutomaticSeasonSearch(_)
|
||||||
| SonarrEvent::TriggerAutomaticEpisodeSearch(_) => "/command",
|
| SonarrEvent::TriggerAutomaticEpisodeSearch(_)
|
||||||
|
| SonarrEvent::UpdateAllSeries => "/command",
|
||||||
SonarrEvent::GetRootFolders
|
SonarrEvent::GetRootFolders
|
||||||
| SonarrEvent::DeleteRootFolder(_)
|
| SonarrEvent::DeleteRootFolder(_)
|
||||||
| SonarrEvent::AddRootFolder(_) => "/rootfolder",
|
| SonarrEvent::AddRootFolder(_) => "/rootfolder",
|
||||||
@@ -258,6 +260,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.trigger_automatic_episode_search(episode_id)
|
.trigger_automatic_episode_search(episode_id)
|
||||||
.await
|
.await
|
||||||
.map(SonarrSerdeable::from),
|
.map(SonarrSerdeable::from),
|
||||||
|
SonarrEvent::UpdateAllSeries => self.update_all_series().await.map(SonarrSerdeable::from),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1523,6 +1526,23 @@ impl<'a, 'b> Network<'a, 'b> {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn update_all_series(&mut self) -> Result<Value> {
|
||||||
|
info!("Updating all series");
|
||||||
|
let event = SonarrEvent::UpdateAllSeries;
|
||||||
|
let body = SonarrCommandBody {
|
||||||
|
name: "RefreshSeries".to_owned(),
|
||||||
|
..SonarrCommandBody::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
let request_props = self
|
||||||
|
.request_props_from(event, RequestMethod::Post, Some(body), None, None)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
self
|
||||||
|
.handle_request::<SonarrCommandBody, Value>(request_props, |_, _| ())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
async fn extract_series_id(&mut self, series_id: Option<i64>) -> (i64, String) {
|
async fn extract_series_id(&mut self, series_id: Option<i64>) -> (i64, String) {
|
||||||
let series_id = if let Some(id) = series_id {
|
let series_id = if let Some(id) = series_id {
|
||||||
id
|
id
|
||||||
|
|||||||
@@ -168,7 +168,8 @@ mod test {
|
|||||||
SonarrEvent::StartTask(None),
|
SonarrEvent::StartTask(None),
|
||||||
SonarrEvent::TriggerAutomaticEpisodeSearch(None),
|
SonarrEvent::TriggerAutomaticEpisodeSearch(None),
|
||||||
SonarrEvent::TriggerAutomaticSeasonSearch(None),
|
SonarrEvent::TriggerAutomaticSeasonSearch(None),
|
||||||
SonarrEvent::TriggerAutomaticSeriesSearch(None)
|
SonarrEvent::TriggerAutomaticSeriesSearch(None),
|
||||||
|
SonarrEvent::UpdateAllSeries
|
||||||
)]
|
)]
|
||||||
event: SonarrEvent,
|
event: SonarrEvent,
|
||||||
) {
|
) {
|
||||||
@@ -4495,6 +4496,30 @@ mod test {
|
|||||||
async_server.assert_async().await;
|
async_server.assert_async().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_handle_update_all_series_event() {
|
||||||
|
let (async_server, app_arc, _server) = mock_servarr_api(
|
||||||
|
RequestMethod::Post,
|
||||||
|
Some(json!({
|
||||||
|
"name": "RefreshSeries",
|
||||||
|
})),
|
||||||
|
Some(json!({})),
|
||||||
|
None,
|
||||||
|
SonarrEvent::UpdateAllSeries,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
let mut network = Network::new(&app_arc, CancellationToken::new(), Client::new());
|
||||||
|
|
||||||
|
assert!(network
|
||||||
|
.handle_sonarr_event(SonarrEvent::UpdateAllSeries)
|
||||||
|
.await
|
||||||
|
.is_ok());
|
||||||
|
|
||||||
|
async_server.assert_async().await;
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_extract_series_id() {
|
async fn test_extract_series_id() {
|
||||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||||
|
|||||||
Reference in New Issue
Block a user