Example #1
0
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
Example #2
0
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
Example #3
0
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
Example #4
0
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
Example #5
0
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
Example #6
0
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
Example #7
0
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
Example #8
0
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
Example #9
0
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
Example #10
0
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
Example #11
0
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
Example #12
0
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
Example #13
0
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
Example #14
0
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
Example #15
0
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
Example #16
0
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
Example #17
0
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
Example #18
0
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
Example #19
0
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
Example #20
0
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