-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-api.py
73 lines (47 loc) · 1.72 KB
/
test-api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#
# Example of logging in with a Curl call and getting a token
# https://predix-toolkit.run.aws-usw02-pr.ice.predix.io/#!/clientLogin
#
import requests
import base64
import json
client_id = 'a4028f56-2e1c-e4da-d6a7-a7f1eb600801'
client_name = 'SDRDL'
secret = "838dZk-'C."
uua_url = 'https://624eff02-dbb1-4c6c-90bc-fa85a29e5fa8.predix-uaa.run.aws-usw02-pr.ice.predix.io'
def get_token(uaa, client, secret):
cs = (client + ':' + secret).encode('ascii')
credentials = base64.b64encode(cs)
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Cache-Control': 'no-cache',
'Authorization': b'Basic ' + credentials
}
params = {
'client_id': client,
'grant_type': 'client_credentials'
}
response = requests.post(uaa, headers=headers, data=params)
return json.loads(response.text)['access_token']
token = get_token(uua_url+'/oauth/token', client_id, secret)
#
# Only useful documentation:
# https://www.programmableweb.com/news/how-ge-current-apis-power-smart-city-applications/sponsored-content/2016/07/21?page=1
#
metadata_url = 'https://ic-metadata-service-sandiego.run.aws-usw02-pr.ice.predix.io'
bbox = '32.715675:-117.161230,32.708498:-117.151681'
def get_assets(url, token, zone, bbox, device_type):
url = url + '/v1/assets/search'
headers = {
'Authorization': 'Bearer ' + token,
'Predix-Zone-Id': zone
}
params = {
'q': 'device-type:' + device_type,
'bbox': bbox,
}
r = requests.get(url, headers=headers, params=params)
r.raise_for_status()
return r.text
#return json.loads(response.text)['_embedded']['assets']
print(get_assets(metadata_url, token, '', bbox, 'DATASIM'))