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_one_numeric_arg(self):
url = endpoint.Endpoint.build_url('{}', 1)
path = urlsplit(url).path
self.assertEqual(path, '/1')
r = requests.post(
cls.build_url(),
data=json.dumps({
'direct_message': {
'source_guid': str(time.time()),
'recipient_id': recipient_id,
'text': text,
'attachments': attachments
}
}),
headers={'content-type': 'application/json'}
)
return cls.response(r)
class Likes(Endpoint):
"""Endpoint for the likes API.
Likes can be created or destroyed.
.. note::
The ``conversation_id`` is poorly documented. For messages in a group,
it corresponds to the ``group_id`` (or ``id`` since they seem to always
be identical). For direct messages, it corresponds to the ``user_id``
of both conversation participants sorted lexicographically and
concatenated with a plus sign ("+").
"""
url = '/'.join([Endpoint.url, 'messages'])
@classmethod
return cls.response(r)
@classmethod
def destroy(cls, bot_id):
"""Destroy a bot.
:param str bot_id: the ID of the bot to destroy
"""
r = requests.post(
cls.build_url('destroy'),
params={'bot_id': bot_id}
)
return cls.response(r)
class Users(Endpoint):
"""Endpoint for the users API.
"""
url = '/'.join([Endpoint.url, 'users'])
@classmethod
def me(cls):
"""Get the user's information.
:returns: the user's information
:rtype: :class:`dict`
"""
r = requests.get(
cls.build_url('me')
)
return cls.response(r)
:rtype: :class:`dict`
"""
r = requests.post(
cls.build_url('update'),
params={
'avatar_url': avatar_url,
'name': name,
'email': email,
'zip_code': zip_code
}
)
return cls.response(r)
class Sms(Endpoint):
"""Endpoint for the SMS API.
SMS mode can be enabled or disabled.
"""
url = '/'.join([Endpoint.url, 'users', 'sms_mode'])
@classmethod
def create(cls, duration=4, registration_id=None):
"""Enable SMS mode.
:param int duration: duration of SMS mode in hours (max of 48)
:param str registration_id: the push registration_id or token to
suppress (if omitted, SMS and push notifications will both
be enabled)
"""
duration = cls.clamp(duration, 1, 48)
"""Destroy (or leave) a group.
.. note::
If you are not the owner of a group, you cannot destroy it.
:param str group_id: the ID of the group to destroy/leave
:rtype: :class:`dict`
"""
r = requests.post(
cls.build_url('{}/destroy', group_id)
)
return cls.response(r)
class Members(Endpoint):
"""Endpoint for the members API.
Members can be added and removed from a group, and the results of adding
members can be obtained.
"""
url = '/'.join([Endpoint.url, 'groups'])
@classmethod
def add(cls, group_id, *members):
"""Add one or more members to a group.
:param str group_id: the ID of the group to which the members should
be added
:param list members: the members to add.
:returns: the results ID for this request
:rtype: :class:`dict`
@classmethod
def remove(cls, group_id, member_id):
"""Remove a member from a group.
:param str group_id: the ID of the group from which the member should
be removed
:param str member_id: the ID of the member to remove
"""
r = requests.post(
cls.build_url('{}/members/{}/remove', group_id, member_id)
)
return cls.response(r)
class Messages(Endpoint):
"""Endpoint for the messages API.
Messages can be listed and created.
"""
url = '/'.join([Endpoint.url, 'groups'])
@classmethod
def index(cls, group_id,
before_id=None, since_id=None, after_id=None, limit=100):
"""List the messages from a group.
Listing messages gives the most recent 100 by default. Additional
messages can be obtained by specifying a reference message, thereby
facilitating paging through messages.
Use ``before_id`` and ``after_id`` to "page" through messages.
"""
r = requests.post(
cls.build_url('{}/messages', group_id),
data=json.dumps({
'message': {
'source_guid': str(time.time()),
'text': text,
'attachments': attachments
}
}),
headers={'content-type': 'application/json'}
)
return cls.response(r)
class DirectMessages(Endpoint):
"""Endpoint for the direct message API.
"""
url = '/'.join([Endpoint.url, 'direct_messages'])
@classmethod
def index(cls, other_user_id, before_id=None, since_id=None, after_id=None):
"""List the direct messages with another user.
:param str other_user_id: the ID of the other party
:param str before_id: a reference message ID; specify this to list
messages prior to it
:returns: a list of direct messages
:rtype: :class:`list`
"""
r = requests.get(
cls.build_url(),
'registration_id': registration_id
}
)
return cls.response(r)
@classmethod
def delete(cls):
"""Disable SMS mode.
"""
r = requests.post(
cls.build_url('delete')
)
return cls.response(r)
class Images(Endpoint):
"""Endpoint for the image service API.
GroupMe images are created through an upload service that returns a URL at
which it can be accessed.
"""
url = '/'.join([config.IMAGE_API_URL, 'pictures'])
@classmethod
def response(cls, r):
"""Extract the data from the image service API response *r*.
This method basically returns the inner "payload."
:param r: the HTTP response from an API call
:type r: :class:`requests.Response`
:returns: API response data
return cls.response(r)
@classmethod
def destroy(cls, conversation_id, message_id):
"""Unlike a message.
:param str conversation_id: the ID of the group or recipient
:param str message_id: the ID of the message
"""
r = requests.post(
cls.build_url('{}/{}/unlike', conversation_id, message_id)
)
return cls.response(r)
class Bots(Endpoint):
"""Endpoint for the bots API.
Bots can be listed, created, updated, and destroyed. Bots can also post
messages to groups.
"""
url = '/'.join([Endpoint.url, 'bots'])
@classmethod
def index(cls):
"""List bots.
:returns: a list of bots
:rtype: :class:`list`
"""
r = requests.get(
cls.build_url()
class Likes(Endpoint):
"""Endpoint for the likes API.
Likes can be created or destroyed.
.. note::
The ``conversation_id`` is poorly documented. For messages in a group,
it corresponds to the ``group_id`` (or ``id`` since they seem to always
be identical). For direct messages, it corresponds to the ``user_id``
of both conversation participants sorted lexicographically and
concatenated with a plus sign ("+").
"""
url = '/'.join([Endpoint.url, 'messages'])
@classmethod
def create(cls, conversation_id, message_id):
"""Like a message.
:param str conversation_id: the ID of the group or recipient
:param str message_id: the ID of the message
"""
r = requests.post(
cls.build_url('{}/{}/like', conversation_id, message_id)
)
return cls.response(r)
@classmethod
def destroy(cls, conversation_id, message_id):
"""Unlike a message.