在我的Rails 7应用程序中,我已经与第三方API集成。响应可能包含response['next_page']
,这意味着响应是分页的。我想在响应中存在next_page
键时消耗所有页面。下面我的客户:
module Customers
module Settlements
class Client
def self.with_account(account) = new(account.id)
def initialize(account_id)
@conn = setup_conn(Rails.application.config.settlements_url, account_id)
end
def fetch_report(page:, limit: 500)
handle_response(@conn.get("reports?page=#{page}&limit=#{limit}"))
end
# (...) other private methods
end
end
end
有没有什么常用的方法可以使用所有页面?
1条答案
按热度按时间s1ag04yj1#
您可以
while
有下一页,或loop
和休息,或: