'Fetch pages.
:param item_type: Type of single item. ResultList of such items will be returned.
:param items_key: Path to the items in JSON returned from server.
Set it to None, if response is an array, and not a JSON object.
:param request_path: path in request URL
:param startAt: index of the first record to be fetched
:param maxResults: Maximum number of items to return.
If maxResults evaluates as False, it will try to get all items in batches.
:param params: Params to be used in all requests. Should not contain startAt and maxResults,
as they will be added for each request created from this function.
:param base: base URL
:return: ResultList'

def _fetch_pages(self, item_type, items_key, request_path, startAt=0, maxResults=50, params=None, base=JIRA_BASE_URL):

    page_params = (params.copy() if params else {})
    if startAt:
        page_params[u'startAt'] = startAt
    if maxResults:
        page_params[u'maxResults'] = maxResults
    try:
        resource = self._get_json(request_path, params=page_params, base=base)
        next_items_page = [item_type(self._options, self._session, raw_issue_json) for raw_issue_json in (resource[items_key] if items_key else resource)]
    except KeyError as e:
        raise KeyError(((str(e) + u'    :    ') + json.dumps(resource)))
    items = next_items_page
    if True:
        if isinstance(resource, dict):
            total = resource.get(u'total')
            is_last = resource.get(u'isLast', True)
            start_at_from_response = resource.get(u'startAt', 0)
            max_results_from_response = resource.get(u'maxResults', 1)
        else:
            total = 1
            is_last = True
            start_at_from_response = 0
            max_results_from_response = 1
        if (not maxResults):
            page_size = (max_results_from_response or len(items))
            page_start = ((startAt or start_at_from_response or 0) + page_size)
            while ((not is_last) and ((total is None) or (page_start < total)) and (len(next_items_page) == page_size)):
                page_params[u'startAt'] = page_start
                page_params[u'maxResults'] = page_size
                resource = self._get_json(request_path, params=page_params, base=base)
                if resource:
                    try:
                        next_items_page = [item_type(self._options, self._session, raw_issue_json) for raw_issue_json in (resource[items_key] if items_key else resource)]
                    except KeyError as e:
                        raise KeyError(((str(e) + u'    :    ') + json.dumps(resource)))
                    items.extend(next_items_page)
                    page_start += page_size
                else:
                    break
        return ResultList(items, start_at_from_response, max_results_from_response, total, is_last)
    else:
        return ResultList([item_type(self._options, self._session, resource)], 0, 1, 1, True)
