Skip to content

Instantly share code, notes, and snippets.

@kun432
Created July 17, 2014 08:31
Show Gist options
  • Save kun432/494f14cb94c617f9e2e1 to your computer and use it in GitHub Desktop.
Save kun432/494f14cb94c617f9e2e1 to your computer and use it in GitHub Desktop.
for DigitalOcean API V2.0 paging feature
unless method == :delete
begin
body = JSON.parse(result.body)
@logger.info "Response: #{body}"
nextpage = body["links"]["pages"]["next"] rescue nil
+ unless nextpage.nil?
+ uri = URI.parse(nextpage)
+ next_result = self.request("#{path}?#{uri.query}")
+ target = path.split("/")[-1]
+ body["#{target}"].concat(next_result["#{target}"])
+ end
rescue JSON::ParserError => e
raise(Errors::JSONError, {
:message => e.message,
:path => path,
:params => params,
:response => result.body
})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment