Sha256: b445e0de6b8031f448df8b76fcf2084f8e2ee1c26ae915f7ef78b154544bbf82

Contents?: true

Size: 1.23 KB

Versions: 36

Compression:

Stored size: 1.23 KB

Contents

require_relative 'base_resource'
require_relative 'array_like'

module Contentful
  # Wrapper Class for Sync results
  class SyncPage < BaseResource
    include Contentful::ArrayLike

    attr_reader :sync, :items, :next_sync_url, :next_page_url

    def initialize(item,
                   configuration = {
                     default_locale: Contentful::Client::DEFAULT_CONFIGURATION[:default_locale]
                   }, *)
      super(item, configuration, true)

      @items = item.fetch('items', [])
      @next_sync_url = item.fetch('nextSyncUrl', nil)
      @next_page_url = item.fetch('nextPageUrl', nil)
    end

    # @private
    def inspect
      "<#{repr_name} next_sync_url='#{next_sync_url}' last_page=#{last_page?}>"
    end

    # Requests next sync page from API
    #
    # @return [Contentful::SyncPage, void]
    def next_page
      sync.get(next_page_url) if next_page?
    end

    # Returns wether there is a next sync page
    #
    # @return [Boolean]
    def next_page?
      # rubocop:disable Style/DoubleNegation
      !!next_page_url
      # rubocop:enable Style/DoubleNegation
    end

    # Returns wether it is the last sync page
    #
    # @return [Boolean]
    def last_page?
      !next_page_url
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
contentful-2.17.1 lib/contentful/sync_page.rb
contentful-2.17.0 lib/contentful/sync_page.rb
contentful-2.16.3 lib/contentful/sync_page.rb
contentful-2.16.2 lib/contentful/sync_page.rb
contentful-2.16.1 lib/contentful/sync_page.rb
contentful-2.16.0 lib/contentful/sync_page.rb
contentful-2.15.4 lib/contentful/sync_page.rb
contentful-2.15.3 lib/contentful/sync_page.rb
contentful-2.15.2 lib/contentful/sync_page.rb
contentful-2.15.1 lib/contentful/sync_page.rb
contentful-2.15.0 lib/contentful/sync_page.rb
contentful-2.14.0 lib/contentful/sync_page.rb
contentful-2.13.3 lib/contentful/sync_page.rb
contentful-2.13.2 lib/contentful/sync_page.rb
contentful-2.13.1 lib/contentful/sync_page.rb
contentful-2.13.0 lib/contentful/sync_page.rb
contentful-2.12.0 lib/contentful/sync_page.rb
contentful-2.11.1 lib/contentful/sync_page.rb
contentful-2.11.0 lib/contentful/sync_page.rb
contentful-2.10.1 lib/contentful/sync_page.rb