diff options
author | kballou <kballou@devnulllabs.io> | 2015-04-10 14:47:34 -0600 |
---|---|---|
committer | kballou <kballou@devnulllabs.io> | 2015-04-10 18:03:43 -0600 |
commit | 243acb83f520cb5cf18de2095d63e08ff086969c (patch) | |
tree | 1b55aaa316a36613380412b95525df88abae19a8 /pylibchorus/__init__.py | |
parent | cb884b11cdcf75a8b5ad82fe16069df6b2c1b1e2 (diff) | |
download | pylibchorus-243acb83f520cb5cf18de2095d63e08ff086969c.tar.gz pylibchorus-243acb83f520cb5cf18de2095d63e08ff086969c.tar.xz |
Refactor: Move ChorusSession to pylibchorus
In moving ChorusSession to the top level of pylibchorus, we are also
moving/exposing API functions.
Diffstat (limited to 'pylibchorus/__init__.py')
-rw-r--r-- | pylibchorus/__init__.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pylibchorus/__init__.py b/pylibchorus/__init__.py index 7e473c2..67fdd10 100644 --- a/pylibchorus/__init__.py +++ b/pylibchorus/__init__.py @@ -2,5 +2,36 @@ '''PyLibChorus -- Python Chorus API Library''' import logging +from pylibchorus.chorus_client import login +from pylibchorus.chorus_client import logout +from pylibchorus.chorus_client import check_login_status LOG = logging.getLogger(__name__) + +#pylint: disable=R0903 +class ChorusSession(object): + '''Chorus User Session Object''' + + def __init__(self, config): + self.config = config + self.sid = None + self.cookies = None + + def __enter__(self): + '''create session and return sid and cookies''' + + LOG.debug("Opening Chorus Session") + post = login( + self.config.get('alpine', 'username'), + self.config.get('alpine', 'password'), + self) + json = post.json() + + self.sid = json['response']['session_id'] + self.cookies = post.cookies + return self + + def __exit__(self, _type, _value, _traceback): + '''Close chorus session''' + LOG.debug("Closing Chorus Session") + logout(self) |