Skip to content

Commit ed19834

Browse files
committedJan 11, 2020
Merge branch 'develop'
2 parents 9f1b8bc + a966137 commit ed19834

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed
 

‎arcsecond/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
"ArcsecondConnectionError",
88
"ArcsecondInvalidEndpointError"]
99

10-
__version__ = '0.7.1'
10+
__version__ = '0.7.2'

‎arcsecond/api/main.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@
5454
VALID_PREFIXES = {'dataset': 'datasets/'}
5555

5656

57+
def get_api_state(state=None, **kwargs):
58+
state = state or State(is_using_cli=False)
59+
60+
if 'debug' in kwargs.keys():
61+
state.debug = kwargs.get('debug')
62+
if 'verbose' in kwargs.keys():
63+
state.verbose = kwargs.get('verbose')
64+
if 'organisation' in kwargs.keys():
65+
state.organisation = kwargs.get('organisation')
66+
67+
return state
68+
69+
5770
def set_api_factory(cls):
5871
def factory(endpoint_class, state, **kwargs):
5972
return ArcsecondAPI(endpoint_class, state, **kwargs)
@@ -82,18 +95,11 @@ def register(cls, username, email, password1, password2, state=None):
8295

8396
class ArcsecondAPI(object):
8497
def __init__(self, endpoint_class=None, state=None, **kwargs):
85-
self.state = state or State(is_using_cli=False)
98+
self.state = get_api_state(state, **kwargs)
8699

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

90-
if 'debug' in kwargs.keys():
91-
self.state.debug = kwargs.get('debug')
92-
if 'verbose' in kwargs.keys():
93-
self.state.verbose = kwargs.get('verbose')
94-
if 'organisation' in kwargs.keys():
95-
self.state.organisation = kwargs.get('organisation')
96-
97103
prefix = kwargs.get('prefix', '')
98104
possible_prefixes = set(kwargs.keys()).intersection(VALID_PREFIXES.keys())
99105
if len(possible_prefixes) > 1:
@@ -224,11 +230,12 @@ def _get_and_save_api_key(cls, state, username, auth_token):
224230

225231
@classmethod
226232
def is_logged_in(cls, state=None):
233+
state = get_api_state(state)
227234
return config_file_read_api_key(debug=state.debug) is not None
228235

229236
@classmethod
230237
def login(cls, username, password, subdomain, state=None):
231-
state = state or State()
238+
state = get_api_state(state)
232239
result, error = AuthAPIEndPoint(state).login(username, password)
233240
if error:
234241
return ArcsecondAPI._echo_error(state, error)
@@ -240,7 +247,7 @@ def login(cls, username, password, subdomain, state=None):
240247

241248
@classmethod
242249
def register(cls, username, email, password1, password2, state=None):
243-
state = state or State()
250+
state = get_api_state(state)
244251
result, error = AuthAPIEndPoint(state).register(username, email, password1, password2)
245252
if error:
246253
return ArcsecondAPI._echo_error(state, error)

0 commit comments

Comments
 (0)
Please sign in to comment.