Class: TentD::API::Followings::GetActualId

Inherits:
Middleware
  • Object
show all
Defined in:
lib/tentd/api/followings.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



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tentd/api/followings.rb', line 7

def action(env)
  id_mapping = [:following_id, :since_id, :before_id].select { |key| env.params.has_key?(key) }.inject({}) { |memo, key|
    memo[env.params[key]] = key
    env.params[key] = nil
    memo
  }
  followings = Model::Following.all(:public_id => id_mapping.keys, :fields => [:id, :public_id])
  followings.each do |following|
    key = id_mapping[following.public_id]
    env.params[key] = following.id
  end
  env
end