1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #1535 from minter/paginated_domains_via_each

Add support for pulling in >100 zones via Zones.each.
This commit is contained in:
Brian Hartsock 2013-01-31 15:00:35 -08:00
commit 23c0b3d842

View file

@ -8,9 +8,9 @@ module Fog
model Fog::DNS::Rackspace::Zone
def all
def all(options={})
clear
data = service.list_domains.body['domains']
data = service.list_domains(options).body['domains']
load(data)
end
@ -22,6 +22,28 @@ module Fog
data = service.list_domains(:name => substring).body['domains']
load(data)
end
alias :each_zone_this_page :each
def each
if !block_given?
self
else
body = service.list_domains.body
subset = dup.all
subset.each_zone_this_page {|f| yield f}
while !body['links'].select{|l| l['rel'] == 'next'}.empty?
url = body['links'].select{|l| l['rel'] == 'next'}.first['href']
query = url.match(/\?(.+)/)
parsed = CGI.parse($1)
body = service.list_domains(:offset => parsed['offset'], :limit => parsed['limit']).body
subset = dup.all(:offset => parsed['offset'], :limit => parsed['limit'])
subset.each_zone_this_page {|f| yield f}
end
self
end
end
def get(zone_id)
if zone_id.nil? or zone_id.to_s.empty?