mirror of
https://github.com/no2chem/wideq.git
synced 2025-05-19 08:40:25 -07:00
Inline the load/dump bits
The ol' expression problem strikes again.
This commit is contained in:
parent
ebc9c5b679
commit
8179148342
57
wideq.py
57
wideq.py
@ -204,17 +204,6 @@ class Gateway(object):
|
|||||||
gw = gateway_info()
|
gw = gateway_info()
|
||||||
return cls(gw['empUri'], gw['thinqUri'], gw['oauthUri'])
|
return cls(gw['empUri'], gw['thinqUri'], gw['oauthUri'])
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def load(cls, data):
|
|
||||||
return cls(data['auth_base'], data['api_root'], data['oauth_root'])
|
|
||||||
|
|
||||||
def dump(self):
|
|
||||||
return {
|
|
||||||
'auth_base': self.auth_base,
|
|
||||||
'api_root': self.api_root,
|
|
||||||
'oauth_root': self.oauth_root,
|
|
||||||
}
|
|
||||||
|
|
||||||
def oauth_url(self):
|
def oauth_url(self):
|
||||||
return oauth_url(self.auth_base)
|
return oauth_url(self.auth_base)
|
||||||
|
|
||||||
@ -242,16 +231,6 @@ class Auth(object):
|
|||||||
session_id = session_info['jsessionId']
|
session_id = session_info['jsessionId']
|
||||||
return Session(self, session_id), session_info['item']
|
return Session(self, session_id), session_info['item']
|
||||||
|
|
||||||
def dump(self):
|
|
||||||
return {
|
|
||||||
'access_token': self.access_token,
|
|
||||||
'refresh_token': self.refresh_token,
|
|
||||||
}
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def load(cls, gateway, data):
|
|
||||||
return cls(gateway, data['access_token'], data['refresh_token'])
|
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
"""Refresh the authentication, returning a new Auth object.
|
"""Refresh the authentication, returning a new Auth object.
|
||||||
"""
|
"""
|
||||||
@ -266,13 +245,6 @@ class Session(object):
|
|||||||
self.auth = auth
|
self.auth = auth
|
||||||
self.session_id = session_id
|
self.session_id = session_id
|
||||||
|
|
||||||
def dump(self):
|
|
||||||
return self.session_id
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def load(cls, auth, data):
|
|
||||||
return cls(auth, data)
|
|
||||||
|
|
||||||
def post(self, path, data=None):
|
def post(self, path, data=None):
|
||||||
"""Make a POST request to the API server.
|
"""Make a POST request to the API server.
|
||||||
|
|
||||||
@ -412,13 +384,19 @@ class Client(object):
|
|||||||
client = cls()
|
client = cls()
|
||||||
|
|
||||||
if 'gateway' in state:
|
if 'gateway' in state:
|
||||||
client._gateway = Gateway.load(state['gateway'])
|
data = state['gateway']
|
||||||
|
client._gateway = Gateway(
|
||||||
|
data['auth_base'], data['api_root'], data['oauth_root']
|
||||||
|
)
|
||||||
|
|
||||||
if 'auth' in state:
|
if 'auth' in state:
|
||||||
client._auth = Auth.load(client.gateway, state['auth'])
|
data = state['auth']
|
||||||
|
client._auth = Auth(
|
||||||
|
client.gateway, data['access_token'], data['refresh_token']
|
||||||
|
)
|
||||||
|
|
||||||
if 'session' in state:
|
if 'session' in state:
|
||||||
client._session = Session.load(client.auth, state['session'])
|
client._session = Session(client.auth, state['session'])
|
||||||
|
|
||||||
return client
|
return client
|
||||||
|
|
||||||
@ -426,12 +404,23 @@ class Client(object):
|
|||||||
"""Serialize the client state."""
|
"""Serialize the client state."""
|
||||||
|
|
||||||
out = {}
|
out = {}
|
||||||
|
|
||||||
if self._gateway:
|
if self._gateway:
|
||||||
out['gateway'] = self._gateway.dump()
|
out['gateway'] = {
|
||||||
|
'auth_base': self._gateway.auth_base,
|
||||||
|
'api_root': self._gateway.api_root,
|
||||||
|
'oauth_root': self._gateway.oauth_root,
|
||||||
|
}
|
||||||
|
|
||||||
if self._auth:
|
if self._auth:
|
||||||
out['auth'] = self._auth.dump()
|
out['auth'] = {
|
||||||
|
'access_token': self._auth.access_token,
|
||||||
|
'refresh_token': self._auth.refresh_token,
|
||||||
|
}
|
||||||
|
|
||||||
if self._session:
|
if self._session:
|
||||||
out['session'] = self._session.dump()
|
out['session'] = self._session.session_id
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user