Skip to content

Commit d6a5494

Browse files
committed
pair call test
1 parent e7fe4f0 commit d6a5494

File tree

3 files changed

+59
-4
lines changed

3 files changed

+59
-4
lines changed

allow2/__init__.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
import human_curl as requests
2+
import json
23

3-
def test():
4-
r = requests.get('http://h.wrttn.me/basic-auth/test_username/test_password', auth=('test_username', 'test_password'))
5-
r.status_code
4+
a2appUrl = 'https://app.allow2.com:8443'
5+
a2apiUrl = 'https://app.allow2.com:9443'
66

7-
r.content
7+
def pair(usr, pwd, deviceToken, deviceName):
8+
9+
r = requests.post(a2appUrl + '/api/pairDevice', data={
10+
'user' : usr,
11+
'pass' : pwd,
12+
'deviceToken' : deviceToken,
13+
'name' : deviceName
14+
})
15+
16+
if (r.status_code == 404):
17+
raise Exception('Authentication Failed', 404)
18+
19+
if (r.status_code != 200):
20+
raise Exception('Unexpected Error', r.status_code)
21+
22+
json_response = json.loads(r.content)
23+
24+
if json_response.get('error') or (not json_response.get('status')) or (json_response['status'] != 'success'):
25+
raise Exception(json_response['error'], 500)
26+
27+
return json_response['userId'], json_response['pairId'], json_response['children']

allow2/allow2.py

Whitespace-only changes.

pair.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/python
2+
3+
import allow2, sys, getopt
4+
5+
def usage():
6+
print 'pair.py -u <username> -p <password> <deviceToken> <deviceName>'
7+
sys.exit(2)
8+
9+
def main(argv):
10+
inputfile = ''
11+
outputfile = ''
12+
usr = None
13+
pwd = None
14+
try:
15+
opts, args = getopt.getopt(argv,"hu:p:",["ifile=","ofile="])
16+
except getopt.GetoptError:
17+
usage()
18+
for opt, arg in opts:
19+
if opt == '-h':
20+
usage()
21+
elif opt in ("-u", "--username"):
22+
usr = arg
23+
elif opt in ("-p", "--password"):
24+
pwd = arg
25+
if (len(args) != 2) or (usr is None) or (pwd is None):
26+
usage()
27+
28+
userId, pairId, children = allow2.pair(usr, pwd, args[0], args[1])
29+
30+
print 'userId: ', userId
31+
print 'pairId: ', pairId
32+
print 'children: ', children
33+
34+
if __name__ == "__main__":
35+
main(sys.argv[1:])

0 commit comments

Comments
 (0)