Wrapper to assist with paginated responses from Digicert's REST API.

def _paginate(url, topkey, *args, **kwargs):
    '''
    Wrapper to assist with paginated responses from Digicert's REST API.
    '''

    ret = salt.utils.http.query(url, **kwargs)
    if 'errors' in ret['dict']:
        return ret['dict']

    lim = int(ret['dict']['page']['limit'])
    total = int(ret['dict']['page']['total'])

    if total == 0:
        return {}

    numpages = (total / lim) + 1

    # If the count returned is less than the page size, just return the dict
    if numpages == 1:
        return ret['dict'][topkey]

    aggregate_ret = ret['dict'][topkey]
    url = args[0]
    for p in range(2, numpages):
        param_url = url + '?offset={0}'.format(lim * (p - 1))
        next_ret = salt.utils.http.query(param_url, kwargs)
        aggregate_ret[topkey].extend(next_ret['dict'][topkey])

    return aggregate_ret