-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
199 lines (146 loc) · 5.7 KB
/
test.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import json
import datetime
import requests
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
def Get(url, headers, timeout=10):
try:
if not headers:
r = requests.get(url, timeout=timeout)
else:
r = requests.get(url, headers=headers, timeout=timeout)
return r.text
'''
req = urllib2.Request(url)
res = urllib2.urlopen(req)
data = res.read()
return data
'''
except Exception, e:
print("Error in getting HTTP Data\n" + str(e))
return ""
def Post(url, headers, body, timeout=10):
try:
if not headers:
if not body:
r = requests.post(url, timeout=timeout)
else:
r = requests.post(url, data=body, timeout=timeout)
else:
r = requests.post(url, headers=headers, data=body, timeout=timeout)
print("Headers: " + str(headers))
print("body: " + str(body))
print r.text
return r.text
except Exception, e:
print("Error in getting HTTP Data\n" + str(e))
return ""
BASEURL = "http://localhost:8090/"
def CreatePlayer(email, photoUrl, name, source):
url = BASEURL + "login/googleapp"
data = {}
data["email"] = email
data["photoUrl"] = photoUrl
data["displayName"] = name
data["device_source"] = source
return Post(url, None, data)
def CreateGroup(name, owner, players, picture=None):
url = BASEURL + "group/create"
data = {}
data["group_name"] = name
data["group_owner"] = owner
data["players"] = players
if picture:
data["group_picutre_url"] = name
return Post(url, None, data)
def GetGroupDetails(groupID):
url = BASEURL + "group/getdetails"
data = {}
data["group_id"] = groupID
return Post(url, None, data)
def StartSession(name, groupID, playerDetails, createdBy, currency, createdAt):
url = BASEURL + "session/start"
data = {}
data["session_name"] = name
data["group_id"] = groupID
data["player_details"] = json.dumps(playerDetails)
data["session_created_by"] = createdBy
data["session_currency"] = currency
data["created_at"] = createdAt
return Post(url, None, data)
def UpdateSession(sID, name, currency):
url = BASEURL + "session/update"
data = {}
data["session_id"] = sID
data["session_name"] = name
data["session_currency"] = currency
return Post(url, None, data)
def AddPlayersSession(sID, playerDetails, createdBy, createdAt):
url = BASEURL + "session/addplayers"
data = {}
data["session_id"] = sID
data["player_details"] = json.dumps(playerDetails)
data["created_at"] = createdAt
data["created_by"] = createdBy
return Post(url, None, data)
def GetSessionTransactions(sID):
url = BASEURL + "session/gettransactions"
data = {}
data["session_id"] = sID
return Post(url, None, data)
def EndSession(sID, playerDetails, timeat, createdBy):
url = BASEURL + "session/end"
data = {}
data["session_id"] = sID
data["player_details"] = json.dumps(playerDetails)
data["created_at"] = timeat.strftime(TIME_FORMAT)
data["created_by"] = createdBy
return Post(url, None, data)
def GetPlayerDetails(pID):
url = BASEURL + "player/getdetails"
data = {}
data["email"] = pID
return Post(url, None, data)
def UpdatePlayer(pID, name="", pic="", group=""):
url = BASEURL + "player/update"
data = {}
data["email"] = pID
#data["displayName"] = name
#data["photoUrl"] = pic
data["group"] = group
return Post(url, None, data)
def UpdateGroup(gID, name="", players=[], pic="", hidden=True):
url = BASEURL + "group/update"
data = {}
data["group_id"] = gID
data["group_name"] = name
data["players"] = json.dumps(players)
data["group_picture_url"] = pic
data["group_hidden"] = json.dumps(hidden)
return Post(url, None, data)
if __name__ == "__main__":
vikramEmail = "vikram@bst.com"
myEmail = "m.r@gmail.com"
noobieEmail = "noobie@gmail.com"
randomEmail = "someuser@gmail.com"
groupID = "5bc7a0ab-54f2-11e7-9095-17fa2f45a70c"
groupID2 = "93c6d333-54ec-11e7-9eb5-e30a7fffaeb6"
sessionID = "554f3d0c-5501-11e7-a061-39853acdfddb"
CreatePlayer(myEmail, "http://sammu.jpg", "Samyak Ranjan", "android")
CreatePlayer(vikramEmail, "http://vikram.jpg", "VikG", "ios")
CreatePlayer(noobieEmail, "http://noobie.jpg", "SohA", "android")
CreatePlayer(randomEmail, "http://foo.jpg", "Some User", "foo")
#CreatePlayer(noobieEmail, "http://newpicture.jpg", "Some User", "foo")
#ret = CreateGroup("GroupA", myEmail, json.dumps([vikramEmail, noobieEmail]))
#groupID = json.loads(ret)["group_id"]
#GetGroupDetails(groupID)
#playerDetails = { myEmail: 500, vikramEmail: 500 }
#playerDetails = { myEmail: 1000, noobieEmail: 500 }
#playerDetails = { myEmail: -1000, noobieEmail: -500 }
#StartSession("19thJune", groupID, playerDetails, noobieEmail, "INR", datetime.datetime.utcnow().strftime(TIME_FORMAT))
#UpdateSession(sessionID, "OldName", "USD")
#AddPlayersSession(sessionID, playerDetails, myEmail, datetime.datetime.utcnow().strftime(TIME_FORMAT))
#GetSessionTransactions(sessionID)
#GetPlayerDetails(myEmail)
#UpdatePlayer(randomEmail, "SomeName", "www.newurl.com", groupID2)
#UpdateGroup(groupID2, "SomeName")
#EndSession(sessionID, playerDetails, datetime.datetime.now(), noobieEmail)