mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add initial support for pulling in >100 zones via Zones.each.
Uses the hypermedia links returned by the response body to determine whether or not there are more results available.
This commit is contained in:
parent
148cb14c19
commit
ca7d6f61c8
1 changed files with 22 additions and 0 deletions
|
@ -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 = load(body['domains'])
|
||||
|
||||
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 = load(body['domains'])
|
||||
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…
Add table
Reference in a new issue