Class: Contentful::Sync

Inherits:
Object
  • Object
show all
Defined in:
lib/contentful/sync.rb

Overview

Resource class for Sync.

See Also:

  • https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/synchronization

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, options_or_url) ⇒ Sync

Returns a new instance of Sync.



12
13
14
15
16
# 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

Instance Attribute Details

#next_sync_urlObject (readonly)

Returns the value of attribute next_sync_url.



10
11
12
# File 'lib/contentful/sync.rb', line 10

def next_sync_url
  @next_sync_url
end

Instance Method Details

#completed?Boolean

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

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/contentful/sync.rb', line 43

def completed?
  # rubocop:disable Style/DoubleNegation
  !!next_sync_url
  # rubocop:enable Style/DoubleNegation
end

#each_item {|Contentful::Entry, Contentful::Asset| ... } ⇒ Object

Directly iterates over all resources that have changed



52
53
54
55
56
# File 'lib/contentful/sync.rb', line 52

def each_item(&block)
  each_page do |page|
    page.each_item(&block)
  end
end

#each_page {|Contentful::SyncPage| ... } ⇒ Object

Note:

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

Iterates over all pages of the current sync



23
24
25
26
27
28
29
30
31
# 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_pageContentful::SyncPage

Returns the first sync result page



36
37
38
# File 'lib/contentful/sync.rb', line 36

def first_page
  get(@first_page_options_or_url)
end