Skip to content

Commit

Permalink
move refresh event in security
Browse files Browse the repository at this point in the history
client does not need to know logic behind this. It's the security job
  • Loading branch information
Kyria committed Dec 18, 2016
1 parent 5f3730d commit 1a71b23
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion esipy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
from __future__ import absolute_import
__version__ = "0.0.2"
__version__ = "0.0.3"

from .client import EsiClient # noqa
from .security import EsiSecurity # noqa
Expand Down
7 changes: 0 additions & 7 deletions esipy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from .cache import BaseCache
from .cache import DictCache
from .cache import DummyCache
from .events import after_token_refresh

from pyswagger.core import BaseClient
from requests import Request
Expand Down Expand Up @@ -34,13 +33,11 @@ def __init__(
:param headers: (optionnal) additional headers we want to add
:param transport_adapter: (optionnal) an HTTPAdapter object / implement
:param cache: (optionnal) esipy.cache.BaseCache cache implementation.
:param auth_offset: (optionnal) time in second to substract to the
expiry date of the token
"""
super(EsiClient, self).__init__(security)
self.security = security
self._session = Session()
self.auth_offset = kwargs.pop('auth_offset', 0)

# check for specified headers and update session.headers
headers = kwargs.pop('headers', {})
Expand Down Expand Up @@ -77,10 +74,6 @@ def request(self, req_and_resp, opt={}):
:return: the final response.
"""
if self.security and self.security.is_token_expired(self.auth_offset):
json_response = self.security.refresh()
after_token_refresh.send(**json_response)

# required because of inheritance
request, response = super(EsiClient, self).request(req_and_resp, opt)

Expand Down
5 changes: 5 additions & 0 deletions esipy/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import absolute_import

from . import __version__
from .events import after_token_refresh
from .exceptions import APIException

from requests import Session
Expand Down Expand Up @@ -256,6 +257,10 @@ def __call__(self, request):
if not request._security:
return request

if self.is_token_expired():
json_response = self.refresh()
after_token_refresh.send(**json_response)

for security in request._security:
if self.security_name not in security:
logger.warning(
Expand Down
File renamed without changes.

0 comments on commit 1a71b23

Please sign in to comment.