1

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?

Centimane
  • 280
  • 5
  • 17

1 Answers1

4

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.

Dabrorius
  • 1,039
  • 1
  • 8
  • 17
  • 1
    That's a step in the right direction, but it seems to cap out at 100, limit: 0 => size 25 and limit: 2000 => size 100. I'm hoping to score much more than 100 at a time. – Centimane Feb 27 '15 at 17:46
  • 1
    I update my answer recently with a link to redmine api documentation. You will notice that 100 is defined as a maximum allowed value. You will have to combine limit and offset params and do multiple requests in order to gather all issues. I'll update my answer with an example. – Dabrorius Feb 27 '15 at 17:49
  • 2
    I'll have to look if I can modify that limit, I'd rather not have hundreds of queries if I can avoid it, but that's how it is for now. – Centimane Feb 27 '15 at 17:51
  • 1
    The limit enforced by Redmine can be easily removed in it's code, located in the file: `./htdocs/app/controllers/application_controller.rb` there is a line: `elsif limit > 100 \ limit = 100` which can be commented out to remove the 100 max limit. Enforcing a max limit of 100 doesn't seem helpful considering that multiple queries can be used to get any number of items, and that extra queries would be more taxing to the server. – Centimane Dec 09 '15 at 12:38