Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion plexapi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,26 @@ def account(self):
data = self.query(Account.key)
return Account(self, data)

def claim(self, account):
""" Claim the Plex server using a :class:`~plexapi.myplex.MyPlexAccount`.
This will only work with an unclaimed server on localhost or the same subnet.

Parameters:
account (:class:`~plexapi.myplex.MyPlexAccount`): The account used to
claim the server.
"""
key = '/myplex/claim'
params = {'token': account.claimToken()}
data = self.query(key, method=self._session.post, params=params)
return Account(self, data)

def unclaim(self):
""" Unclaim the Plex server. This will remove the server from your
:class:`~plexapi.myplex.MyPlexAccount`.
"""
data = self.query(Account.key, method=self._session.delete)
return Account(self, data)

@property
def activities(self):
"""Returns all current PMS activities."""
Expand All @@ -209,7 +229,7 @@ def agents(self, mediaType=None):
return self.fetchItems(key)

def createToken(self, type='delegation', scope='all'):
"""Create a temp access token for the server."""
""" Create a temp access token for the server. """
if not self._token:
# Handle unclaimed servers
return None
Expand Down
10 changes: 10 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,16 @@ def test_server_account(plex):
assert re.match(utils.REGEX_EMAIL, account.username)


@pytest.mark.authenticated
def test_server_claim_unclaim(plex, account):
server_account = plex.account()
assert server_account.signInState == 'ok'
result = plex.unclaim()
assert result.signInState == 'none'
result = plex.claim(account)
assert result.signInState == 'ok'


def test_server_downloadLogs(tmpdir, plex):
plex.downloadLogs(savepath=str(tmpdir), unpack=True)
assert len(tmpdir.listdir()) > 1
Expand Down