diff --git a/.gitignore b/.gitignore index 4be6e16..5df9179 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -dist/* \ No newline at end of file +build/ +dist/ \ No newline at end of file diff --git a/MANIFEST b/MANIFEST index 1a9956d..e2fbd01 100644 --- a/MANIFEST +++ b/MANIFEST @@ -2,6 +2,6 @@ setup.cfg setup.py apiary2postman/__init__.py -apiary2postman/apiary.py apiary2postman/apiary2postman.py +apiary2postman/blueprint.py apiary2postman/converter.py diff --git a/apiary2postman/converter.py b/apiary2postman/converter.py index 9cde58a..7d021eb 100644 --- a/apiary2postman/converter.py +++ b/apiary2postman/converter.py @@ -3,29 +3,60 @@ from uuid import uuid4 from time import time -def write(json_data, out=stdout, only_collection=False, pretty=False): - result = dict() - json_obj = json.loads(json_data) - - # Create the header - result['version'] = 1 - result['collections'] = [] - result['globals'] =[] - result['headerPresets'] =[] +def _buildCollectionResponse(apiary): + environment = createEnvironment(apiary) + # Create the collection + collections = parseResourceGroups( + apiary['resourceGroups'], + environment['values'], + True) + + result = { + 'id' : str(uuid4()), + 'name' : apiary['name'], + 'description' : apiary['description'], + 'timestamp' : int(time()), + 'remote_id' : 0, + 'synced' : False, + 'folders' : [], + 'requests' : [], + } + + for collection in collections: + result['folders'] += collection['folders'] + result['requests'] += collection['requests'] + + return result + +def _buildFullResponse(apiary): # Create the Environment - result['environments'] = [ createEnvironment(json_obj) ] + environment = createEnvironment(apiary) + + # Create the Header + result = { + 'version' : 1, + 'globals' : [], + 'headerPresets' : [], + 'environments' : [ environment ], + } # Create the collection result['collections'] = parseResourceGroups( - json_obj['resourceGroups'], + apiary['resourceGroups'], result['environments'][0]['values'], - only_collection ) + False) + + return result + +def write(json_data, out=stdout, only_collection=False, pretty=False): + json_obj = json.loads(json_data) - result_out = result if only_collection: - result_out = result['collections'][0] - + result_out = _buildCollectionResponse(json_obj) + else: + result_out = _buildFullResponse(json_obj) + if pretty: json.dump(result_out, out, indent=2, separators=(',', ': ')) else: