Class: TentD::API::Followings::Destroy

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



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/tentd/api/followings.rb', line 123

def action(env)
  if (following = Model::Following.first(:id => env.params.following_id))
    client = ::TentClient.new(following.core_profile.servers, following.auth_details.merge(:faraday_adapter => TentD.faraday_adapter))
    res = client.follower.delete(following.remote_id)
    following.destroy
    if (200...300).to_a.include?(res.status)
      env.response = ''
      env.notify_action = 'delete'
      env.notify_instance = following
    end
  end
  env
end