Search code examples
ruby-on-railsrubyactiveresourceredmine-api

How do I query ActiveResource without a limit?


I am attempting to collect all entries of an object from an instance of Redmine using its ruby REST API. The code I'm trying:

require 'rubygems'
require 'active_resource'

class Issue < ActiveResource::Base
    self.site = '<site url>'
    self.user = '<username>'
    self.password = '<password>'
    self.format = :xml
end

test = Issue.all
puts test.size

test = Issue.all(:limit => 0)
puts test.size

The resulting output is:

25
25

There are thousands of entries in the database, so for the size to be 25 is clearly off. I also tried ":limit => 10" and got a size == 25, so it seems as though the ':limit' argument is being completely ignored.

I also tried Issue.find(:all, :limit => 0) and :limit => 10, both of which returned size == 25. What would be the correct method for querying active_resource without a limit?


Solution

  • It seems that "limit" option is not supported by ActiveResource. If you check out the documentation you will see that available options are 'from', and 'params'.

    My guess is that number of resources returned is decided by the service server. Did you try something like this?

    Issue.all(params: { limit: 25})
    

    This should work if I read the redmine api documentation correctly.

    Unfortunately, as stated in documentation, 100 is maximum allowed value for limit param.

    limit: the number of items to be present in the response (default is 25, maximum is 100)

    You will have to make multiple requests and use offset and limit params to get all records.