Skip to content

Commit

Permalink
Updating headers according to the upcoming change from Quby
Browse files Browse the repository at this point in the history
  • Loading branch information
costastf committed Apr 11, 2019
1 parent 60f7851 commit c201b85
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions toonapilib/toonapilib.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def _authenticate(self):
self._token = self._get_token(code)
self._set_headers(self._token)
self._get_agreements()
self._update_headers()
self._api_url = '{}/toon/v3/{}'.format(self._base_url,
self.agreement.id)

Expand All @@ -160,6 +161,10 @@ def _set_headers(self, token):
'content-type': 'application/json',
'cache-control': 'no-cache'}

def _update_headers(self):
self._headers.update({'X-Common-Name': self.agreement.display_common_name,
'X-Agreement-ID': self.agreement.id})

def _get_agreements(self):
url = '{base_url}/toon/v3/agreements'.format(base_url=self._base_url)
response = requests.get(url, headers=self._headers)
Expand Down Expand Up @@ -273,6 +278,7 @@ def _patched_request(self, *args, **kwargs):
self._set_headers(self._token)
kwargs['headers'].update(
{'Authorization': 'Bearer {}'.format(self._token.access_token)})
self._update_headers()
self._logger.debug('Updated headers, trying again initial request')
response = self.original_request(*args, **kwargs)
return response
Expand Down

0 comments on commit c201b85

Please sign in to comment.