Skip to content

Commit 16b4d54

Browse files
committed
Update doc strings
1 parent e1fe660 commit 16b4d54

File tree

1 file changed

+59
-20
lines changed

1 file changed

+59
-20
lines changed

plexapi/myplex.py

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,9 +1683,11 @@ def syncItems(self):
16831683

16841684
class MyPlexPinLogin:
16851685
"""
1686-
MyPlex PIN login class which supports getting the four character PIN which the user must
1687-
enter on https://plex.tv/link to authenticate the client and provide an access token to
1688-
create a :class:`~plexapi.myplex.MyPlexAccount` instance.
1686+
MyPlex PIN login class which supports getting a token for authenticating the client and
1687+
providing an access token to create a :class:`~plexapi.myplex.MyPlexAccount` instance.
1688+
The login can be done using the four character PIN which the user must enter at
1689+
https://plex.tv/link or using Plex OAuth.
1690+
16891691
This helper class supports a polling, threaded and callback approach.
16901692
16911693
- The polling approach expects the developer to periodically check if the PIN login was
@@ -1702,17 +1704,32 @@ class MyPlexPinLogin:
17021704
Parameters:
17031705
session (requests.Session, optional): Use your own session object if you want to
17041706
cache the http responses from Plex.
1705-
requestTimeout (int): timeout in seconds on initial connect to plex.tv (default config.TIMEOUT).
1706-
headers (dict): A dict of X-Plex headers to send with requests.
1707-
oauth (bool): True to use Plex OAuth instead of PIN login.
1707+
requestTimeout (int, optional): Timeout in seconds on initial connect to plex.tv (default config.TIMEOUT).
1708+
headers (dict, optional): A dict of X-Plex headers to send with requests.
1709+
oauth (bool, optional): True to use Plex OAuth instead of PIN login.
17081710
17091711
Attributes:
17101712
PINS (str): 'https://plex.tv/api/v2/pins'
17111713
POLLINTERVAL (int): 1
1714+
pin (str): Four character PIN to use for the login at https://plex.tv/link.
17121715
finished (bool): Whether the pin login has finished or not.
17131716
expired (bool): Whether the pin login has expired or not.
1714-
token (str): Token retrieved through the pin login.
1715-
pin (str): Pin to use for the login on https://plex.tv/link.
1717+
token (str): Token retrieved after login.
1718+
1719+
Example:
1720+
1721+
.. code-block:: python
1722+
1723+
from plexapi.myplex import MyPlexAccount, MyPlexPinLogin
1724+
1725+
pinlogin = MyPlexPinLogin()
1726+
pinlogin.run()
1727+
print(f'Login to Plex at the following url:\\n{pinlogin.oauthUrl()}')
1728+
pinlogin.waitForLogin()
1729+
token = pinlogin.token
1730+
1731+
account = MyPlexAccount(token=token)
1732+
17161733
"""
17171734
PINS = 'https://plex.tv/api/v2/pins'
17181735
POLLINTERVAL = 1
@@ -1737,7 +1754,7 @@ def __init__(self, session=None, requestTimeout=None, headers=None, oauth=False)
17371754

