Sha256: f8e8e8e5a9c1c65f720dced89ddf8f042fb1cfced8e1c744772de5a601bf976b

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contentful-management-0.2.1 lib/contentful/management/array.rb
contentful-management-0.2.0 lib/contentful/management/array.rb
contentful-management-0.1.0 lib/contentful/management/array.rb
contentful-management-0.0.3 lib/contentful/management/array.rb