From 27992c1683b01f53e7346a1bfe0c81e19a993fe6 Mon Sep 17 00:00:00 2001 From: Steven Marks Date: Mon, 27 Jun 2022 14:24:09 +0000 Subject: [PATCH 1/2] fix: updating episode was throwing errors --- .gitignore | 2 ++ pyarr/sonarr.py | 81 +++++++++++++++++++++++++------------------------ 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 6c3a717..c10a84b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,8 @@ dist build .vscode/* *.egg-info +.mypy_cache +.pytest_cache .devcontainer/* !.devcontainer/recommended-devcontainer.json diff --git a/pyarr/sonarr.py b/pyarr/sonarr.py index 137b254..8f0b1f6 100644 --- a/pyarr/sonarr.py +++ b/pyarr/sonarr.py @@ -1,5 +1,6 @@ from datetime import datetime from typing import Any, Optional +from warnings import warn from requests import Response @@ -112,6 +113,24 @@ def post_command(self, name: SonarrCommands, **kwargs) -> Any: ## EPISODE + # GET /episode + def get_episode(self, id_: int, series: bool = False) -> dict[str, Any]: + """Get get episodes by ID or series + + Args: + id_ (int): ID for Episode or Series. + series (bool, optional): Set to true if the ID is for a Series. Defaults to false. + + Returns: + list[dict[str, Any]]: List of dictionaries with items + """ + return self.assert_return( + f"episode{'' if series else f'/{id_}'}", + self.ver_uri, + dict, + params={"seriesId": id_} if series else None, + ) + # GET /episode def get_episodes_by_series_id(self, id_: int) -> list[dict[str, Any]]: # sourcery skip: class-extract-method @@ -123,11 +142,16 @@ def get_episodes_by_series_id(self, id_: int) -> list[dict[str, Any]]: Returns: list[dict[str, Any]]: List of dictionaries with items """ + warn( + "This method is deprecated and will be removed in a future release. Please use get_episode()", + DeprecationWarning, + stacklevel=2, + ) params = {"seriesId": id_} return self.assert_return("episode", self.ver_uri, list, params) # GET /episode/{id} - def get_episode_by_episode_id(self, id_: int) -> list[dict[str, Any]]: + def get_episode_by_episode_id(self, id_: int) -> dict[str, Any]: """Gets a specific episode by database id Args: @@ -136,22 +160,30 @@ def get_episode_by_episode_id(self, id_: int) -> list[dict[str, Any]]: Returns: list[dict[str, Any]]: List of dictionaries with items """ - return self.assert_return(f"episode/{id_}", self.ver_uri, list) + warn( + "This method is deprecated and will be removed in a future release. Please use get_episode()", + DeprecationWarning, + stacklevel=2, + ) + return self.assert_return(f"episode/{id_}", self.ver_uri, dict) # PUT /episode - def upd_episode(self, data: dict[str, Any]) -> dict[str, Any]: - """Update the given episodes, currently only monitored is changed, all other modifications are ignored. - - Note: - To be used in conjunction with get_episode() + def upd_episode(self, id_: int, data: dict[str, Any]) -> dict[str, Any]: + """Update the given episodes, currently only monitored is supported Args: - data (dict[str, Any]): All parameters to update episode + id_ (int): ID of the Episode to be updated + data (dict[str, Any]): Parameters to update the episode + + Example: + :: + payload = {"monitored": True} + sonarr.upd_episode(1, payload) Returns: dict[str, Any]: Dictionary with updated record """ - return self._put("episode", self.ver_uri, data=data) + return self._put(f"episode/{id_}", self.ver_uri, data=data) ## EPISODE FILE @@ -261,37 +293,6 @@ def get_quality_profile(self, id_: Optional[int] = None) -> list[dict[str, Any]] path = f"profile/{id_}" if id_ else "profile" return self.assert_return(path, self.ver_uri, list) - # PUT /profile/{id} - # TODO: this doesnt work on v3 API - def upd_quality_profile(self, id_: int, data: dict[str, Any]) -> dict[str, Any]: - """Update the quality profile data. - - Note: - To be used in conjunction with get_quality_profile() - - Args: - id_ (int): Profile ID to Update - data (dict[str, Any]): All parameters to update - - Returns: - dict[str, Any]: Dictionary with updated record - """ - return self._put(f"profile/{id_}", self.ver_uri, data=data) - - # DELETE /profile - # TODO: this doesnt work on v3 API - def del_quality_profile(self, id_: int) -> Response: - """Removes a specific quality profile from the blocklist - - Args: - id_ (int): Quality profile id from database - - Returns: - Response: HTTP Response - """ - params = {"id": id_} - return self._delete("profile", self.ver_uri, params=params) - ## QUEUE # GET /queue From fa91cbdc8aea0f9920e7ba3ff6c0c2fab381a2f2 Mon Sep 17 00:00:00 2001 From: Steven Marks Date: Mon, 27 Jun 2022 14:24:35 +0000 Subject: [PATCH 2/2] chore: update version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9ad5760..fde76fb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pyarr" -version = "4.0.0" +version = "4.0.1" description = "Synchronous Sonarr, Radarr, Lidarr and Readarr API's for Python" authors = ["Steven Marks "] license = "MIT"