-
Notifications
You must be signed in to change notification settings - Fork 0
/
sparkapi.py
49 lines (42 loc) · 1.4 KB
/
sparkapi.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
#!/usr/bin/python
import unirest
import json
#TBD change to dynamically detected bot key
hard_key = 'Bearer '
class sparkapi:
def __init( self, x=0):
self.key = hard_key
def get_msg(self,id):
response = unirest.get("https://api.ciscospark.com/v1/messages/"+id,
headers={
"Authorization": hard_key
}
)
cmnd_text = response.body['text'].split(' ',1)
print cmnd_text
#cmnd_list = cmnd_text[1].split('|')
#print string
return cmnd_text
def post_msg(self,grp,msg):
response = unirest.post("https://api.ciscospark.com/v1/messages/",
headers={
"Authorization": hard_key,
"Content-Type": "application/json"
},
params=json.dumps({"roomId":grp,"text":msg})
)
print response.body
def post_file(self,grp,file_o):
response = unirest.post("https://api.ciscospark.com/v1/messages/",
headers={
"Authorization": hard_key,
"Content-Type": "application/json"},
params=json.dumps({"roomId":grp,"files":["https://secret-brushlands-95547.herokuapp.com/imgs/"+file_o]})
)
def post_txt_file(self,grp,file_o):
response = unirest.post("https://api.ciscospark.com/v1/messages/",
headers={
"Authorization": hard_key,
"Content-Type": "application/json"},
params=json.dumps({"roomId":grp,"files":["https://secret-brushlands-95547.herokuapp.com/txt/"+file_o]})
)