# Path: asana/error.py
# class InvalidTokenError(AsanaError):
#     def __init__(self, response=None):
#         super(InvalidTokenError, self).__init__(
#             message='Sync token invalid or too old',
#             status=412,
#             response=response
#         )
#         self.sync = response is not None and response.json()['sync']


from .error import InvalidTokenError
import time
    def items(self):
        """Returns an iterator for each item in each page"""
        for page in self:
            for item in page:
                yield item


class CollectionPageIterator(PageIterator):
    """Iterator that returns one page of a collection at a time"""

    CONTINUATION_KEY = 'next_page'

    def get_initial(self):
        return self.client.get(self.path, self.query, **self.options)

    def get_next(self):
        self.options['offset'] = self.continuation['offset']
        return self.client.get(self.path, self.query, **self.options)


class EventsPageIterator(PageIterator):
    """Iterator that returns the next page of events, polls until a non-empty page is returned"""

    CONTINUATION_KEY = 'sync'

    def get_initial(self):
        # If no sync token was provided, make a request to get one
        if 'sync' not in self.query:
            try:
                self.client.events.get(self.query, **self.options)

# Path: asana/error.py
# class InvalidTokenError(AsanaError):
#     def __init__(self, response=None):
#         super(InvalidTokenError, self).__init__(
#             message='Sync token invalid or too old',
#             status=412,
#             response=response
#         )
#         self.sync = response is not None and response.json()['sync']


# Path: asana/page_iterator.py
from .error import InvalidTokenError
import time

    def items(self):
        """Returns an iterator for each item in each page"""
        for page in self:
            for item in page:
                yield item


class CollectionPageIterator(PageIterator):
    """Iterator that returns one page of a collection at a time"""

    CONTINUATION_KEY = 'next_page'

    def get_initial(self):
        return self.client.get(self.path, self.query, **self.options)

    def get_next(self):
        self.options['offset'] = self.continuation['offset']
        return self.client.get(self.path, self.query, **self.options)


class EventsPageIterator(PageIterator):
    """Iterator that returns the next page of events, polls until a non-empty page is returned"""

    CONTINUATION_KEY = 'sync'

    def get_initial(self):
        # If no sync token was provided, make a request to get one
        if 'sync' not in self.query:
            try:
                self.client.events.get(self.query, **self.options)

            except InvalidTokenError as e: