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:
commit
23c0b3d842
1 changed files with 24 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
@ -23,6 +23,28 @@ module Fog
|
|||
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?
|
||||
return nil
|
||||
|
|
Loading…
Reference in a new issue