Class: TentD::API::Followers::Discover

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tentd/api/followers.rb', line 49

def action(env)
  return env if env.authorized_scopes.include?(:write_followers)
  return [422, {}, ['Invalid notification path']] unless env.params.data.notification_path.kind_of?(String) &&
                                                        !env.params.data.notification_path.match(%r{\Ahttps?://})
  return [406, {}, ['Can not follow self']] if Model::User.current.profile_entity == env.params.data.entity
  client = ::TentClient.new(nil, :faraday_adapter => TentD.faraday_adapter)
  profile, profile_url = client.discover(env.params[:data]['entity']).get_profile
  return [404, {}, ['Not Found']] unless profile

  profile = CoreProfileData.new(profile)
  return [409, {}, ['Entity Mismatch']] unless profile.entity?(env.params.data.entity)
  env['profile'] = profile
  env
end