Class: MasterApiKey::ApiKeysController

Inherits:
ApplicationController show all
Defined in:
app/controllers/master_api_key/api_keys_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /api_keys



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/master_api_key/api_keys_controller.rb', line 27

def create
  authorizers = authorizer_params
  created_api_key = ApiKey.create! do |api_key|
    api_key.group = group_param
    unless authorizers.nil?
      access_types = [TrueClass, FalseClass]
      read_access = authorizers[:read_access]
      write_access = authorizers[:write_access]
      api_key.read_access = enforce_param_type(read_access, :read_access, *access_types) unless read_access.nil?
      api_key.write_access = enforce_param_type(write_access, :write_access, *access_types) unless write_access.nil?
    end
  end

  render json: { api_key: created_api_key}, status: :created
end

#destroyObject

DELETE /api_keys/1 deprecated



55
56
57
58
59
# File 'app/controllers/master_api_key/api_keys_controller.rb', line 55

def destroy
  ApiKey.delete_all(['id = ?', access_id_param])
  message = 'This method has been deprecated since this is less secure than access by token. It will be removed in v2.0.0'
  render text: message, status: :ok
end

#destroy_by_access_tokenObject

DELETE /api_keys



62
63
64
65
66
# File 'app/controllers/master_api_key/api_keys_controller.rb', line 62

def destroy_by_access_token
  Rails.logger.warn "The api token is #{access_token_param}"
  ApiKey.delete_all(['api_token = ?', access_token_param])
  head :ok
end

#indexObject

GET /api_keys



18
19
20
21
22
23
24
# File 'app/controllers/master_api_key/api_keys_controller.rb', line 18

def index
  found_api_key = ApiKey.find_by_api_token(access_token_param)

  check_presence_before_action(found_api_key) do |api_key|
    render json: { api_key: api_key}, status: :ok
  end
end

#update_by_access_tokenObject

PATCH /api_keys/



44
45
46
47
48
49
50
51
# File 'app/controllers/master_api_key/api_keys_controller.rb', line 44

def update_by_access_token
  updated_api_key = ApiKey.find_by_api_token(access_token_param)

  check_presence_before_action(updated_api_key) do |api_key|
    api_key.update_attributes(required_auth_params)
    render json: { api_key: api_key}, status: :ok
  end
end