Skip to content

Commit

Permalink
Plumbing to work with the internal API
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillmanjr committed Feb 18, 2018
1 parent 04bccb3 commit 3ef76fa
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions snakeStorm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,30 @@
__all__ = ['Client']

APIVERSION = 'bleed'
APIBASE = 'https://api.stormondemand.com'
APIBASE = {
'public': 'https://api.stormondemand.com',
'internal': 'https://api.int.liquidweb.com',
}
APIPORT = 443

DOCBASE = 'https://cart.liquidweb.com/storm/api/docs'
DOCBASE = {
'public': 'https://cart.liquidweb.com/storm/api/docs',
'internal': 'https://billing.int.liquidweb.com/mysql/content/admin/api/internal/docs',
}


def get_api_methods(api_version=APIVERSION):
def get_api_methods(api_version=APIVERSION, environment='public', need_creds=False, creds=None):
"""
Return a dictionary of methods and associated parameters and outputs
"""

method_dict = {}
api_docs = requests.get(DOCBASE + '/' + api_version + '/docs.json').json()
request_args = {
'url': DOCBASE[environment] + '/' + api_version + '/docs.json'
}
if need_creds:
request_args['auth'] = creds
api_docs = requests.get(**request_args).json()
for group_name, group in api_docs.items():
for method_name, method_specs in group['__methods'].items():
full_method = group_name.lower() + '/' + method_name.lower()
Expand All @@ -33,10 +44,10 @@ def get_api_methods(api_version=APIVERSION):
'outputs': [],
}

for param in method_specs['__input'].keys():
for param in (method_specs['__input'] or {}).keys():
method_dict[full_method]['parameters'].append(param)

for output in method_specs['__output'].keys():
for output in (method_specs['__output'] or {}).keys():
method_dict[full_method]['outputs'].append(output)

return method_dict
Expand All @@ -49,12 +60,15 @@ class Client:
def __getattr__(self, item):
pass

def __init__(self, username, password, api_version=APIVERSION, api_base=APIBASE, api_port=APIPORT):
def __init__(self, username, password, api_version=APIVERSION, api_base=APIBASE['public'], api_port=APIPORT,
environment='public', need_doc_creds=False):
self.username = username
self.password = password
self.environment = environment
self.api_version = APIVERSION
self.base_uri = api_base + ':' + str(api_port) + '/' + api_version
self.api_methods = get_api_methods(self.api_version)
self.api_methods = get_api_methods(self.api_version, self.environment, creds=(self.username, self.password),
need_creds=need_doc_creds)
self.endpoint = MethodGroup()

# Build out the endpoints
Expand Down

0 comments on commit 3ef76fa

Please # to comment.