Skip to content

Commit

Permalink
Merge pull request #109 from totaldebug/108-upd_episode_doesnt_work_a…
Browse files Browse the repository at this point in the history
…s_expected

fix: upd_episode throws error when supplying data
  • Loading branch information
marksie1988 authored Jun 27, 2022
2 parents 9bc142b + fa91cbd commit b4d4155
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ dist
build
.vscode/*
*.egg-info
.mypy_cache
.pytest_cache

.devcontainer/*
!.devcontainer/recommended-devcontainer.json
Expand Down
81 changes: 41 additions & 40 deletions pyarr/sonarr.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from typing import Any, Optional
from warnings import warn

from requests import Response

Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit b4d4155

Please sign in to comment.