-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestRequestHandler.py
More file actions
27 lines (21 loc) · 953 Bytes
/
RestRequestHandler.py
File metadata and controls
27 lines (21 loc) · 953 Bytes
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
from httplib2 import Http
import threading
import json
class RestRequestHandler:
REQUEST_URL_CREATE = 'https://chat.googleapis.com/v1/{}/messages'
REQUEST_URL_CREATE_IN_THREAD = 'https://chat.googleapis.com/v1/{}/messages?threadKey={}'
REQUEST_URL_UPDATE = 'https://chat.googleapis.com/v1/{}?updateMask={}'
REQUEST_UPDATEMASK = 'cards,text'
REQUESTTYPE_POST = "POST"
REQUESTTYPE_PUT = "PUT"
http_auth = None
def __init__(self, creds):
self.lock = threading.Lock()
self.http_auth = creds.authorize(Http())
def send_rest_request_chat(self, url, requestType, body):
with self.lock:
response, content = self.http_auth.request(url,
method=requestType,
headers={'Content-type': 'application/json'},
body=json.dumps(body))
return json.loads(content)