コード例 #1
0
ファイル: groups.py プロジェクト: rhgrant10/Groupy
    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]
コード例 #2
0
    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]
コード例 #3
0
ファイル: groups.py プロジェクト: rhgrant10/Groupy
    def get(self, id):
        """Get a single group by ID.

        :param str id: a group ID
        :return: a group
        :rtype: :class:`~groupy.api.groups.Group`
        """
        url = utils.urljoin(self.url, id)
        response = self.session.get(url)
        return Group(self, **response.data)
コード例 #4
0
    def get(self, id):
        """Get a single group by ID.

        :param str id: a group ID
        :return: a group
        :rtype: :class:`~groupy.api.groups.Group`
        """
        url = utils.urljoin(self.url, id)
        response = self.session.get(url)
        return Group(self, **response.data)
コード例 #5
0
    def destroy(self, bot_id):
        """Destroy a bot.

        :param str bot_id: the ID of the bot to destroy
        :return: ``True`` if successful
        :rtype: bool
        """
        url = utils.urljoin(self.url, 'destroy')
        payload = {'bot_id': bot_id}
        response = self.session.post(url, json=payload)
        return response.ok
コード例 #6
0
ファイル: groups.py プロジェクト: rhgrant10/Groupy
    def destroy(self, id):
        """Destroy a group.

        :param str id: a group ID
        :return: ``True`` if successful
        :rtype: bool
        """
        path = '{}/destroy'.format(id)
        url = utils.urljoin(self.url, path)
        response = self.session.post(url)
        return response.ok
コード例 #7
0
    def destroy(self, id):
        """Destroy a group.

        :param str id: a group ID
        :return: ``True`` if successful
        :rtype: bool
        """
        path = '{}/destroy'.format(id)
        url = utils.urljoin(self.url, path)
        response = self.session.post(url)
        return response.ok
コード例 #8
0
ファイル: groups.py プロジェクト: rhgrant10/Groupy
    def rejoin(self, group_id):
        """Rejoin a former group.

        :param str group_id: the group_id of a group
        :return: the group
        :rtype: :class:`~groupy.api.groups.Group`
        """
        url = utils.urljoin(self.url, 'join')
        payload = {'group_id': group_id}
        response = self.session.post(url, json=payload)
        return Group(self, **response.data)
コード例 #9
0
    def rejoin(self, group_id):
        """Rejoin a former group.

        :param str group_id: the group_id of a group
        :return: the group
        :rtype: :class:`~groupy.api.groups.Group`
        """
        url = utils.urljoin(self.url, 'join')
        payload = {'group_id': group_id}
        response = self.session.post(url, json=payload)
        return Group(self, **response.data)
コード例 #10
0
    def remove(self, membership_id):
        """Remove a member from the group.

        :param str membership_id: the ID of a member in this group
        :return: ``True`` if the member was successfully removed
        :rtype: bool
        """
        path = '{}/remove'.format(membership_id)
        url = utils.urljoin(self.url, path)
        payload = {'membership_id': membership_id}
        response = self.session.post(url, json=payload)
        return response.ok
コード例 #11
0
ファイル: memberships.py プロジェクト: rhgrant10/Groupy
    def remove(self, membership_id):
        """Remove a member from the group.

        :param str membership_id: the ID of a member in this group
        :return: ``True`` if the member was successfully removed
        :rtype: bool
        """
        path = '{}/remove'.format(membership_id)
        url = utils.urljoin(self.url, path)
        payload = {'membership_id': membership_id}
        response = self.session.post(url, json=payload)
        return response.ok
コード例 #12
0
    def join(self, group_id, share_token):
        """Join a group using a share token.

        :param str group_id: the group_id of a group
        :param str share_token: the share token
        :return: the group
        :rtype: :class:`~groupy.api.groups.Group`
        """
        path = '{}/join/{}'.format(group_id, share_token)
        url = utils.urljoin(self.url, path)
        response = self.session.post(url)
        group = response.data['group']
        return Group(self, **group)
