mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-10 06:04:15 +00:00
Add preliminary session support
This commit is contained in:
parent
382a4f45aa
commit
b6569dc6a3
1 changed files with 8 additions and 2 deletions
|
@ -24,9 +24,10 @@ DEFAULT_BASEURI = 'http://localhost:32400'
|
|||
|
||||
class PlexServer(object):
|
||||
|
||||
def __init__(self, baseuri=None, token=None):
|
||||
def __init__(self, baseuri=None, token=None, session=None):
|
||||
self.baseuri = baseuri or DEFAULT_BASEURI
|
||||
self.token = token
|
||||
self.session = session # set this as a requests.session to use that session
|
||||
data = self._connect()
|
||||
self.friendlyName = data.attrib.get('friendlyName')
|
||||
self.machineIdentifier = data.attrib.get('machineIdentifier')
|
||||
|
@ -80,10 +81,15 @@ class PlexServer(object):
|
|||
headers['X-Plex-Token'] = self.token
|
||||
return headers
|
||||
|
||||
def query(self, path, method=requests.get, **kwargs):
|
||||
def query(self, path, method=None, **kwargs):
|
||||
global TOTAL_QUERIES
|
||||
TOTAL_QUERIES += 1
|
||||
url = self.url(path)
|
||||
if method is None:
|
||||
if self.session is not None:
|
||||
method = self.session.get
|
||||
else:
|
||||
method = requests.get
|
||||
log.info('%s %s', method.__name__.upper(), url)
|
||||
response = method(url, headers=self.headers(), timeout=TIMEOUT, **kwargs)
|
||||
if response.status_code not in [200, 201]:
|
||||
|
|
Loading…
Reference in a new issue