Skip to content

Commit 253949c

Browse files
authored
Add MyPlexAccount.ping() to refresh authentication token (#1271)
* Add `MyPlexAccount.ping()` to refresh auth token * Test account ping
1 parent 7f5cf76 commit 253949c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

plexapi/myplex.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class MyPlexAccount(PlexObject):
108108
OPTOUTS = 'https://plex.tv/api/v2/user/{userUUID}/settings/opt_outs' # get
109109
LINK = 'https://plex.tv/api/v2/pins/link' # put
110110
VIEWSTATESYNC = 'https://plex.tv/api/v2/user/view_state_sync' # put
111+
PING = 'https://plex.tv/api/v2/ping'
111112
# Hub sections
112113
VOD = 'https://vod.provider.plex.tv' # get
113114
MUSIC = 'https://music.provider.plex.tv' # get
@@ -250,6 +251,15 @@ def query(self, url, method=None, headers=None, timeout=None, **kwargs):
250251
data = response.text.encode('utf8')
251252
return ElementTree.fromstring(data) if data.strip() else None
252253

254+
def ping(self):
255+
""" Ping the Plex.tv API.
256+
This will refresh the authentication token to prevent it from expiring.
257+
"""
258+
pong = self.query(self.PING)
259+
if pong is not None:
260+
return utils.cast(bool, pong.text)
261+
return False
262+
253263
def device(self, name=None, clientId=None):
254264
""" Returns the :class:`~plexapi.myplex.MyPlexDevice` that matches the name specified.
255265

tests/test_myplex.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,7 @@ def test_myplex_pin(account, plex):
361361

362362
def test_myplex_geoip(account):
363363
assert account.geoip(account.publicIP())
364+
365+
366+
def test_myplex_ping(account):
367+
assert account.ping()

0 commit comments

Comments
 (0)