class WCC::Contentful::SimpleClient::SyncResponse

Public Class Methods

new(response) click to toggle source
# File lib/wcc/contentful/simple_client/response.rb, line 130
def initialize(response)
  super(response.client, response.request, response.raw_response)
end
parse_sync_token(url) click to toggle source
# File lib/wcc/contentful/simple_client/response.rb, line 186
def self.parse_sync_token(url)
  url = URI.parse(url)
  q = CGI.parse(url.query)
  q['sync_token']&.first
end

Public Instance Methods

count() click to toggle source
# File lib/wcc/contentful/simple_client/response.rb, line 181
def count
  raise NotImplementedError,
    'Sync does not return an accurate total.  Use #items.count instead.'
end
each_page() click to toggle source
# File lib/wcc/contentful/simple_client/response.rb, line 160
def each_page
  raise ArgumentError, 'Not a collection response' unless page_items

  ret =
    Enumerator.new do |y|
      y << self

      if next_page?
        next_page.each_page.each do |page|
          y << page
        end
      end
    end

  if block_given?
    ret.map(&block)
  else
    ret.lazy
  end
end
next_page() click to toggle source
# File lib/wcc/contentful/simple_client/response.rb, line 138
def next_page
  return unless next_page?

  url = raw['nextPageUrl']
  next_page =
    _instrument 'page', url: url do
      @client.get(url)
    end

  @next_page ||= SyncResponse.new(next_page)
  @next_page.assert_ok!
end
next_page?() click to toggle source
# File lib/wcc/contentful/simple_client/response.rb, line 134
def next_page?
  raw['nextPageUrl'].present?
end
next_sync_token() click to toggle source
# File lib/wcc/contentful/simple_client/response.rb, line 151
def next_sync_token
  # If we haven't grabbed the next page yet, then our next "sync" will be getting
  # the next page.  We could just as easily call sync again with that token.
  @next_page&.next_sync_token ||
    @next_sync_token ||= SyncResponse.parse_sync_token(
      raw['nextPageUrl'] || raw['nextSyncUrl']
    )
end