How to use the groupy.api.base.Manager function in groupy

To help you get started, we’ve selected a few groupy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rhgrant10 / Groupy / tests / api / test_base.py View on Github external
def setUp(self):
        self.manager = base.Manager(mock.Mock(), path='foo')
github rhgrant10 / Groupy / groupy / api / groups.py View on Github external
from . import base
from . import bots
from . import messages
from . import memberships
from . import user
from groupy import utils
from groupy import pagers
from groupy import exceptions


class Groups(base.Manager):
    """A group manager."""

    def __init__(self, session):
        super().__init__(session, path='groups')

    def _raw_list(self, **params):
        response = self.session.get(self.url, params=params)
        if response.status_code == 304:
            return []
        return [Group(self, **group) for group in response.data]

    def list(self, page=1, per_page=10, omit=None):
        """List groups by page.

        The API allows certain fields to be excluded from the results so that
        very large groups can be fetched without exceeding the maximum
github rhgrant10 / Groupy / groupy / api / attachments.py View on Github external
:param str source_url: an optional, absolute URL for the image source
    :param str file_id: an optional file ID (used when viewing uploaded files
                        in the gallery)
    """

    def __init__(self, url, source_url=None, file_id=None):
        super().__init__(type='image', url=url, source_url=source_url,
                         file_id=file_id)


# this is documented nowhere :(
class LinkedImage(Image):
    pass


class Images(base.Manager):
    """A manager for handling image uploads/downloads."""

    #: the base url for the pictures API
    base_url = 'https://image.groupme.com/'

    def from_file(self, fp):
        """Create a new image attachment from an image file.

        :param file fp: a file object containing binary image data
        :return: an image attachment
        :rtype: :class:`~groupy.api.attachments.Image`
        """
        image_urls = self.upload(fp)
        return Image(image_urls['url'], source_url=image_urls['picture_url'])

    def upload(self, fp):
github rhgrant10 / Groupy / groupy / api / chats.py View on Github external
from . import base
from . import messages
from groupy import pagers
from groupy import utils


class Chats(base.Manager):
    """A chat manager."""

    def __init__(self, session):
        super().__init__(session, 'chats')

    def _raw_list(self, **params):
        response = self.session.get(self.url, params=params)
        return [Chat(self, **chat) for chat in response.data]

    def list(self, page=1, per_page=10):
        """List a page of chats.

        :param int page: which page
        :param int per_page: how many chats per page
        :return: chats with other users
        :rtype: :class:`~groupy.pagers.ChatList`
github rhgrant10 / Groupy / groupy / api / images.py View on Github external
from . import base
from groupy import utils


class Images(base.Manager):
    base_url = 'https://image.groupme.com/'

    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

    def download(self, url):
        response = self.session.get(url)
        return response.content
github rhgrant10 / Groupy / groupy / api / bots.py View on Github external
from . import base
from groupy import utils


class Bots(base.Manager):
    """A bot manager."""

    def __init__(self, session):
        super().__init__(session, path='bots')

    def list(self):
        """Return a list of bots.

        :return: all of your bots
        :rtype: :class:`list`
        """
        response = self.session.get(self.url)
        return [Bot(self, **bot) for bot in response.data]

    def create(self, name, group_id, avatar_url=None, callback_url=None,
               dm_notification=None, **kwargs):
github rhgrant10 / Groupy / groupy / api / messages.py View on Github external
super().__init__(session, path=path)

    def like(self):
        """Like the message."""
        url = utils.urljoin(self.url, 'like')
        response = self.session.post(url)
        return response.ok

    def unlike(self):
        """Unlike the message."""
        url = utils.urljoin(self.url, 'unlike')
        response = self.session.post(url)
        return response.ok


class Gallery(base.Manager):
    """Manager for messages in the gallery.

    This endpoint is undocumented!

    :param session: request session
    :param str group_id: group_id for a particular group
    """

    def __init__(self, session, group_id):
        path = 'conversations/{}/gallery'.format(group_id)
        super().__init__(session, path=path)

    def _raw_list(self, **params):
        response = self.session.get(self.url, params=params)
        if response.status_code == 304:
            return []
github rhgrant10 / Groupy / groupy / api / blocks.py View on Github external
from . import base


class Blocks(base.Manager):
    """Blocks manager.

    :param session: the request session
    :type session: :class:`~groupy.session.Session`
    :param str user_id: your user ID
    """

    def __init__(self, session, user_id):
        super().__init__(session, 'blocks')
        self.user_id = user_id

    def list(self):
        """List the users you have blocked.

        :return: a list of :class:`~groupy.api.blocks.Block`'s
        :rtype: :class:`list`
github rhgrant10 / Groupy / groupy / api / memberships.py View on Github external
from collections import namedtuple
import time
import uuid

from . import base
from . import messages
from . import user
from groupy import utils
from groupy import exceptions


class Memberships(base.Manager):
    """A membership manager for a particular group.

    :param session: the request session
    :type session: :class:`~groupy.session.Session`
    :param str group_id: the group_id of a group
    """

    def __init__(self, session, group_id):
        path = 'groups/{}/members'.format(group_id)
        super().__init__(session, path=path)
        self.group_id = group_id

    def add(self, nickname, email=None, phone_number=None, user_id=None):
        """Add a user to the group.

        You must provide either the email, phone number, or user_id that
github rhgrant10 / Groupy / groupy / api / messages.py View on Github external
'source_guid': source_guid or str(time.time()),
        }

        if text is not None:
            message['text'] = text

        if attachments is not None:
            message['attachments'] = [a.to_json() for a in attachments]

        payload = {'message': message}
        response = self.session.post(self.url, json=payload)
        message = response.data['message']
        return Message(self, **message)


class DirectMessages(base.Manager):
    """Manager for direct messages with a particular user.

    :param session: request session
    :param str other_user_id: user_id of another user
    """

    def __init__(self, session, other_user_id):
        super().__init__(session, 'direct_messages')
        self.other_user_id = other_user_id

    def _raw_list(self, **params):
        params['other_user_id'] = self.other_user_id
        response = self.session.get(self.url, params=params)
        if response.status_code == 304:
            return []
        messages = response.data['direct_messages']