Class: TentD::API::Groups::GetAll

Inherits:
Middleware show all
Defined in:
lib/tentd/api/groups.rb

Instance Method Summary collapse

Methods inherited from Middleware

#call, #initialize

Methods included from Authorizable

#authorize_env!, #authorize_env?

Constructor Details

This class inherits a constructor from TentD::API::Middleware

Instance Method Details

#action(env) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/tentd/api/groups.rb', line 43

def action(env)
  conditions = {}
  conditions[:id.lt] = env.params.before_id if env.params.before_id
  conditions[:id.gt] = env.params.since_id if env.params.since_id
  conditions[:limit] = [env.params.limit.to_i, MAX_PER_PAGE].min if env.params.limit
  conditions[:limit] ||= PER_PAGE
  if env.params.return_count
    env.response = Model::Group.count(conditions)
  else
    conditions[:order] = :id.desc
    if conditions[:limit] == 0
      env.response = []
    else
      env.response = Model::Group.all(conditions)
    end
  end
  env
end