Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_result_is_base_when_no_path(self):
self.assertEqual(utils.urljoin(self.url), self.url)
def _get_messages(self, path=None, **params):
url = utils.urljoin(self.url, path)
response = self.session.get(url, params=params)
messages = response.data['messages']
return [Message(self, **message) for message in messages]
def check(self, results_id):
"""Check for results of a membership request.
:param str results_id: the ID of a membership request
:return: successfully created memberships
:rtype: :class:`list`
:raises groupy.exceptions.ResultsNotReady: if the results are not ready
:raises groupy.exceptions.ResultsExpired: if the results have expired
"""
path = 'results/{}'.format(results_id)
url = utils.urljoin(self.url, path)
response = self.session.get(url)
if response.status_code == 503:
raise exceptions.ResultsNotReady(response)
if response.status_code == 404:
raise exceptions.ResultsExpired(response)
return response.data['members']
def post(self, bot_id, text, attachments=None):
"""Post a new message as a bot to its room.
:param str bot_id: the ID of the bot
:param str text: the text of the message
:param attachments: a list of attachments
:type attachments: :class:`list`
:return: ``True`` if successful
:rtype: bool
"""
url = utils.urljoin(self.url, 'post')
payload = dict(bot_id=bot_id, text=text)
if attachments:
payload['attachments'] = [a.to_json() for a in attachments]
response = self.session.post(url, json=payload)
return response.ok
def __init__(self, session, path=None):
self.session = session
self.url = utils.urljoin(self.base_url, path)
def list_former(self):
"""List all former groups.
:return: a list of groups
:rtype: :class:`list`
"""
url = utils.urljoin(self.url, 'former')
response = self.session.get(url)
return [Group(self, **group) for group in response.data]
def get_next_page_param(self, item):
return utils.get_rfc3339(item.created_at)
def upload(self, fp):
url = utils.urljoin(self.url, 'pictures')
response = self.session.post(url, files={'file': fp})
image_urls = response.data['payload']
return image_urls