Sha256: 1b65d959d7177641a51ec4cfdec86a35d78615b7e3b8e1faed38f8d469f52ef4

Contents?: true

Size: 899 Bytes

Versions: 6

Compression:

Stored size: 899 Bytes

Contents

require_relative 'resource'
require_relative 'resource/array_like'

module Contentful
  # 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::Resource
    include Contentful::Resource::SystemProperties
    include Contentful::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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
contentful-0.8.0 lib/contentful/array.rb
contentful-0.7.0 lib/contentful/array.rb
contentful-0.6.0 lib/contentful/array.rb
contentful-0.5.0 lib/contentful/array.rb
contentful-0.4.0 lib/contentful/array.rb
contentful-0.3.5 lib/contentful/array.rb