Sha256: 426b954c8beb4f7e23487de03c785978d59edc59bb14cd4a3d36fd4971f5252e

Contents?: true

Size: 1.13 KB

Versions: 12

Compression:

Stored size: 1.13 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

12 entries across 12 versions & 1 rubygems

Version Path
landable-1.13.1 app/controllers/landable/api/access_tokens_controller.rb
landable-1.12.3 app/controllers/landable/api/access_tokens_controller.rb
landable-1.12.2 app/controllers/landable/api/access_tokens_controller.rb
landable-1.12.1 app/controllers/landable/api/access_tokens_controller.rb
landable-1.11.1 app/controllers/landable/api/access_tokens_controller.rb
landable-1.11.0 app/controllers/landable/api/access_tokens_controller.rb
landable-1.10.0.rc2 app/controllers/landable/api/access_tokens_controller.rb
landable-1.10.0.rc1 app/controllers/landable/api/access_tokens_controller.rb
landable-1.9.2 app/controllers/landable/api/access_tokens_controller.rb
landable-1.9.1 app/controllers/landable/api/access_tokens_controller.rb
landable-1.9.0 app/controllers/landable/api/access_tokens_controller.rb
landable-1.9.0.rc2 app/controllers/landable/api/access_tokens_controller.rb