feat(network): Support for updating all series in Sonarr
This commit is contained in:
@@ -76,6 +76,7 @@ pub enum SonarrEvent {
|
||||
TriggerAutomaticEpisodeSearch(Option<i64>),
|
||||
TriggerAutomaticSeasonSearch(Option<(i64, i64)>),
|
||||
TriggerAutomaticSeriesSearch(Option<i64>),
|
||||
UpdateAllSeries,
|
||||
}
|
||||
|
||||
impl NetworkResource for SonarrEvent {
|
||||
@@ -98,7 +99,8 @@ impl NetworkResource for SonarrEvent {
|
||||
| SonarrEvent::StartTask(_)
|
||||
| SonarrEvent::TriggerAutomaticSeriesSearch(_)
|
||||
| SonarrEvent::TriggerAutomaticSeasonSearch(_)
|
||||
| SonarrEvent::TriggerAutomaticEpisodeSearch(_) => "/command",
|
||||
| SonarrEvent::TriggerAutomaticEpisodeSearch(_)
|
||||
| SonarrEvent::UpdateAllSeries => "/command",
|
||||
SonarrEvent::GetRootFolders
|
||||
| SonarrEvent::DeleteRootFolder(_)
|
||||
| SonarrEvent::AddRootFolder(_) => "/rootfolder",
|
||||
@@ -258,6 +260,7 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.trigger_automatic_episode_search(episode_id)
|
||||
.await
|
||||
.map(SonarrSerdeable::from),
|
||||
SonarrEvent::UpdateAllSeries => self.update_all_series().await.map(SonarrSerdeable::from),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1523,6 +1526,23 @@ impl<'a, 'b> Network<'a, 'b> {
|
||||
.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) {
|
||||
let series_id = if let Some(id) = series_id {
|
||||
id
|
||||
|
||||
@@ -168,7 +168,8 @@ mod test {
|
||||
SonarrEvent::StartTask(None),
|
||||
SonarrEvent::TriggerAutomaticEpisodeSearch(None),
|
||||
SonarrEvent::TriggerAutomaticSeasonSearch(None),
|
||||
SonarrEvent::TriggerAutomaticSeriesSearch(None)
|
||||
SonarrEvent::TriggerAutomaticSeriesSearch(None),
|
||||
SonarrEvent::UpdateAllSeries
|
||||
)]
|
||||
event: SonarrEvent,
|
||||
) {
|
||||
@@ -4495,6 +4496,30 @@ mod test {
|
||||
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]
|
||||
async fn test_extract_series_id() {
|
||||
let app_arc = Arc::new(Mutex::new(App::default()));
|
||||
|
||||
Reference in New Issue
Block a user