コード例 #13
0
ファイル: groups.py プロジェクト: rhgrant10/Groupy
    def join(self, group_id, share_token):
        """Join a group using a share token.

        :param str group_id: the group_id of a group
        :param str share_token: the share token
        :return: the group
        :rtype: :class:`~groupy.api.groups.Group`
        """
        path = '{}/join/{}'.format(group_id, share_token)
        url = utils.urljoin(self.url, path)
        response = self.session.post(url)
        group = response.data['group']
        return Group(self, **group)
コード例 #14
0
ファイル: attachments.py プロジェクト: rhgrant10/Groupy
    def upload(self, fp):
        """Upload image data to the image service.

        Call this, rather than :func:`from_file`, you don't want to
        create an attachment of the image.

        :param file fp: a file object containing binary image data
        :return: the URLs for the image uploaded
        :rtype: dict
        """
        url = utils.urljoin(self.url, 'pictures')
        response = self.session.post(url, data=fp.read())
        image_urls = response.data
        return image_urls
コード例 #15
0
ファイル: attachments.py プロジェクト: hallcc/DnD-Bot
    def upload(self, fp):
        """Upload image data to the image service.

        Call this, rather than :func:`from_file`, you don't want to
        create an attachment of the image.

        :param file fp: a file object containing binary image data
        :return: the URLs for the image uploaded
        :rtype: dict
        """
        url = utils.urljoin(self.url, 'pictures')
        response = self.session.post(url, files={'file': fp})
        image_urls = response.data['payload']
        return image_urls
コード例 #16
0
    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']
コード例 #17
0
ファイル: memberships.py プロジェクト: rhgrant10/Groupy
    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']
コード例 #18
0
    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
コード例 #19
0
ファイル: memberships.py プロジェクト: rhgrant10/Groupy
    def add_multiple(self, *users):
        """Add multiple users to the group at once.

        Each given user must be a dictionary containing a nickname and either
        an email, phone number, or user_id.

        :param args users: the users to add
        :return: a membership request
        :rtype: :class:`MembershipRequest`
        """
        guid = uuid.uuid4()
        for i, user_ in enumerate(users):
            user_['guid'] = '{}-{}'.format(guid, i)

        payload = {'members': users}
        url = utils.urljoin(self.url, 'add')
        response = self.session.post(url, json=payload)
        return MembershipRequest(self, *users, group_id=self.group_id,
                                 **response.data)
コード例 #20
0
    def update(self,
               id,
               name=None,
               description=None,
               image_url=None,
               office_mode=None,
               share=None,
               **kwargs):
        """Update the details of a group.

        .. note::

            There are significant bugs in this endpoint!
            1. not providing ``name`` produces 400: "Topic can't be blank"
            2. not providing ``office_mode`` produces 500: "sql: Scan error on
            column index 14: sql/driver: couldn't convert <nil> (<nil>) into
            type bool"

            Note that these issues are "handled" automatically when calling
            update on a :class:`~groupy.api.groups.Group` object.

        :param str id: group ID
        :param str name: group name (140 characters maximum)
        :param str description: short description (255 characters maximum)
        :param str image_url: GroupMe image service URL
        :param bool office_mode: (undocumented)
        :param bool share: whether to generate a share URL
        :return: an updated group
        :rtype: :class:`~groupy.api.groups.Group`
        """
        path = '{}/update'.format(id)
        url = utils.urljoin(self.url, path)
        payload = {
            'name': name,
            'description': description,
            'image_url': image_url,
            'office_mode': office_mode,
            'share': share,
        }
        payload.update(kwargs)
        response = self.session.post(url, json=payload)
        return Group(self, **response.data)
コード例 #21
0
    def change_owners(self, group_id, owner_id):
        """Change the owner of a group.

        .. note:: you must be the owner to change owners

        :param str group_id: the group_id of a group
        :param str owner_id: the ID of the new owner
        :return: the result
        :rtype: :class:`~groupy.api.groups.ChangeOwnersResult`
        """
        url = utils.urljoin(self.url, 'change_owners')
        payload = {
            'requests': [{
                'group_id': group_id,
                'owner_id': owner_id,
            }],
        }
        response = self.session.post(url, json=payload)
        result, = response.data['results']  # should be exactly one
        return ChangeOwnersResult(**result)
