Limit option not working properly for list_account_invoices
Describe the bug
Hello, I noticed when I set the limit option to 5 or any number for the list_account_invoices method, it gets ignored and returns all account invoices every time. Our Recurly sandbox account has around 40 invoices and all of them get returned each time. I'm not sure if I'm using the correct setup for params or not.
To Reproduce I used the example code found here and pass the limit option to params: Method: Recurly::Client#list_account_invoices
test_params = { limit: 5 }
invoices = @client.list_account_invoices( account_id: account_id, params: test_params )
invoices.each do |invoice| puts "Invoice: #{invoice.number}" end
Expected behavior
I expected at least 5 account invoices to be returned if the limit is set to 5.
Your Environment
- Which version of this library are you using? version 4.42.0
- Which version of ruby are you using? version 3.0.1
I've been caught off guard by this too, but it's by design. On all paginated APIs, the Ruby client will automatically iterate through all pages. The limit is only telling it how many records to fetch per page.
To get around this you could do something like:
invoices.each.each_with_index do |invoice, index|
puts "Invoice: #{invoice.number}"
break if index >= 4
end
or
invoices.each.first(5).each { |invoice| puts "Invoice: #{invoice.number}" }