Class: AlphaApi::BaseController

Inherits:
ActionController::API
  • Object
show all
Defined in:
lib/alpha_api/base_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_auth_tokenObject (readonly)

Returns the value of attribute current_auth_token.



55
56
57
# File 'lib/alpha_api/base_controller.rb', line 55

def current_auth_token
  @current_auth_token
end

#current_auth_token_payloadObject (readonly)

Returns the value of attribute current_auth_token_payload.



55
56
57
# File 'lib/alpha_api/base_controller.rb', line 55

def current_auth_token_payload
  @current_auth_token_payload
end

#current_userObject (readonly)

Returns the value of attribute current_user.



55
56
57
# File 'lib/alpha_api/base_controller.rb', line 55

def current_user
  @current_user
end

Instance Method Details

#error_generator(title, detail, source = nil) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/alpha_api/base_controller.rb', line 57

def error_generator(title, detail, source = nil)
  error = { title: title, detail: detail }
  if source
    key_mapper = {
      organisation: 'organisation_id',
      splash: 'splash_id',
      box_hardware: 'box_hardware_id'
    }
    error[:source] = { pointer: "/data/attributes/#{key_mapper[source] || source}" }
  end
  error
end

#method_not_allowedObject Also known as: create, destroy, index, update



82
83
84
85
86
87
88
# File 'lib/alpha_api/base_controller.rb', line 82

def method_not_allowed
  error = error_generator(
    'Method Not Allowed',
    "Method #{request.method} is not allowed on #{request.path}"
  )
  render json: { errors: [error] }, status: :method_not_allowed
end

#not_foundObject Also known as: show



74
75
76
77
78
79
80
# File 'lib/alpha_api/base_controller.rb', line 74

def not_found
  error = error_generator(
    'Not Found',
    "Resource #{request.path} is not found"
  )
  render json: { errors: [error] }, status: :not_found
end

#unsupported_media_typeObject



70
71
72
# File 'lib/alpha_api/base_controller.rb', line 70

def unsupported_media_type
  head :unsupported_media_type
end

#versionObject



96
97
98
# File 'lib/alpha_api/base_controller.rb', line 96

def version
  render json: Constants::VERSION
end