Add MyPlexAccount.ping() to refresh authentication token (#1271)

* Add `MyPlexAccount.ping()` to refresh auth token

* Test account ping
This commit is contained in:
JonnyWong16 2023-11-02 21:24:46 -07:00 committed by GitHub
parent 7f5cf76cbd
commit 253949c1fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -108,6 +108,7 @@ class MyPlexAccount(PlexObject):
OPTOUTS = 'https://plex.tv/api/v2/user/{userUUID}/settings/opt_outs' # get
LINK = 'https://plex.tv/api/v2/pins/link' # put
VIEWSTATESYNC = 'https://plex.tv/api/v2/user/view_state_sync' # put
PING = 'https://plex.tv/api/v2/ping'
# Hub sections
VOD = 'https://vod.provider.plex.tv' # get
MUSIC = 'https://music.provider.plex.tv' # get
@ -250,6 +251,15 @@ class MyPlexAccount(PlexObject):
data = response.text.encode('utf8')
return ElementTree.fromstring(data) if data.strip() else None
def ping(self):
""" Ping the Plex.tv API.
This will refresh the authentication token to prevent it from expiring.
"""
pong = self.query(self.PING)
if pong is not None:
return utils.cast(bool, pong.text)
return False
def device(self, name=None, clientId=None):
""" Returns the :class:`~plexapi.myplex.MyPlexDevice` that matches the name specified.

View file

@ -361,3 +361,7 @@ def test_myplex_pin(account, plex):
def test_myplex_geoip(account):
assert account.geoip(account.publicIP())
def test_myplex_ping(account):
assert account.ping()