Exemple #1
0
    def get_messages(
        self, token=None, start_usec=1000, last_n=None, return_raw_json=False
    ):
        """Returns the most recent messages for this thread.

        Args:
            start_usec: Return all messages since this timestamp.
            last_n: An integer indicating the number of messages you want returned.
                This is distinct from the `count` param accepted by the Quip API,
                in that it is the total number of messages to return, not the
                total to return for a given request.

        Returns:
            A list of message dicts, sorted by their created date in ascending order
        """
        self.messages = []
        client = quip.QuipClient(token)
        COUNT = last_count = 200  # For the first iteration of the while loop
        last_usec = None

        while last_count == COUNT:
            # I think the non list comprehension version is equally unreadable
            message_dicts = [
                msg
                for msg in client.get_messages(
                    self.meta.id, max_created_usec=last_usec, count=last_n
                )
                if msg["created_usec"] > start_usec
            ]

            last_count = len(message_dicts)
            self.messages.extend(message_dicts)
            if last_count == last_n:
                break
        return self.messages
Exemple #2
0
    def send_message(
        self,
        token=None,
        frame=None,
        content=None,
        silent=False,
        return_raw_json=False,
        parts=None,
    ) -> QuipMessage:
        """Send a message to this thread.

        Args:
            frame: Controls how Quip displays the message.
            body: An integer indicating the number of messages you want returned.
                This is distinct from the `count` param accepted by the Quip API,
                in that it is the total number of messages to return, not the
                total to return for a given request.

        Returns:
            A QuipMessage instance
        """
        client = quip.QuipClient(token)
        # Using the vendored library, note that it passes keywords to the api via **kwargs
        msg_dict = client.new_message(
            self.id, content=content, silent=silent, frame=frame, parts=parts
        )
        return QuipMessage.from_dict(msg_dict)
Exemple #3
0
def _get_user_favorites(user, token):
    """Given a user dict, recursively retrieve the user's starred items."""
    starred_id = user["starred_folder_id"]
    client = quip.QuipClient(token)
    folder = client.get_folder(starred_id)
    print(folder)
    folder = QuipFolder(**folder)
    return _get_children(folder, token)
Exemple #4
0
def get_user_info(token, alias="User"):
    """Call the Quip API and get information about the authenticated user.

    Keyword args:
    alias -- the alias under which the token is stored (default "Default")
    """
    client = quip.QuipClient(token)
    user = client.get_authenticated_user()
    table = terminaltables.SingleTable(_format_user_matrix(user), alias)
    table.inner_row_border = True
    return user, table.table
Exemple #5
0
 def get_thread(token, room):
     """Instantiate a thread by calling the QuipAPI."""
     client = quip.QuipClient(token)
     thread_json = client.get_thread(room)
     return QuipThread(**thread_json)
Exemple #6
0
def _get_children(folder, token):
    """Get all child threads for this folder."""
    client = quip.QuipClient(token)
    threads = client.get_threads(folder.child_threads)
    return threads
Exemple #7
0
def send_messages(token, alias, room):
    """Call the Quip API and send a message."""
    client = quip.QuipClient(token)
    messages = client.send_messages(room)
    return messages