Exemple #1
0
    def get(self):
        '''List all messages.
        Returns:
            List: Message(s)
        '''
        with connection() as session:
            messages = get_messages(session)
            messages = [
                marshal(msg, message_fields) for msg in messages
            ]

            return messages
Exemple #2
0
 def get(self, message_id):
     '''Get a single message.
     Params:
         message_id (unicode)
     Return:
         JSON: requested message
     '''
     with connection() as session:
         message = get_message(session, message_id)
         if message is None:
             raise MessageNotFound(message_id)
         return marshal(message, message_fields)
Exemple #3
0
    def delete(self, message_id):
        '''Delete a single message.
        Params:
            message_id (unicode)
        Returns:
            JSON: Deleted message
        '''
        with connection() as session:
            message = delete_message(session, message_id)

            if message is None:
                raise MessageNotFound(message_id)
            return marshal(message, message_fields)
Exemple #4
0
    def post(self):
        '''Add a new message
        Returns:
            JSON: New mesage
        '''
        rp = reqparse.RequestParser()
        rp.add_argument('message', type=unicode, required=True)
        rp.add_argument('username', type=unicode, required=True)
        args = rp.parse_args()

        message = args['message']
        username = args['username']

        with connection() as session:
            msg = add_message(
                session, message, username, is_palindrome(message)
            )
            msg = marshal(msg, message_fields)
            return msg