Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: broken endpoints and pylint errors #95

Merged
merged 8 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MASTER]
disable=missing-module-docstring, line-too-long, too-many-public-methods, too-many-arguments
2 changes: 1 addition & 1 deletion pyarr/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def upd_quality_definition(self, id_, data):
Returns:
JSON: Array
"""
path = f"qualitydefinition/{id}"
path = f"qualitydefinition/{id_}"
return self.request_put(path, self.ver_uri, data=data)

# INDEXER
Expand Down
14 changes: 0 additions & 14 deletions pyarr/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
class PyarrError(Exception):
"""Generic PyArr Exception."""

pass


class PyarrConnectionError(PyarrError):
"""Sonarr connection exception."""

pass


class PyarrUnauthorizedError(PyarrError):
"""Unauthorised access exception"""

pass


class PyarrAccessRestricted(PyarrError):
"""Pyarr access restricted exception."""

pass


class PyarrResourceNotFound(PyarrError):
"""Pyarr resource not found exception"""

pass


class PyarrBadGateway(PyarrError):
"""Pyarr bad gateway exception"""

pass


class PyarrMissingProfile(PyarrError):
"""Pyarr missing profile"""

pass
4 changes: 2 additions & 2 deletions pyarr/radarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def upd_movie(self, data, move_files=False):
JSON: 200 Ok, 401 Unauthorized
"""

path = "/api/movie"
path = "movie"
params = {"moveFiles": move_files}
return self.request_put(path, self.ver_uri, data=data, params=params)

Expand Down Expand Up @@ -196,7 +196,7 @@ def lookup_movie_by_imdb_id(self, id_):
JSON: List of movies found
"""
params = {"term": f"imdb:{id_}"}
path = "/api/v3/movie/lookup"
path = "movie/lookup"
return self.request_get(path, self.ver_uri, params=params)

# PUT /movie/editor
Expand Down
36 changes: 18 additions & 18 deletions pyarr/readarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,15 +543,15 @@ def get_log_file(self):
def add_root_folder(
self,
name: str,
dir: str,
isCalibreLib: bool = False,
calibreHost: str = "localhost",
calibrePort: int = 8080,
useSsl: bool = False,
outputProfile: str = "default",
defaultTags: list = [],
defaultQualityProfileId: int = 1,
defaultMetadataProfileId: int = 1,
directory: str,
is_calibre_lib: bool = False,
calibre_host: str = "localhost",
calibre_port: int = 8080,
use_ssl: bool = False,
output_profile: str = "default",
default_tags: list = None,
default_quality_profile_id: int = 1,
default_metadata_profile_id: int = 1,
):
"""Add a new root directory to the Readarr Server

Expand All @@ -571,16 +571,16 @@ def add_root_folder(
JSON: Array
"""
folder_json = {
"isCalibreLibrary": isCalibreLib,
"host": calibreHost,
"port": calibrePort,
"useSsl": useSsl,
"outputProfile": outputProfile,
"defaultTags": defaultTags,
"defaultQualityProfileId": defaultQualityProfileId,
"defaultMetadataProfileId": defaultMetadataProfileId,
"isCalibreLibrary": is_calibre_lib,
"host": calibre_host,
"port": calibre_port,
"useSsl": use_ssl,
"outputProfile": output_profile,
"defaultTags": default_tags or [],
"defaultQualityProfileId": default_quality_profile_id,
"defaultMetadataProfileId": default_metadata_profile_id,
"name": name,
"path": dir,
"path": directory,
}
path = "rootFolder"
return self.request_post(path, self.ver_uri, data=folder_json)
Expand Down
73 changes: 37 additions & 36 deletions pyarr/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def request_get(self, path, ver_uri="", params=None):
raise PyarrConnectionError(
"Timeout occurred while connecting to API"
) from exception
return self._process_response(res)
return _process_response(res)

def request_post(self, path, ver_uri="", params=None, data=None):
"""Wrapper on any post requests
Expand All @@ -102,7 +102,7 @@ def request_post(self, path, ver_uri="", params=None, data=None):
raise PyarrConnectionError(
"Timeout occurred while connecting to API"
) from exception
return self._process_response(res)
return _process_response(res)

def request_put(self, path, ver_uri="", params=None, data=None):
"""Wrapper on any put requests
Expand All @@ -128,7 +128,7 @@ def request_put(self, path, ver_uri="", params=None, data=None):
raise PyarrConnectionError(
"Timeout occurred while connecting to API"
) from exception
return self._process_response(res)
return _process_response(res)

def request_del(self, path, ver_uri="", params=None, data=None):
"""Wrapper on any delete requests
Expand All @@ -154,36 +154,37 @@ def request_del(self, path, ver_uri="", params=None, data=None):
raise PyarrConnectionError(
"Timeout occurred while connecting to API"
) from exception
return self._process_response(res)

def _process_response(self, res):
"""Check the response status code and error or return results

Args:
res (str): JSON or Text response from API Call

Raises:
PyarrUnauthorizedError: Invalid API Key
PyarrAccessRestricted: Invalid Permissions
PyarrResourceNotFound: Incorrect Resource
PyarrBadGateway: Bad Gateway

Returns:
JSON: Array
"""
if res.status_code == 401:
raise PyarrUnauthorizedError(
"Unauthorized. Please ensure valid API Key is used.", {}
)
if res.status_code == 403:
raise PyarrAccessRestricted(
"Access restricted. Please ensure API Key has correct permissions", {}
)
if res.status_code == 404:
raise PyarrResourceNotFound("Resource not found")
if res.status_code == 502:
raise PyarrBadGateway("Bad Gateway. Check your server is accessible")
content_type = res.headers.get("Content-Type", "")
if "application/json" in content_type:
return res.json()
return res
return _process_response(res)


def _process_response(res):
"""Check the response status code and error or return results

Args:
res (str): JSON or Text response from API Call

Raises:
PyarrUnauthorizedError: Invalid API Key
PyarrAccessRestricted: Invalid Permissions
PyarrResourceNotFound: Incorrect Resource
PyarrBadGateway: Bad Gateway

Returns:
JSON: Array
"""
if res.status_code == 401:
raise PyarrUnauthorizedError(
"Unauthorized. Please ensure valid API Key is used.", {}
)
if res.status_code == 403:
raise PyarrAccessRestricted(
"Access restricted. Please ensure API Key has correct permissions", {}
)
if res.status_code == 404:
raise PyarrResourceNotFound("Resource not found")
if res.status_code == 502:
raise PyarrBadGateway("Bad Gateway. Check your server is accessible")
content_type = res.headers.get("Content-Type", "")
if "application/json" in content_type:
return res.json()
return res
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 = "3.0.0"
version = "3.0.1"
description = "Python client for Servarr API's (Sonarr, Radarr, Readarr)"
authors = ["Steven Marks <[email protected]>"]
license = "MIT"
Expand Down