Class: Tzispa::Api::Handler

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tzispa/api/handler.rb

Constant Summary collapse

HANDLED_UNDEFINED =
nil
HANDLED_OK =
1
HANDLED_MISSING_PARAMETER =
98
HANDLED_ERROR =
99
HANDLED_RESULT =
200
HANDLED_MESSAGES =
{
  HANDLED_OK                => 'La operación se ha realizado correctamente',
  HANDLED_MISSING_PARAMETER => 'Error: faltan parámetros para realizar la operación',
  HANDLED_ERROR             => 'Error indeterminado: la operación no se ha podido realizar'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Handler

Returns a new instance of Handler.



26
27
28
# File 'lib/tzispa/api/handler.rb', line 26

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



12
13
14
# File 'lib/tzispa/api/handler.rb', line 12

def context
  @context
end

#dataObject (readonly)

Returns the value of attribute data.



12
13
14
# File 'lib/tzispa/api/handler.rb', line 12

def data
  @data
end

#response_verbObject (readonly)

Returns the value of attribute response_verb.



12
13
14
# File 'lib/tzispa/api/handler.rb', line 12

def response_verb
  @response_verb
end

#statusObject (readonly)

Returns the value of attribute status.



12
13
14
# File 'lib/tzispa/api/handler.rb', line 12

def status
  @status
end

Instance Method Details

#messageObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tzispa/api/handler.rb', line 37

def message
  if @status.nil?
    nil
  elsif @status >= HANDLED_OK && @status <= HANDLED_ERROR
    HANDLED_MESSAGES[@status]
  elsif @status > HANDLED_ERROR && @status < HANDLED_RESULT
    error_message @status
  elsif @status > HANDLED_RESULT
    result_messages @status
  else
    nil
  end
end

#result(response_verb:, status: HANDLED_UNDEFINED, data: nil, detailed_error: nil) ⇒ Object



30
31
32
33
34
35
# File 'lib/tzispa/api/handler.rb', line 30

def result(response_verb:, status: HANDLED_UNDEFINED, data: nil, detailed_error: nil)
  @status = status
  @response_verb = response_verb
  @data = data
  @detailed_error = detailed_error
end