Commit b97335fd authored by Andrew Buddenberg's avatar Andrew Buddenberg
Browse files

Added varargs support to constructor

parent 23e39498
...@@ -79,12 +79,26 @@ class AssociationException(Exception): ...@@ -79,12 +79,26 @@ class AssociationException(Exception):
class GcisClient(object): class GcisClient(object):
def __init__(self, url, username, api_key): def __init__(self, *args, **kwargs):
self.base_url = url username = None
api_key = None
#Handle varargs
#User only specifies url
if len(args) == 1:
self.base_url = args[0]
#User provides url, username, and key
elif len(args) == 3:
self.base_url = args[0]
username, api_key == args[1:3]
#User provides none or inconsistent args
else:
print 'Using http://data.globalchange.gov'
self.base_url = 'http://data.globalchange.gov'
#If credentials were not provided, obtain them #If credentials were not provided, obtain them
if username is None or api_key is None: if username is None or api_key is None:
username, api_key = get_credentials(url) username, api_key = get_credentials(self.base_url)
self.s = requests.Session() self.s = requests.Session()
self.s.auth = (username, api_key) self.s.auth = (username, api_key)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment