mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-25 21:20:18 +00:00
Add a method to request a claim token (#287)
* add MyPlexAccount.claimToken() * improve docstring for MyPlexAccount.claimToken()
This commit is contained in:
parent
93ec86d746
commit
12a318a8e2
2 changed files with 17 additions and 0 deletions
|
@ -478,6 +478,19 @@ class MyPlexAccount(PlexObject):
|
|||
|
||||
return SyncItem(self, data, None, clientIdentifier=client.clientIdentifier)
|
||||
|
||||
def claimToken(self):
|
||||
""" Returns a str, a new "claim-token", which you can use to register your new Plex Server instance to your
|
||||
account.
|
||||
See: https://hub.docker.com/r/plexinc/pms-docker/, https://www.plex.tv/claim/
|
||||
"""
|
||||
response = self._session.get('https://plex.tv/api/claim/token.json', headers=self._headers(), timeout=TIMEOUT)
|
||||
if response.status_code not in (200, 201, 204): # pragma: no cover
|
||||
codename = codes.get(response.status_code)[0]
|
||||
errtext = response.text.replace('\n', ' ')
|
||||
log.warning('BadRequest (%s) %s %s; %s' % (response.status_code, codename, response.url, errtext))
|
||||
raise BadRequest('(%s) %s %s; %s' % (response.status_code, codename, response.url, errtext))
|
||||
return response.json()['token']
|
||||
|
||||
|
||||
class MyPlexUser(PlexObject):
|
||||
""" This object represents non-signed in users such as friends and linked
|
||||
|
|
|
@ -165,3 +165,7 @@ def test_myplex_plexpass_attributes(account_plexpass):
|
|||
assert 'premium_music_metadata' in account_plexpass.subscriptionFeatures
|
||||
assert 'plexpass' in account_plexpass.roles
|
||||
assert set(account_plexpass.entitlements) == utils.ENTITLEMENTS
|
||||
|
||||
|
||||
def test_myplex_claimToken(account):
|
||||
assert account.claimToken().startswith('claim-')
|
||||
|
|
Loading…
Reference in a new issue