Sha256: 10d80e4a72f0be59365d5a15e5890b16375402566be1123778fa7475ec907a0e

Contents?: true

Size: 1.07 KB

Versions: 12

Compression:

Stored size: 1.07 KB

Contents

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
          response = new_request.get
          result = ResourceBuilder.new(response, {}, {})
          result.run
        else
          false
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
contentful-management-0.8.0 lib/contentful/management/array.rb
contentful-management-0.7.3 lib/contentful/management/array.rb
contentful-management-0.7.2 lib/contentful/management/array.rb
contentful-management-0.7.1 lib/contentful/management/array.rb
contentful-management-0.7.0 lib/contentful/management/array.rb
contentful-management-0.6.1 lib/contentful/management/array.rb
contentful-management-0.6.0 lib/contentful/management/array.rb
contentful-management-0.5.0 lib/contentful/management/array.rb
contentful-management-0.4.1 lib/contentful/management/array.rb
contentful-management-0.4.0 lib/contentful/management/array.rb
contentful-management-0.3.1 lib/contentful/management/array.rb
contentful-management-0.3.0 lib/contentful/management/array.rb