=== Params

 * limit_page - Integer
 * request_num - Integer
 * options - Hash

 === Options

 * from - Time or String
 * to - Time or String

 fetch reports `:from` newer `:to` older
10211
def fetch(filter_type, request_num, options = {})
      limit_page = options[:limit_page] || MAX_PAGES_DEFAULT
      filter = Filter.new(filter_type, min_time: options[:to])
      page = Page.new(session, filter, options[:from], options[:to])

      # NOTE: filter は report に渡したほうがシンプルじゃない？
      limit_page.times.each_with_object(Report.new(request_num)) do |_, report|
        report.push(page)
        break report if page.last_page? || report.reach_request_num?

        page = page.next
      end
    end
788648
def get(object, options = {})
      if options[:all_pages]
        options.delete(:all_pages)
        options[:page] = 1
        out = []
        begin
          data = get(object, options)
          out = out | data
          options[:page] += 1
        end while data.count >= 100
        return out
      else
        if options[:id]
          resp = @connection.get "#{object}/#{options[:id]}"
        elsif options.size > 0
          resp = @connection.get "#{object}#{Client.parse_options(options)}"
        else
          resp = @connection.get object
        end
        raise "Bad response: #{resp.status}" unless resp.status == 200
        Client.mash(JSON.parse(resp.body))
      end
    end
1121214
def find_page(options = {})
      options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination, :select
      options[:per_page] ||= 999_999_999
      options[:page] ||= 1

      find_options = finder_options(options)
      query = beginning_of_chain.where(nil) # where(nil) is needed because we need a relation

      # NOTE: we must use :include in the count query, because some conditions may reference other tables
      if options[:pagination] && options[:pagination] != :infinite
        count = count_items(query, find_options, options[:count_includes])
      end

      query = append_to_query(query, find_options)
      # we build the paginator differently for method- and sql-based sorting
      pager = if options[:sorting]&.sorts_by_method?
                ::Paginator.new(count, options[:per_page]) do |offset, per_page|
                  calculate_last_modified(query)
                  sorted_collection = sort_collection_by_column(query.to_a, *options[:sorting].first)
                  sorted_collection = sorted_collection.slice(offset, per_page) if options[:pagination]
                  sorted_collection
                end
              else
                ::Paginator.new(count, options[:per_page]) do |offset, per_page|
                  query = append_to_query(query, :offset => offset, :limit => per_page) if options[:pagination]
                  calculate_last_modified(query)
                  query
                end
              end
      pager.page(options[:page])
    end
719788
def extract_paging(response)
      paging            = response.to_h['paging']
      next_page_url     = paging && paging['next']      # gives nil when any one of the keys doens't exist
      previous_page_url = paging && paging['previous']  # can be replaced with Hash#dig for ruby >= 2.3.0
      @paging_next      = extract_endpoint_from(next_page_url)
      @paging_previous  = extract_endpoint_from(previous_page_url)
    end
192115
def limit(value = nil, &block)
      chain { criteria.update_request_options size: block || Integer(value) }
    end
760088
def _paginate(url, topkey, *args, **kwargs):
    '''
    
    '''

    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
1055490
def fetch
      puts "fetching #{@uri.to_s}".green.on_black
      start_time = Time.now
      begin
        request = Net::HTTP::Get.new(@uri.request_uri)
        request["User-Agent"] = UserAgents.random
        response = @http.request(request) 
        end_time = Time.now
        case response
        when Net::HTTPSuccess then
          page = Page.new(@uri, response_code: response.code.to_i,
                                response_head: response.instance_variable_get("@header"),
                                response_body: response.body,
                                response_time: (end_time-start_time).to_f,
                                crawled_time: (Time.now.to_f*1000).to_i)
        when Net::HTTPRedirection then
          page = Page.new(@uri, response_code: response.code.to_i,
                                response_head: response.instance_variable_get("@header"),
                                response_body: response.body,
                                response_time: (end_time-start_time).to_f,
                                redirect_url:  response['location'])
        when Net::HTTPNotFound then
          page = Page.new(@uri, response_code: response.code.to_i,
                                response_time: (end_time-start_time).to_f)
        end
      rescue Exception => e
        puts e.inspect
        puts e.backtrace
      end
    end
249406
def params
      {}.tap do |param|
        param[:status] = SubscriptionPaymentOrder::STATUSES[status.to_sym]
        param[:page] = page
        param[:maxPageResults] = options[:per_page]
        param[:credentials] = options[:credentials]
      end
    end
1147230
def _limit_is_valid_or_none(self, params):
        
        if not "limit" in params or not params["limit"]:
            return True
        if not isinstance(params["limit"], int) or params["limit"] < 1:
            return False
        if not "order_by" in params:
            return False
        return True
