Sha256: 964b76723150465381c1767ccf7f4d0c5783fd3a7e62bd621ef512040cfd20a5

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

# -*- encoding: utf-8 -*-
require_relative 'resource'
require_relative 'resource/array_like'

module Contentful
  module Management
    # Resource Class for Arrays (e.g. search results)
    # https://www.contentful.com/developers/documentation/content-delivery-api/#arrays
    # It also provides an #each method and includes Ruby's Enumerable module (gives you methods like #min, #first, etc)
    class Array
      DEFAULT_LIMIT = 100

      include Contentful::Management::Resource
      include Contentful::Management::Resource::SystemProperties
      include Contentful::Management::Resource::ArrayLike

      property :total, :integer
      property :limit, :integer
      property :skip, :integer
      property :items

      # Simplifies pagination
      def next_page
        if request
          new_skip = (skip || 0) + (limit || DEFAULT_LIMIT)
          new_request = request.copy
          new_request.query[:skip] = new_skip
          new_request.get
        else
          false
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
contentful-management-0.0.2 lib/contentful/management/array.rb
contentful-management-0.0.1 lib/contentful/management/array.rb
contentful-management-0.0.1.pre lib/contentful/management/array.rb