Class: KlaviyoAPI::Collections::MarkerCollection

Inherits:
ActiveResource::Collection
  • Object
show all
Defined in:
lib/klaviyo_api/collections/marker_collection.rb

Overview

This collection is used for item types that rely on markers to provide pagination.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = {}) ⇒ MarkerCollection

Returns a new instance of MarkerCollection.



9
10
11
12
13
14
15
16
17
# File 'lib/klaviyo_api/collections/marker_collection.rb', line 9

def initialize(response = {})
  # May not exist
  @count = response.delete 'count'

  @next = response['next'] || response['marker']
  @marker = @next

  @elements = response['data'] || response['records'] || []
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



7
8
9
# File 'lib/klaviyo_api/collections/marker_collection.rb', line 7

def count
  @count
end

#markerObject

Returns the value of attribute marker.



7
8
9
# File 'lib/klaviyo_api/collections/marker_collection.rb', line 7

def marker
  @marker
end

#nextObject

Returns the value of attribute next.



7
8
9
# File 'lib/klaviyo_api/collections/marker_collection.rb', line 7

def next
  @next
end

Instance Method Details

#more_pages?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/klaviyo_api/collections/marker_collection.rb', line 23

def more_pages?
  !@next.nil?
end

#next_pageObject



27
28
29
30
31
32
# File 'lib/klaviyo_api/collections/marker_collection.rb', line 27

def next_page
  # Return empty collection if no other pages
  return self.class.new unless more_pages?

  first.class.all params: { **first.prefix_options, **original_params, "#{next_page_marker_name}": marker }
end

#next_page_marker_nameObject



19
20
21
# File 'lib/klaviyo_api/collections/marker_collection.rb', line 19

def next_page_marker_name
  'marker'
end