17381755
@property
17391756
def pin(self):
1740-
""" Return the 4 character PIN used for linking a device at
1757+
""" Return the four character PIN used for linking a device at
17411758
https://plex.tv/link.
17421759
"""
17431760
if self._oauth:
@@ -1911,30 +1928,52 @@ class MyPlexJWTLogin:
19111928
"""
19121929
MyPlex JWT login class which supports getting a JWT for authenticating the client and
19131930
providing an access token to create a :class:`~plexapi.myplex.MyPlexAccount` instance.
1914-
This helper class supports a polling, threaded and callback approach.
1915-
Requires the ``PyJWT`` with ``cryptography`` packages to be installed (``pyjwt[crypto]``).
1931+
The login can be done using the four character PIN which the user must enter at
1932+
https://plex.tv/link or using Plex OAuth.
1933+
This class can also be used to refresh or verify an existing JWT.
1934+
19161935
See: https://developer.plex.tv/pms/#section/API-Info/Authenticating-with-Plex
19171936
1937+
Using this class requires the ``PyJWT`` with ``cryptography`` packages to be installed
1938+
(``pyjwt[crypto]``).
1939+
1940+
This helper class supports a polling, threaded and callback approach.
1941+
1942+
- The polling approach expects the developer to periodically check if the PIN login was
1943+
successful using :func:`~plexapi.myplex.MyPlexJWTLogin.checkLogin`.
1944+
- The threaded approach expects the developer to call
1945+
:func:`~plexapi.myplex.MyPlexJWTLogin.run` and then at a later time call
1946+
:func:`~plexapi.myplex.MyPlexJWTLogin.waitForLogin` to wait for and check the result.
1947+
- The callback approach is an extension of the threaded approach and expects the developer
1948+
to pass the ``callback`` parameter to the call to :func:`~plexapi.myplex.MyPlexJWTLogin.run`.
1949+
The callback will be called when the thread waiting for the PIN login to succeed either
1950+
finishes or expires. The parameter passed to the callback is the received authentication
1951+
token or ``None`` if the login expired.
1952+
19181953
Parameters:
19191954
session (requests.Session, optional): Use your own session object if you want to
19201955
cache the http responses from Plex.
1921-
requestTimeout (int): timeout in seconds on initial connect to plex.tv (default config.TIMEOUT).
1922-
headers (dict): A dict of X-Plex headers to send with requests.
1923-
token (str): Plex token only required to register the device initially if not using OAuth.
1924-
jwtToken (str): Existing Plex JWT to verify or refresh.
1925-
keypair (tuple[str|bytes]): A tuple of the full file paths (str) to the ED25519 private and public key pair
1926-
or the raw keys themselves (bytes) to use for signing the JWT.
1927-
scope (list[str]): List of scopes to request in the new token.
1956+
requestTimeout (int, optional): Timeout in seconds on initial connect to plex.tv (default config.TIMEOUT).
1957+
headers (dict, optional): A dict of X-Plex headers to send with requests.
1958+
oauth (bool, optional): True to use Plex OAuth instead of PIN login.
1959+
token (str, optional): Plex token only required to register the device initially if not using OAuth.
1960+
jwtToken (str, optional): Existing Plex JWT to verify or refresh.
1961+
keypair (tuple[str|bytes], optional): A tuple of the full file paths (str) to the ED25519 private and public
1962+
key pair or the raw keys themselves (bytes) to use for signing the JWT.
1963+
Use :func:`~plexapi.myplex.MyPlexJWTLogin.generateKeypair` to generate a new keypair if not provided.
1964+
scope (list[str], optional): List of scopes to request in the new token.
19281965
Default is all available scopes.
19291966
19301967
Attributes:
19311968
PINS (str): 'https://plex.tv/api/v2/pins'
19321969
AUTH (str): 'https://clients.plex.tv/api/v2/auth'
19331970
POLLINTERVAL (int): 1
19341971
SCOPES (list): List of all available scopes to request for the JWT.
1972+
pin (str): Four character PIN to use for the login at https://plex.tv/link.
19351973
finished (bool): Whether the JWT login has finished or not.
19361974
expired (bool): Whether the JWT login has expired or not.
19371975
jwtToken (str): The Plex JWT received after login or refreshing.
1976+
decodedJWT (dict): The decoded Plex JWT payload.
19381977
19391978
Example:
19401979
@@ -1947,8 +1986,8 @@ class MyPlexJWTLogin:
19471986
scopes=['username', 'email', 'friendly_name']
19481987
)
19491988
jwtlogin.generateKeypair(keyfiles=('private.key', 'public.key'))
1950-
print(f'Login to Plex at the following url:\\n{jwtlogin.oauthUrl()}')
19511989
jwtlogin.run()
1990+
print(f'Login to Plex at the following url:\\n{jwtlogin.oauthUrl()}')
19521991
jwtlogin.waitForLogin()
19531992
jwtToken = jwtlogin.jwtToken
19541993
@@ -2210,7 +2249,7 @@ def verifyJWT(self, refreshWithinDays=1):
22102249

22112250
@property
22122251
def pin(self):
2213-
""" Return the 4 character PIN used for linking a device at
2252+
""" Return the four character PIN used for linking a device at
22142253
https://plex.tv/link.
22152254
"""
22162255
if self._oauth:

0 commit comments

Comments
 (0)