def get_items_limit_offset(self, limit=None, offset=0, fields=None):
        """
        Get the items in a folder using limit-offset paging.

        :param limit:
            The maximum number of items to return per page. If not specified, then will use the server-side default.
        :type limit:
            `int` or None
        :param offset:
            The index at which to start returning items.
        :type offset:
            `int`
        :param fields:
            List of fields to request.
        :type fields:
            `Iterable` of `unicode`
        :returns:
            An iterator of the items in the folder.
        :rtype:
            :class:`BoxObjectCollection`
        """
        return LimitOffsetBasedObjectCollection(
            self.session,
            self.get_url('items'),
            limit=limit,
            fields=fields,
            offset=offset,
            return_full_pages=False,
        )
Exemple #2
0
 def _object_collection_instance(self, session, limit=None, return_full_pages=False, starting_pointer=None):
     """Baseclass override."""
     if starting_pointer is None:
         starting_pointer = 0
     return LimitOffsetBasedObjectCollection(
         session,
         '/some/endpoint',
         limit=limit,
         return_full_pages=return_full_pages,
         offset=starting_pointer,
     )
Exemple #3
0
    def test_object_collection_sets_next_pointer_correctly(self, mock_session, return_full_pages):
        page_size = 10
        object_collection = LimitOffsetBasedObjectCollection(
            mock_session,
            '/some/endpoint',
            limit=page_size,
            return_full_pages=return_full_pages,
        )

        assert object_collection.next_pointer() == 0
        object_collection.next()
        assert object_collection.next_pointer() == page_size

        # Iterate to the last page, which doesn't return a full page.
        [_ for _ in object_collection]  # pylint:disable=pointless-statement
        assert object_collection.next_pointer() == self.NUM_ENTRIES
Exemple #4
0
    def get_items(self,
                  limit=None,
                  offset=0,
                  marker=None,
                  use_marker=False,
                  sort=None,
                  direction=None,
                  fields=None):
        """
        Get the items in a folder.

        :param limit:
            The maximum number of items to return per page. If not specified, then will use the server-side default.
        :type limit:
            `int` or None
        :param offset:
            The index at which to start returning items when using offset-based pagin.
        :type offset:
            `int`
        :param use_marker:
            Whether to use marker-based paging instead of offset-based paging, defaults to False.
        :type use_marker:
            `bool`
        :param marker:
            The paging marker to start returning items from when using marker-based paging.
        :type marker:
            `unicode` or None
        :param sort:
            Item field to sort results on: 'id', 'name', or 'date'.
        :type sort':
            `unicode` or None
        :param direction:
            Sort direction for the items returned.
        :type direction:
            `unicode` or None
        :param fields:
            List of fields to request.
        :type fields:
            `Iterable` of `unicode`
        :returns:
            The collection of items in the folder.
        :rtype:
            `Iterable` of :class:`Item`
        """
        url = self.get_url('items')
        additional_params = {}
        if limit is not None:
            additional_params['limit'] = limit
        if sort:
            additional_params['sort'] = sort
        if direction:
            additional_params['direction'] = direction

        if use_marker:
            additional_params['usemarker'] = True
            return MarkerBasedObjectCollection(
                url=url,
                session=self._session,
                limit=limit,
                marker=marker,
                fields=fields,
                additional_params=additional_params,
                return_full_pages=False,
            )

        return LimitOffsetBasedObjectCollection(
            url=url,
            session=self._session,
            limit=limit,
            offset=offset,
            fields=fields,
            additional_params=additional_params,
            return_full_pages=False,
        )