412575
def write_pagination_headers(data, offset, limit, response, uripath,
                             resource_name):
    
    items = data.get('results') or data.get('data') or {}
    count = len(items)
    try:
        total = int(data['collection-count'])
    except (ValueError, TypeError, KeyError):
        total = None
    if total is None and offset == 0 and (limit is None or limit > len(items)):
        total = count

    # Set 'content-range' header
    response.set_header(
        'Content-Range',
        "%s %d-%d/%s" % (resource_name, offset, offset + max(count - 1, 0),
                         total if total is not None else '*')
    )

    partial = False
    if offset:
        partial = True  # Any offset automatically means we've skipped data
    elif total is None and count == limit:
        # Unknown total, but first page is full (so there may be more)
        partial = True  # maybe more records in next page
    elif total > count:
        # Known total and not all records returned
        partial = True

    if partial:
        uripath = uripath.strip('/')
        response.status = 206  # Partial

        # Add Next page link to http header
        if total is None or (offset + limit) < total - 1:
            nextfmt = (
                '</%s?limit=%d&offset=%d>; rel="next"; title="Next page"')
            response.add_header(
                "Link", nextfmt % (uripath, limit, offset + limit)
            )

        # Add Previous page link to http header
        if offset > 0 and (offset - limit) >= 0:
            prevfmt = ('</%s?limit=%d&offset=%d>; rel="previous"; '
                       'title="Previous page"')
            response.add_header(
                "Link", prevfmt % (uripath, limit, offset - limit)
            )

        # Add first page link to http header
        if offset > 0:
            firstfmt = '</%s?limit=%d>; rel="first"; title="First page"'
            response.add_header(
                "Link", firstfmt % (uripath, limit))

        # Add last page link to http header
        if (total is not None and  # can't calculate last page if unknown total
                limit and  # if no limit, then any page is the last page!
                limit < total):
            lastfmt = '</%s?offset=%d>; rel="last"; title="Last page"'
            if limit and total % limit:
                last_offset = total - (total % limit)
            else:
                last_offset = total - limit
            response.add_header(
                "Link", lastfmt % (uripath, last_offset))
505878
def request
      @last_response = nil
      old_stripe_client = Thread.current[:stripe_client]
      Thread.current[:stripe_client] = self

      begin
        res = yield
        [res, @last_response]
      ensure
        Thread.current[:stripe_client] = old_stripe_client
      end
    end
805244
function queryOptionsToMongo(query, options) {
    var hash = {},
        fields = fieldsToMongo(query[options.keywords.fields]),
        omitFields = omitFieldsToMongo(query[options.keywords.omit]),
        sort = sortToMongo(query[options.keywords.sort]),
        maxLimit = options.maxLimit || 9007199254740992,
        limit = options.maxLimit || 0

    if (fields) hash.fields = fields
    // omit intentionally overwrites fields if both have been specified in the query
    // mongo does not accept mixed true/fals field specifiers for projections
    if (omitFields) hash.fields = omitFields
    if (sort) hash.sort = sort

    if (query[options.keywords.offset]) hash.skip = Number(query[options.keywords.offset])
    if (query[options.keywords.limit]) limit = Math.min(Number(query[options.keywords.limit]), maxLimit)
    if (limit) {
        hash.limit = limit
    } else if (options.maxLimit) {
        hash.limit = maxLimit
    }

    return hash
}
714551
def search_rules(query, params = {}, request_options = {})
      anchoring = params[:anchoring]
      context = params[:context]
      page = params[:page] || params['page'] || 0
      hits_per_page = params[:hitsPerPage] || params['hitsPerPage'] || 20
      params = {
        :query => query,
        :page => page,
        :hitsPerPage => hits_per_page
      }
      params[:anchoring] = anchoring unless anchoring.nil?
      params[:context] = context unless context.nil?
      client.post(Protocol.search_rules_uri(name), params.to_json, :read, request_options)
    end
643756
def p_recent(self, kind, cur_p='', with_catalog=True, with_date=True):
        '''
        
        '''
        if cur_p == '':
            current_page_number = 1
        else:
            current_page_number = int(cur_p)

        current_page_number = 1 if current_page_number < 1 else current_page_number

        pager_num = int(MPost.total_number(kind) / CMS_CFG['list_num'])
        kwd = {
            'pager': '',
            'title': 'Recent posts.',
            'with_catalog': with_catalog,
            'with_date': with_date,
            'kind': kind,
            'current_page': current_page_number,
            'post_count': MPost.get_counts(),
            'router': config.router_post[kind],
        }
        self.render('admin/post_ajax/post_list.html',
                    kwd=kwd,
                    view=MPost.query_recent(num=20, kind=kind),
                    infos=MPost.query_pager_by_slug(
                        kind=kind,
                        current_page_num=current_page_number
                    ),
                    format_date=tools.format_date,
                    userinfo=self.userinfo,
                    cfg=CMS_CFG, )
703873
def __continued_query(self, query_params):
    '''
    
    '''
    query_params.update(self.__title_query_param)

    last_continue = {}
    prop = query_params.get('prop', None)

    while True:
      params = query_params.copy()
      params.update(last_continue)

      request = _wiki_request(params)

      if 'query' not in request:
        break

      pages = request['query']['pages']
      if 'generator' in query_params:
        for datum in pages.values():  # in python 3.3+: "yield from pages.values()"
          yield datum
      else:
        for datum in pages[self.pageid][prop]:
          yield datum

      if 'continue' not in request:
        break

      last_continue = request['continue']
394735
def get(self, limit=None, page=None):
        
        has_more = False
        self.bounds.paginate = True
        limit_paginate, offset = self.bounds.get(limit, page)
        self.default_val = []
        results = self._query('get')

        if limit_paginate:
            self.bounds.paginate = False
            if len(results) == limit_paginate:
                has_more = True
                results.pop(-1)

        it = ResultsIterator(results, orm_class=self.orm_class, has_more=has_more, query=self)
        return self.iterator_class(it)
1043782
def get_all_file_report_pages(self, query):
        
        responses = []
        next_page, response = self.get_hashes_from_search(self, query)
        responses.append(_return_response_and_status_code(response))
        while next_page:
            next_page, response = self.get_hashes_from_search(query, next_page)
            responses.append(_return_response_and_status_code(response))
        return dict(results=responses)