def list(token, max=0): headers = {'Authorization': common._sparktoken(token)} if max: payload = {'max': max} resp = requests.get(common._sparkurl('/teams'), params=payload, headers=headers) team_dict = json.loads(resp.text) team_dict['statuscode'] = str(resp.status_code) return team_dict
def get_details(token, personId): headers = {'Authorization': common._sparktoken(token)} resp = requests.get(common._sparkurl('/people/{:s}/'.format(personId)), headers=headers) person_detail_dict = json.loads(resp.text) person_detail_dict['statuscode'] = str(resp.status_code) return person_detail_dict
def get_details(token, webhookId): headers = {'Authorization': common._sparktoken(token)} resp = requests.get(common._sparkurl('/webhooks/{:s}'.format(webhookId)), headers=headers) webhook_dict = json.loads(resp.text) webhook_dict['statuscode'] = str(resp.status_code) return webhook_dict
def create(token, roomId='', toPersonId='', toPersonEmail='', text='', markdown='', files=''): headers = {'Authorization': common._sparktoken(token), 'content-type': 'application/json'} payload = {} if roomId: payload['roomId'] = roomId if toPersonId: payload['toPersonId'] = toPersonId if toPersonEmail: payload['toPersonEmail'] = toPersonEmail if markdown: payload['markdown'] = markdown if text: payload['text'] = text if files: if re.match('.*://.*', files): # public URL files message payload['files'] = [files] resp = requests.post(url=common._sparkurl('/messages'), json=payload, headers=headers) else: # local files message filesbin = open(files, 'rb') filestype = mimetypes.guess_type(files)[0] payload['files'] = (files, filesbin, filestype) m = MultipartEncoder(fields=payload) # all payload dict is packaged and streamed headers['content-type'] = m.content_type resp = requests.post(url=common._sparkurl('/messages'), data=m, headers=headers) else: # text message resp = requests.post(url=common._sparkurl('/messages'), json=payload, headers=headers) message_dict = json.loads(resp.text) message_dict['statuscode'] = str(resp.status_code) return message_dict
def get_details(token, teamId): headers = {'Authorization': common._sparktoken(token)} payload = {'showSipAddress': 'true'} resp = requests.get(common._sparkurl('/teams/{:s}'.format(teamId)), params=payload, headers=headers) team_dict = json.loads(resp.text) team_dict['statuscode'] = str(resp.status_code) return team_dict
def update(token, teamId, name): headers = {'Authorization': common._sparktoken(token), 'content-type': 'application/json'} payload = {'name': name} resp = requests.put(url=common._sparkurl('/teams/{:s}'.format(teamId)), json=payload, headers=headers) team_dict = json.loads(resp.text) team_dict['statuscode'] = str(resp.status_code) return team_dict
def get_me(token): headers = {'Authorization': common._sparktoken(token)} resp = requests.get(common._sparkurl('/people/me'), headers=headers) # print (resp.text) me_dict = json.loads(resp.text) me_dict['statuscode'] = str(resp.status_code) return me_dict
def update(token, membershipId, isModerator): headers = {'Authorization': common._sparktoken(token), 'content-type': 'application/json'} payload = {'isModerator': isModerator} resp = requests.put(url=common._sparkurl('/memberships/{:s}'.format(membershipId)), json=payload, headers=headers) membership_dict = json.loads(resp.text) membership_dict['statuscode'] = str(resp.status_code) return membership_dict
def delete(token, roomId): headers = { 'Authorization': common._sparktoken(token), 'content-type': 'application/json' } resp = requests.delete(url=common._sparkurl('/rooms/{:s}'.format(roomId)), headers=headers) del_dict = {'statuscode': str(resp.status_code)} return del_dict
def list(token, max=0): headers = {'Authorization': common._sparktoken(token)} payload = {} if max: payload['max'] = max resp = requests.get(common._sparkurl('/webhooks'), params=payload, headers=headers) webhook_dict = json.loads(resp.text) webhook_dict['statuscode'] = str(resp.status_code) return webhook_dict
def create(token, roomId, personId='', personEmail='', isModerator=False): headers = {'Authorization': common._sparktoken(token), 'content-type': 'application/json'} payload = {'roomId': roomId} if personId: payload['personId'] = personId if personEmail: payload['personEmail'] = personEmail if isModerator: payload['isModerator'] = isModerator resp = requests.post(url=common._sparkurl('/memberships'), json=payload, headers=headers) membership_dict = json.loads(resp.text) membership_dict['statuscode'] = str(resp.status_code) return membership_dict
def list(token, roomId, mentionedPeople='', before='', beforeMessage='', max=0): headers = {'Authorization': common._sparktoken(token), 'content-type': 'application/json'} payload = {'roomId': roomId} if mentionedPeople: payload['mentionedPeople'] = mentionedPeople if before: payload['before'] = before if beforeMessage: payload['beforeMessage'] = beforeMessage if max: payload['max'] = max resp = requests.get(common._sparkurl('/messages'), params=payload, headers=headers) messages_dict = json.loads(resp.text) messages_dict['statuscode'] = str(resp.status_code) return messages_dict
def list(token, roomId='', personId='', personEmail='', max=0): headers = {'Authorization': common._sparktoken(token)} payload = {} if roomId: payload['roomId'] = roomId if personId: payload['personId'] = personId if personEmail: payload['personEmail'] = personEmail if max: payload['max'] = max resp = requests.get(common._sparkurl('/memberships'), params=payload, headers=headers) membership_dict = json.loads(resp.text) membership_dict['statuscode'] = str(resp.status_code) return membership_dict
def list(token, email='', displayName='', max=0): headers = {'Authorization': common._sparktoken(token)} payload = {} if email: payload['email'] = email if displayName: payload['displayName'] = displayName if max: payload['max'] = max resp = requests.get(common._sparkurl('/people'), params=payload, headers=headers) people_dict = json.loads(resp.text) people_dict['statuscode'] = str(resp.status_code) return people_dict
def list(token, teamId='', max=0, type=''): headers = {'Authorization': common._sparktoken(token)} payload = {} if teamId: payload['teamId'] = teamId if max: payload['max'] = max if type: payload['type'] = type resp = requests.get(common._sparkurl('/rooms'), params=payload, headers=headers) room_dict = json.loads(resp.text) room_dict['statuscode'] = str(resp.status_code) return room_dict
def update(token, roomId, title): headers = { 'Authorization': common._sparktoken(token), 'content-type': 'application/json' } payload = {'title': title} resp = requests.put(url=common._sparkurl('/rooms/{:s}'.format(roomId)), json=payload, headers=headers) room_dict = json.loads(resp.text) room_dict['statuscode'] = str(resp.status_code) return room_dict
def update(token, webhookId, name, targetUrl): headers = { 'Authorization': common._sparktoken(token), 'content-type': 'application/json' } payload = {'name': name, 'targetUrl': targetUrl} resp = requests.put(url=common._sparkurl( '/webhooks/{:s}'.format(webhookId)), json=payload, headers=headers) webhook_dict = json.loads(resp.text) webhook_dict['statuscode'] = str(resp.status_code) return webhook_dict
def create(token, title, teamId=''): headers = { 'Authorization': common._sparktoken(token), 'content-type': 'application/json' } payload = {'title': title} if teamId: payload['teamId'] = teamId resp = requests.post(url=common._sparkurl('/rooms'), json=payload, headers=headers) room_dict = json.loads(resp.text) room_dict['statuscode'] = str(resp.status_code) return room_dict
def create(token, name, targetUrl, resource, event, secret, filter=''): headers = { 'Authorization': common._sparktoken(token), 'content-type': 'application/json' } payload = { 'name': name, 'targetUrl': targetUrl, 'resource': resource, 'event': event, 'secret': secret } if filter: payload['filter'] = filter resp = requests.post(url=common._sparkurl('/webhooks'), json=payload, headers=headers) webhook_dict = json.loads(resp.text) webhook_dict['statuscode'] = str(resp.status_code) return webhook_dict
def get_details(token, membershipId): headers = {'Authorization': common._sparktoken(token)} resp = requests.get(common._sparkurl('/memberships/{:s}'.format(membershipId)), headers=headers) membership_dict = json.loads(resp.text) membership_dict['statuscode'] = str(resp.status_code) return membership_dict