Skip to content

Commit

Permalink
Implement automatic pagination for layouts and layout assets
Browse files Browse the repository at this point in the history
Currently the maximum number of resources per page is fixed at 250
For sites that have more than 250 resources of one type, the remaining
resources weren't fetched and thus creating/updating them was impossible.

Filemanager#auto_paginate goes through each page and concatenates the responses
together.
  • Loading branch information
Mikk Pristavka committed Apr 21, 2015
1 parent d636d33 commit ff796e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 0 additions & 1 deletion bin/kit
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ pre do |global, command, options, args|
Voog::Dtk.write_config({
host: host,
api_token: api_token,
overwrite: overwrite,
block: @config_block || host,
overwrite: overwrite
})
Expand Down
16 changes: 14 additions & 2 deletions lib/voog/dtk/filemanager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,24 @@ def remove_from_manifest(files = nil)
write_manifest @manifest
end

def auto_paginate(api_method, opt = {})
data = @client.send(api_method, opt)
last_response = @client.last_response

while last_response.rels[:next]
last_response = last_response.rels[:next].get
data.concat(last_response.data) if last_response.data.is_a?(Array)
end

data
end

def get_layouts
@client.layouts(per_page: 10_000)
auto_paginate(:layouts, per_page: 250)
end

def get_layout_assets
@client.layout_assets(per_page: 10_000)
auto_paginate(:layout_assets, per_page: 250)
end

def get_layout(id)
Expand Down
2 changes: 1 addition & 1 deletion lib/voog/dtk/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Voog
module Dtk
VERSION = '0.3.7'
VERSION = '0.3.8'
end
end

0 comments on commit ff796e6

Please sign in to comment.