Update timeline() to use server.query to include proper headers and timeout

This commit is contained in:
Michael Shepanski 2015-08-30 20:59:25 -04:00
parent 457046f174
commit b2c9a29d1e
2 changed files with 3 additions and 5 deletions

View file

@ -93,10 +93,8 @@ class Client(object):
})
def timeline(self):
url = self.url('timeline/poll')
params = {'wait':1, 'commandID':4}
xml_text = requests.get(url, params=params, headers=BASE_HEADERS).text
return ElementTree.fromstring(xml_text)
return self.server.query('timeline/poll', params=params)
def isPlayingMedia(self):
timeline = self.timeline()

View file

@ -74,12 +74,12 @@ class PlexServer(object):
headers['X-Plex-Token'] = self.token
return headers
def query(self, path, method=requests.get):
def query(self, path, method=requests.get, **kwargs):
global TOTAL_QUERIES
TOTAL_QUERIES += 1
url = self.url(path)
log.info('%s %s', method.__name__.upper(), url)
response = method(url, headers=self.headers(), timeout=TIMEOUT)
response = method(url, headers=self.headers(), timeout=TIMEOUT, **kwargs)
if response.status_code not in [200, 201]:
codename = codes.get(response.status_code)[0]
raise BadRequest('(%s) %s' % (response.status_code, codename))