Closed mattes closed 10 years ago
where else? @fjenett
In the future i think we should add it here:
GET /api/v1/users.json
GET /api/v1/group/{id}/users.json
GET /api/v1/user/{id}/groups.json
GET /api/v1/groups.json
GET /api/v1/group/{id}/events.json
But for now it is most needed with the GET /api/v1/group/{id}/events.json
call ...
Please read: https://dev.twitter.com/docs/working-with-timelines
So we could implement params like these:
params do
optional :count, type: Integer, desc: "Number of results to return"
optional :since_id, type: Integer, desc: "Retrieve records after since_id"
end
Requests would look like:
# first request
GET /api/v1/users.json?count=2
returns {result: [{id: 1, name: "peter"}, {id: 4, name: "pan"} ], more: true}
# more == true, so
# second request
GET /api/v1/users.json?count=2&since_id=4
returns {result: [{id: 5, name: "klaus"}, {id: 6, name: "hans"} ], more: false}
not sure, if we need the max_id
param.
This works for numeric IDs only. So it won't work for user_roles
or role_permission
. But I guess we won't need paging here.
what do you think, @fjenett ?
Sounds good to me!
ASC
1
2
3
4
5
since_id: 2 => 3,4,5
max_id: 4 => 1,2,3
since_id: 2 && max_id: 4 => 3
DESC
5
4
3
2
1
since_id: 2 => 2
max_id: 4 => 5
since_id: 2 && max_id: 4 => nil
since_id: 4 => 3,2,1
max_id: 2 => 5,4,3
since_id: 4 && max_id: 2 => 3
Conclusion: Order by ID DESC will lead into issues!!!
Everything else works fine! ORDER BY user.name ASC or ORDER BY user.name DESC works i.e. as long as the ID is ordered by ASC.
Unlike max_id the since_id parameter is not inclusive
Add params
params do
optional :count, type: Integer, default: 100, desc: "number of results"
optional :max_id, type: Integer, desc: "return results to id"
optional :since_id, type: Integer, desc: "return results from id"
end
then in the logic:
User.page(params).all
https://github.com/motionbank/piecemaker2-api/blob/master/api/event_groups.rb#L197