Class: Contentful::SyncPage

Inherits:
BaseResource show all
Includes:
ArrayLike
Defined in:
lib/contentful/sync_page.rb

Overview

Wrapper Class for Sync results

Instance Attribute Summary collapse

Attributes inherited from BaseResource

#_metadata, #default_locale, #raw, #sys

Instance Method Summary collapse

Methods included from ArrayLike

#[], #array?, #each_item, #empty?, #last, #size, #to_ary

Methods inherited from BaseResource

#==, #marshal_dump, #marshal_load, #reload

Constructor Details

#initialize(item, configuration = { default_locale: Contentful::Client::DEFAULT_CONFIGURATION[:default_locale] }) ⇒ SyncPage

Returns a new instance of SyncPage.



11
12
13
14
15
16
17
18
19
20
# File 'lib/contentful/sync_page.rb', line 11

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

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



9
10
11
# File 'lib/contentful/sync_page.rb', line 9

def items
  @items
end

#next_page_urlObject (readonly)

Returns the value of attribute next_page_url.



9
10
11
# File 'lib/contentful/sync_page.rb', line 9

def next_page_url
  @next_page_url
end

#next_sync_urlObject (readonly)

Returns the value of attribute next_sync_url.



9
10
11
# File 'lib/contentful/sync_page.rb', line 9

def next_sync_url
  @next_sync_url
end

#syncObject (readonly)

Returns the value of attribute sync.



9
10
11
# File 'lib/contentful/sync_page.rb', line 9

def sync
  @sync
end

Instance Method Details

#inspectObject



23
24
25
# File 'lib/contentful/sync_page.rb', line 23

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

#last_page?Boolean

Returns wether it is the last sync page

Returns:

  • (Boolean)


46
47
48
# File 'lib/contentful/sync_page.rb', line 46

def last_page?
  !next_page_url
end

#next_pageContentful::SyncPage, void

Requests next sync page from API

Returns:



30
31
32
# File 'lib/contentful/sync_page.rb', line 30

def next_page
  sync.get(next_page_url) if next_page?
end

#next_page?Boolean

Returns wether there is a next sync page

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/contentful/sync_page.rb', line 37

def next_page?
  # rubocop:disable Style/DoubleNegation
  !!next_page_url
  # rubocop:enable Style/DoubleNegation
end