Skip to content

Commit

Permalink
Simple tool for walking hub API versions and testing which work
Browse files Browse the repository at this point in the history
  • Loading branch information
jinnatar committed Nov 19, 2017
1 parent 31edeb9 commit fb84799
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions util/versionExplorer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
import sys
import requests
from cozify import hub
from cozify.Error import APIError

def main(start=hub.apiPath):
id = hub.getDefaultHub()
host = hub.host(id)
token = hub.token(id)
api = start

print('Testing against {0}, starting from {1}'.format(id, hub._getBase(host, api=start)))

while True:
base = hub._getBase(host, api=api)
if not ping(base, token):
print('Fail: {0}'.format(api))
else:
print('Works: {0}'.format(api))
break
api = increment(api)


def increment(apipath):
base, section, version = apipath.split('/')
next_version = round(float(version) + 0.1, 10)

return '{0}/{1}/{2}'.format(base, section, next_version)

def ping(base, hub_token):
headers = { 'Authorization': hub_token }
call = '/hub/tz'
response = requests.get(base + call, headers=headers)
if response.status_code == 200:
return True
else:
return False

if __name__ == "__main__":
if len(sys.argv) > 1:
main(sys.argv[1])
else:
main()

0 comments on commit fb84799

Please sign in to comment.