Class: KlaviyoAPI::List
- Defined in:
- lib/klaviyo_api/resources/list.rb
Class Method Summary collapse
-
.find_single(scope, options) ⇒ Object
Override this from ActiveResource#base in order to inject the id into the response because its not returned.
Instance Method Summary collapse
-
#members(options = {}) ⇒ Object
Gets all Members of this List.
Methods inherited from Base
activate_session, element_path, headers, reset_session, #to_h
Class Method Details
.find_single(scope, options) ⇒ Object
Override this from ActiveResource#base in order to inject the id into the response because its not returned
11 12 13 |
# File 'lib/klaviyo_api/resources/list.rb', line 11 def find_single(scope, ) super.tap { |record| record.id = scope } end |
Instance Method Details
#members(options = {}) ⇒ Object
Gets all Members of this List. Uses the Groups endpoint. Returns an enumerator that knows how to transparently deal with Klaviyo’s marker for pagination. Pages seem to be 1000 items.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/klaviyo_api/resources/list.rb', line 22 def members( = {}) CachingEnumerator.new do |yielder| marker = nil loop do path = "#{self.class.prefix}group/#{id}/members/all" path += "?marker=#{marker}" if marker response = JSON.parse(connection.get(path, self.class.headers).body) marker = response['marker'] list_members = response['records'] list_members.each do |list_member| yielder.yield KlaviyoAPI::ListMember.new list_member end break if marker.nil? end end end |