Class: Landable::Api::AccessTokensController

Inherits:
Landable::ApiController show all
Defined in:
app/controllers/landable/api/access_tokens_controller.rb

Constant Summary

Constants inherited from Landable::ApiController

Landable::ApiController::API_MEDIA_REGEX

Instance Method Summary collapse

Methods inherited from Landable::ApiController

#api_media

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/landable/api/access_tokens_controller.rb', line 12

def create
  ident  = AuthenticationService.call(asset_token_params[:username], asset_token_params[:password])

  author = RegistrationService.call(ident)

  permissions = determine_permissions(ident[:groups])

  respond_with AccessToken.create!(author: author, permissions: permissions), status: :created
rescue Landable::AuthenticationFailedError
  head :unauthorized
end

#destroyObject



31
32
33
34
35
36
37
# File 'app/controllers/landable/api/access_tokens_controller.rb', line 31

def destroy
  token = find_own_access_token
  token.destroy!
  head :no_content
rescue ActiveRecord::RecordNotFound
  head :unauthorized
end

#showObject



8
9
10
# File 'app/controllers/landable/api/access_tokens_controller.rb', line 8

def show
  respond_with find_own_access_token
end

#updateObject



24
25
26
27
28
29
# File 'app/controllers/landable/api/access_tokens_controller.rb', line 24

def update
  token = find_own_access_token
  token.refresh!

  respond_with token
end