Skip to content
This repository was archived by the owner on Aug 21, 2018. It is now read-only.

Commit 87c04c1

Browse files
committed
updates
1 parent be62b81 commit 87c04c1

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

module04/lab04-learning-python-json/spark-room.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import requests
33

4-
accessToken = "ZjU1ZWEyNWMtYjI0MC00NGI5LTgyM2UtN2FlNmQzOWU5NjlhMzRiZmJlMDYtYzcx" #put your access token here between the quotes.
4+
accessToken = "" #put your access token here between the quotes.
55

66

77
def setHeaders():

module04/lab05-mission/spark.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import json
2+
import requests
3+
4+
ACCESS_TOKEN = "" #put your access token between the quotes
5+
ROOM_NAME = "" #give the room you will create a name
6+
YOUR_MESSAGE = "" #put the message that you will post to the room
7+
8+
#sets the header to be used for authentication and data format to be sent.
9+
def setHeaders():
10+
accessToken_hdr = 'Bearer ' + ACCESS_TOKEN
11+
spark_header = {'Authorization': accessToken_hdr, 'Content-Type': 'application/json; charset=utf-8'}
12+
return (spark_header)
13+
14+
15+
# creates a new room and returns the room id.
16+
# Mission: Add code to parse and return the room id
17+
def createRoom(the_header,room_name):
18+
roomInfo = '{"title" :"' + room_name + '"}'
19+
uri = 'https://api.ciscospark.com/v1/rooms'
20+
resp = requests.post(uri, data=roomInfo, headers=the_header)
21+
var = resp.json()
22+
print("createRoom JSON: ", var)
23+
#add code here to parse and return the room id.
24+
25+
26+
# adds a new member to the room. Member e-mail is test@test.com
27+
def addMembers(the_header,roomId):
28+
member = '{"roomId":"' + roomId + '","personEmail": "test@test.com", "isModerator": false}'
29+
uri = 'https://api.ciscospark.com/v1/memberships'
30+
resp = requests.post(uri, data=member, headers=the_header)
31+
print("addMembers JSON: ", resp.json())
32+
33+
#posts a message to the room
34+
def postMsg(the_header,roomId,message):
35+
message = '{"roomId":"' + roomId + '","text":"'+message+'"}'
36+
uri = 'https://api.ciscospark.com/v1/messages'
37+
resp = requests.post(uri, data=message, headers=the_header)
38+
print("postMsg JSON: ", resp.json())
39+
40+
#Mission write code to retrieve and display about the room
41+
def getRoomInfo(the_header,roomId):
42+
print("In function getRoomInfo")
43+
44+
45+
if __name__ == '__main__':
46+
header=setHeaders()
47+
#passing the ROOM_NAME for the room to be created
48+
room_id=createRoom(header,ROOM_NAME)
49+
#passing roomId to members function here to add member to the room.
50+
addMembers(header,room_id)
51+
#passing roomId to message function here to Post Message to a room.
52+
postMsg(header,room_id,YOUR_MESSAGE)
53+
54+

0 commit comments

Comments
 (0)