Sha256: 1238da85923dd2487bda3c92c0311c222bca38bf71d27e50a0d86bebcaab2dea

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require_dependency "landable/api_controller"

module Landable
  module Api
    class AccessTokensController < ApiController
      skip_before_filter :require_author!, only: [:create]

      def show
        respond_with find_own_access_token
      end

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

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

      def update
        token = find_own_access_token
        token.refresh!

        respond_with token
      end

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


      private

      def find_own_access_token(id = params[:id])
        current_author.access_tokens.fresh.find(id)
      end

      def asset_token_params
        params.require(:access_token).permit(:username, :password)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
landable-1.9.0.rc1 app/controllers/landable/api/access_tokens_controller.rb
landable-1.8.0 app/controllers/landable/api/access_tokens_controller.rb
landable-1.7.1.rc1 app/controllers/landable/api/access_tokens_controller.rb
landable-1.7.0 app/controllers/landable/api/access_tokens_controller.rb