Get individual item count
Use a do-while loop, so the loop body gets always executed at least once:

final_count = 0
page = 1
begin
  individual_count = get_item_count(config, page)
  final_count += individual_count
  page += 1
end while individual_count &gt; 20