Class: TentD::API::Posts::GetActualId

Inherits:
Middleware
  • Object
show all
Defined in:
lib/tentd/api/posts.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/posts.rb', line 7

def action(env)
  id_mapping = [:post_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
  }
  posts = Model::Post.all(:public_id => id_mapping.keys, :fields => [:id, :public_id])
  posts.each do |post|
    key = id_mapping[post.public_id]
    env.params[key] = post.id
  end
  env
end