Module: Cloudflare::Paginate

Includes:
Enumerable
Included in:
Accounts, CustomHostnames, DNS::Records, Firewall::Rules, KV::Keys, KV::Namespaces, Logs::Received, Zones
Defined in:
lib/cloudflare/paginate.rb

Instance Method Summary collapse

Instance Method Details

#each(page: 1, per_page: 50, **parameters) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cloudflare/paginate.rb', line 11

def each(page: 1, per_page: 50, **parameters)
	return to_enum(:each, page: page, per_page: per_page, **parameters) unless block_given?
	
	while true
		resource = @resource.with(parameters: {page: page, per_page: per_page, **parameters})
		
		response = self.class.get(resource)
		
		break if response.empty?
		
		response.results.each do |attributes|
			yield represent(response., attributes)
		end
		
		page += 1
		
		# Was this the last page?
		break if response.results.size < per_page
	end
end

#empty?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cloudflare/paginate.rb', line 32

def empty?
	self.value.empty?
end

#find_by_id(id) ⇒ Object



36
37
38
# File 'lib/cloudflare/paginate.rb', line 36

def find_by_id(id)
	representation.new(@resource.with(path: "#{id}/"))
end