class Contentful::Sync

Resource class for Sync. @see _ www.contentful.com/developers/docs/references/content-delivery-api/#/reference/synchronization

Attributes

next_sync_url[R]

Public Class Methods

new(client, options_or_url) click to toggle source
# File lib/contentful/sync.rb, line 12
def initialize(client, options_or_url)
  @client = client
  @next_sync_url = nil
  @first_page_options_or_url = options_or_url
end

Public Instance Methods

completed?() click to toggle source

Returns false as long as last sync page has not been reached

@return [Boolean]

# File lib/contentful/sync.rb, line 43
def completed?
  # rubocop:disable Style/DoubleNegation
  !!next_sync_url
  # rubocop:enable Style/DoubleNegation
end
each_item(&block) click to toggle source

Directly iterates over all resources that have changed

@yield [Contentful::Entry, Contentful::Asset]

# File lib/contentful/sync.rb, line 52
def each_item(&block)
  each_page do |page|
    page.each_item(&block)
  end
end
each_page() { |page| ... } click to toggle source

Iterates over all pages of the current sync

@note Please Keep in Mind: Iterating fires a new request for each page

@yield [Contentful::SyncPage]

# File lib/contentful/sync.rb, line 23
def each_page
  page = first_page
  yield page if block_given?

  until completed?
    page = page.next_page
    yield page if block_given?
  end
end
first_page() click to toggle source

Returns the first sync result page

@return [Contentful::SyncPage]

# File lib/contentful/sync.rb, line 36
def first_page
  get(@first_page_options_or_url)
end
get(options_or_url) click to toggle source

@private

# File lib/contentful/sync.rb, line 59
def get(options_or_url)
  page = fetch_page(options_or_url)

  return page if @client.configuration[:raw_mode]

  link_page_to_sync! page
  update_sync_state_from! page

  page
end

Private Instance Methods

fetch_page(options_or_url) click to toggle source
# File lib/contentful/sync.rb, line 72
def fetch_page(options_or_url)
  return Request.new(@client, options_or_url).get if options_or_url.is_a? String
  Request.new(@client, @client.environment_url('/sync'), options_or_url).get
end
update_sync_state_from!(page) click to toggle source
# File lib/contentful/sync.rb, line 81
def update_sync_state_from!(page)
  @next_sync_url = page.next_sync_url
end