Class: Ant::Client::Validator::JSend

Inherits:
Object
  • Object
show all
Includes:
Exceptions
Defined in:
lib/ant/client/validator/jsend.rb

Constant Summary collapse

EXCEPTION_LIST =
{
  'fail' => AntFail,
  'error' => AntError,
  'fatal' => AntError
}.freeze

Instance Method Summary collapse

Instance Method Details

#validate(response) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ant/client/validator/jsend.rb', line 12

def validate(response)
  case response[:status]
  when 'success'
    response[:data]
  when 'fail', 'error', 'fatal'
    exception_klass = EXCEPTION_LIST[response[:status]]
    raise exception_klass.new(response[:message],
                              response[:code],
                              response[:data])
  else
    raise(AntError, 'Unknown Error')
  end
end