コード例 #22
0
ファイル: groups.py プロジェクト: rhgrant10/Groupy
    def change_owners(self, group_id, owner_id):
        """Change the owner of a group.

        .. note:: you must be the owner to change owners

        :param str group_id: the group_id of a group
        :param str owner_id: the ID of the new owner
        :return: the result
        :rtype: :class:`~groupy.api.groups.ChangeOwnersResult`
        """
        url = utils.urljoin(self.url, 'change_owners')
        payload = {
            'requests': [{
                'group_id': group_id,
                'owner_id': owner_id,
            }],
        }
        response = self.session.post(url, json=payload)
        result, = response.data['results']  # should be exactly one
        return ChangeOwnersResult(**result)
コード例 #23
0
    def add_multiple(self, *users):
        """Add multiple users to the group at once.

        Each given user must be a dictionary containing a nickname and either
        an email, phone number, or user_id.

        :param args users: the users to add
        :return: a membership request
        :rtype: :class:`MembershipRequest`
        """
        guid = uuid.uuid4()
        for i, user_ in enumerate(users):
            user_['guid'] = '{}-{}'.format(guid, i)

        payload = {'members': users}
        url = utils.urljoin(self.url, 'add')
        response = self.session.post(url, json=payload)
        return MembershipRequest(self,
                                 *users,
                                 group_id=self.group_id,
                                 **response.data)
コード例 #24
0
ファイル: groups.py プロジェクト: rhgrant10/Groupy
    def update(self, id, name=None, description=None, image_url=None,
               office_mode=None, share=None, **kwargs):
        """Update the details of a group.

        .. note::

            There are significant bugs in this endpoint!
            1. not providing ``name`` produces 400: "Topic can't be blank"
            2. not providing ``office_mode`` produces 500: "sql: Scan error on
            column index 14: sql/driver: couldn't convert <nil> (<nil>) into
            type bool"

            Note that these issues are "handled" automatically when calling
            update on a :class:`~groupy.api.groups.Group` object.

        :param str id: group ID
        :param str name: group name (140 characters maximum)
        :param str description: short description (255 characters maximum)
        :param str image_url: GroupMe image service URL
        :param bool office_mode: (undocumented)
        :param bool share: whether to generate a share URL
        :return: an updated group
        :rtype: :class:`~groupy.api.groups.Group`
        """
        path = '{}/update'.format(id)
        url = utils.urljoin(self.url, path)
        payload = {
            'name': name,
            'description': description,
            'image_url': image_url,
            'office_mode': office_mode,
            'share': share,
        }
        payload.update(kwargs)
        response = self.session.post(url, json=payload)
        return Group(self, **response.data)
コード例 #25
0
 def disable(self):
     url = utils.urljoin(self.url, 'delete')
     response = self.session.post(url)
     return response.ok
コード例 #26
0
 def update(self, **params):
     url = utils.urljoin(self.url, 'update')
     response = self.session.post(url, json=params)
     return response.data
コード例 #27
0
 def get_me(self):
     url = utils.urljoin(self.url, 'me')
     response = self.session.get(url)
     return response.data
コード例 #28
0
ファイル: messages.py プロジェクト: niranjanravi/Groupy
 def unlike(self):
     """Unlike the message."""
     url = utils.urljoin(self.url, 'unlike')
     response = self.session.post(url)
     return response.ok
コード例 #29
0
ファイル: messages.py プロジェクト: niranjanravi/Groupy
 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]
コード例 #30
0
ファイル: base.py プロジェクト: srr013/GroupMeStats
 def __init__(self, session, path=None):
     self.session = session
     self.url = utils.urljoin(self.base_url, path)
コード例 #31
0
 def test_path_appending(self):
     url = utils.urljoin(self.url, 'bar')
     self.assertEqual(url, 'http://example.com/foo/bar')
コード例 #32
0
ファイル: messages.py プロジェクト: rhgrant10/Groupy
 def unlike(self):
     """Unlike the message."""
     url = utils.urljoin(self.url, 'unlike')
     response = self.session.post(url)
     return response.ok
コード例 #33
0
ファイル: messages.py プロジェクト: rhgrant10/Groupy
 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]
コード例 #34
0
 def test_result_is_base_when_no_path(self):
     self.assertEqual(utils.urljoin(self.url), self.url)