Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
onekiloparsec committed Jan 11, 2020
2 parents 9f1b8bc + a966137 commit ed19834
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion arcsecond/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
"ArcsecondConnectionError",
"ArcsecondInvalidEndpointError"]

__version__ = '0.7.1'
__version__ = '0.7.2'
27 changes: 17 additions & 10 deletions arcsecond/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@
VALID_PREFIXES = {'dataset': 'datasets/'}


def get_api_state(state=None, **kwargs):
state = state or State(is_using_cli=False)

if 'debug' in kwargs.keys():
state.debug = kwargs.get('debug')
if 'verbose' in kwargs.keys():
state.verbose = kwargs.get('verbose')
if 'organisation' in kwargs.keys():
state.organisation = kwargs.get('organisation')

return state


def set_api_factory(cls):
def factory(endpoint_class, state, **kwargs):
return ArcsecondAPI(endpoint_class, state, **kwargs)
Expand Down Expand Up @@ -82,18 +95,11 @@ def register(cls, username, email, password1, password2, state=None):

class ArcsecondAPI(object):
def __init__(self, endpoint_class=None, state=None, **kwargs):
self.state = state or State(is_using_cli=False)
self.state = get_api_state(state, **kwargs)

if not self.__class__.is_logged_in(self.state):
raise ArcsecondNotLoggedInError()

if 'debug' in kwargs.keys():
self.state.debug = kwargs.get('debug')
if 'verbose' in kwargs.keys():
self.state.verbose = kwargs.get('verbose')
if 'organisation' in kwargs.keys():
self.state.organisation = kwargs.get('organisation')

prefix = kwargs.get('prefix', '')
possible_prefixes = set(kwargs.keys()).intersection(VALID_PREFIXES.keys())
if len(possible_prefixes) > 1:
Expand Down Expand Up @@ -224,11 +230,12 @@ def _get_and_save_api_key(cls, state, username, auth_token):

@classmethod
def is_logged_in(cls, state=None):
state = get_api_state(state)
return config_file_read_api_key(debug=state.debug) is not None

@classmethod
def login(cls, username, password, subdomain, state=None):
state = state or State()
state = get_api_state(state)
result, error = AuthAPIEndPoint(state).login(username, password)
if error:
return ArcsecondAPI._echo_error(state, error)
Expand All @@ -240,7 +247,7 @@ def login(cls, username, password, subdomain, state=None):

@classmethod
def register(cls, username, email, password1, password2, state=None):
state = state or State()
state = get_api_state(state)
result, error = AuthAPIEndPoint(state).register(username, email, password1, password2)
if error:
return ArcsecondAPI._echo_error(state, error)
Expand Down

0 comments on commit ed19834

Please sign in to comment.