lib/yao/resources/restfully_accessible.rb in yao-0.13.1 vs lib/yao/resources/restfully_accessible.rb in yao-0.13.2
- old
+ new
@@ -1,7 +1,7 @@
require "forwardable"
-
+require "deep_merge"
module Yao::Resources
module RestfullyAccessible
def self.extended(base)
base.class_eval do
class << self
@@ -83,15 +83,30 @@
#
create_url('detail')
else
create_url
end
-
- json = GET(url, query).body
+ memo_query = query
+ res = {}
+ loop do
+ r = GET(url, query).body
+ if r.is_a?(Hash)
+ res.deep_merge!(r)
+ links = r.find {|k,_| k =~ /links/ }
+ if links && links.last.is_a?(Array) && next_link = links.last.find{|s| s["rel"] == "next" }
+ uri = URI.parse(next_link["href"])
+ query = Hash[URI::decode_www_form(uri.query)] if uri.query
+ next
+ end
+ else
+ res = r
+ end
+ break
+ end
if return_single_on_querying && !query.empty?
- [resource_from_json(json)]
+ [resource_from_json(res)]
else
- resources_from_json(json)
+ resources_from_json(res)
end
end
# @note .list is defined to keep backward compatibility and will be deprecated
alias :list_detail :list