Skip to content

Commit

Permalink
Merge pull request #15 from nwithan8/develop
Browse files Browse the repository at this point in the history
Prep for release
  • Loading branch information
nwithan8 authored Feb 21, 2022
2 parents 4365318 + fa163c4 commit d4fee6f
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 64 deletions.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
objectrest~=1.1.1
pydantic==1.9.0
pytz~=2021.1
pytz~=2021.1
python-dotenv~=0.19.2
packaging~=21.3
5 changes: 3 additions & 2 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
objectrest~=1.1.1
pydantic==1.9.0
pytz~=2021.1
pytest~=6.2.5
python-dotenv~=0.19.2
pytest==7.0.1
python-dotenv~=0.19.2
packaging~=21.3
4 changes: 3 additions & 1 deletion tautulli/_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
__copyright__ = "Copyright © YEARADDEDBYGITHUB - Nate Harris"
__license__ = 'GNU General Public License v3 (GPLv3)'
__description__ = "A complete Python client for Tautulli's API"
__keywords__ = ["Tautulli", "API", "client", "Plex", "PMS", "Plex Media Server", "media", "server", "JSON"]
__keywords__ = ["Tautulli", "API", "client", "Plex", "PMS", "Plex Media Server", "media", "server", "JSON"]

__min_api_version__ = "2.9.4"
222 changes: 169 additions & 53 deletions tautulli/jsonapi.py

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions tautulli/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from tautulli.models.users import Datum as Users
from tautulli.models.updatecheck import Data as UpdateCheck
from tautulli.models.collectionstable import Data as CollectionsTable
from tautulli.models.activity import Data as ExportFields # TODO: Need fix
from tautulli.models.activity import Data as ExportFields # TODO: Need fix
from tautulli.models.geoiplookup import Data as GeoIPLookup
from tautulli.models.history import Data as History
from tautulli.models.homestats import Datum as HomeStats
Expand All @@ -29,7 +29,7 @@
from tautulli.models.newsletterconfig import Data as NewsletterConfig
from tautulli.models.newsletterlog import Data as NewsletterLog
from tautulli.models.notificationlog import Data as NotificationLog
from tautulli.models.activity import Data as NotifierConfig # TODO: Revisit, generator is failing
from tautulli.models.activity import Data as NotifierConfig # TODO: Revisit, generator is failing
from tautulli.models.notifiers import Datum as Notifiers
from tautulli.models.oldratingkeys import Data as OldRatingKeys
from tautulli.models.playliststable import Data as PlaylistsTable
Expand All @@ -49,5 +49,6 @@
from tautulli.models.registereddevice import Data as RegisteredDevice
from tautulli.models.searchresults import Data as SearchResults
from tautulli.models.activity import Data as SQLResults # TODO: Need to implement
from tautulli.models.tautulliinfo import Data as TautulliInfo

from tautulli.models.activitysummary import *
26 changes: 26 additions & 0 deletions tautulli/models/tautulliinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# generated by datamodel-codegen:
# filename: data.json
# timestamp: 2022-02-20T07:32:48+00:00

from __future__ import annotations

from pydantic import BaseModel


class Data(BaseModel):
tautulli_install_type: str
tautulli_version: str
tautulli_branch: str
tautulli_commit: str
tautulli_platform: str
tautulli_platform_release: str
tautulli_platform_version: str
tautulli_platform_linux_distro: str
tautulli_platform_device_name: str
tautulli_python_version: str


class Model(BaseModel):
result: str
message: str
data: Data
13 changes: 12 additions & 1 deletion tautulli/objectapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,17 @@ def get_synced_items(self, machine_id: str, user_id: str = None) -> SyncedItems:
"""
return 'SyncedItems'

@property
@make_property_object
def tautulli_info(self) -> TautulliInfo:
"""
Get the Tautulli server information
:return: Dict of data
:rtype: dict
"""
return 'TautulliInfo'

@make_object
def get_user(self, user_id: str) -> User:
"""
Expand Down Expand Up @@ -1091,7 +1102,7 @@ def delete_login_log(self) -> bool:
return False

@raw_api_bool
def delete_loopup_info(self, rating_key: int = None, service: str = None, delete_all: bool = False) -> bool:
def delete_lookup_info(self, rating_key: int = None, service: str = None, delete_all: bool = False) -> bool:
"""
Delete the 3rd party API lookup info
Expand Down
5 changes: 4 additions & 1 deletion tautulli/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
tautulli_database_import_methods = ['merge', 'overwrite']
plexivity_table_names = ['processed', 'grouped']
image_fallback_types = ["poster", "cover", "art", "poster-live", "art-live", "art-live-full"]
library_media_info_types = ['movie', 'show', 'artist', 'photo']
library_media_info_types = ['movie', 'show', 'artist', 'photo']
logfile_types = ["tautulli", "tautulli_api", "plex_websocket"]
plex_logfile_types = ["Plex Media Server", "Plex Media Scanner"]

12 changes: 11 additions & 1 deletion tautulli/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Union, List, Iterable
import logging
from datetime import datetime, timedelta
from typing import Union, List, Iterable

from pytz import timezone

from tautulli._info import __title__
Expand Down Expand Up @@ -36,6 +37,7 @@
def datetime_to_string(datetime_object: datetime, string_format: str = "%Y-%m-%d") -> str:
"""
Convert a datetime.datetime object to a string
:param datetime_object: Datetime.datetime object to convert
:type datetime_object: datetime
:param string_format: Date format to use
Expand All @@ -51,6 +53,7 @@ def datetime_to_string(datetime_object: datetime, string_format: str = "%Y-%m-%d
def build_optional_params(**kwargs) -> dict:
"""
Build a dict with only kwargs elements that are not None
:param kwargs: All possible parameters to include in final dict
:type kwargs: dict
:return: Dict of non-None parameters
Expand All @@ -66,6 +69,7 @@ def build_optional_params(**kwargs) -> dict:
def bool_to_int(boolean: bool) -> int:
"""
Convert a boolean to a 0/1 equivalent
:param boolean: Boolean to convert
:type boolean: bool
:return: 0 if False, 1 if True
Expand All @@ -80,6 +84,7 @@ def int_list_to_string(int_list: List[int]) -> str:
"""
Convert a list of ints to a comma-separated string
e.g. [0, 1, 4] -> "0,1,4"
:param int_list: List of ints to convert
:type int_list: list
:return: Comma-separated string of ints
Expand Down Expand Up @@ -138,6 +143,7 @@ def _one_needed(**kwargs) -> bool:
"""
Check if at least one of the kwargs is not None
Logs error message if not.
:param kwargs: Dict of keyword arguments
:type kwargs: dict
:return: Whether at least on kwarg is not None
Expand All @@ -156,6 +162,7 @@ def _one_needed(**kwargs) -> bool:
def _which_used(**kwargs) -> tuple:
"""
Get which (first) of kwargs is not None
:param kwargs: Dict of keyword arguments
:type kwargs: dict
:return: First (keyword, value) that is not None
Expand All @@ -171,6 +178,7 @@ def _is_invalid_choice(value, variable_name: str, choices: List) -> bool:
"""
Check if value is one of the possible choices
Logs error message if not.
:param value: Value to evaluate
:type value: object
:param variable_name: Name of variable (for logging purposes)
Expand All @@ -190,6 +198,7 @@ def _is_invalid_choice(value, variable_name: str, choices: List) -> bool:
def _get_response_data(json_data: dict) -> Union[str, int, List, dict]:
"""
Return ['response']['data'] from JSON data
:param json_data: JSON data to parse
:type json_data: dict
:return: json_data['response']['data']
Expand All @@ -202,6 +211,7 @@ def _success_result(json_data: dict) -> bool:
"""
Return if ['response']['result'] from JSON data is 'success'
Logs debug message if not.
:param json_data: JSON data to parse
:type json_data: dict
:return: json_data['response']['result'] == 'success'
Expand Down
23 changes: 21 additions & 2 deletions tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,33 @@ def raw_client(no_key: bool = False) -> tautulli.RawAPI:
if not url:
raise ValueError("T_URL is not set")
if no_key:
return tautulli.RawAPI(base_url=url, api_key="placeholder")
return tautulli.RawAPI(base_url=url, api_key="placeholder", verify=False)
else:
key = os.getenv("T_KEY")
if not key:
temp_client = tautulli.RawAPI(base_url=url, api_key="placeholder")
temp_client = tautulli.RawAPI(base_url=url, api_key="placeholder", verify=False)
key = temp_client.get_api_key()
if key:
os.environ["T_KEY"] = key
return tautulli.RawAPI(base_url=url, api_key=key)
else:
raise ValueError("T_KEY is not set and could not be retrieved from server")


def object_client(no_key: bool = False) -> tautulli.ObjectAPI:
load_dotenv()
url = os.getenv("T_URL")
if not url:
raise ValueError("T_URL is not set")
if no_key:
return tautulli.ObjectAPI(base_url=url, api_key="placeholder")
else:
key = os.getenv("T_KEY")
if not key:
temp_client = tautulli.RawAPI(base_url=url, api_key="placeholder")
key = temp_client.get_api_key()
if key:
os.environ["T_KEY"] = key
return tautulli.ObjectAPI(base_url=url, api_key=key)
else:
raise ValueError("T_KEY is not set and could not be retrieved from server")
7 changes: 7 additions & 0 deletions tests/test_jsonapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ def test_ping():
assert res is True


def test_tautulli_info():
client = raw_client()
tautulli_info = client.tautulli_info
assert tautulli_info is not None
assert type(tautulli_info) == dict


def test_docs():
client = raw_client()
docs = client.docs
Expand Down

0 comments on commit d4fee6f

Please sign in to comment.