Class: TentD::API::Posts::GetAttachment

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



280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/tentd/api/posts.rb', line 280

def action(env)
  return env unless env.response
  type = env['HTTP_ACCEPT'].split(/;|,/).first if env['HTTP_ACCEPT']
  attachment = env.response.attachments.first(:type => type, :name => env.params.attachment_name, :fields => [:data])
  if attachment
    env.response = Base64.decode64(attachment.data)
    env['response.type'] = type
  else
    env.response = nil
  end
  env
end