Class: MessagebirdTexter::Response::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/messagebird_texter/response/error.rb

Constant Summary collapse

ERROR_CODES =
{
  2 => 'Request not allowed',
  9 => 'Missing params',
  10 => 'Invalid params',
  20 => 'Not found',
  25 => 'Not enough balance',
  98 => 'API not found',
  99 => 'Internal error'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error) ⇒ Error

Returns a new instance of Error.



16
17
18
# File 'lib/messagebird_texter/response/error.rb', line 16

def initialize(error)
  @errors = JSON.parse(error, symbolize_names: true)[:errors]
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/messagebird_texter/response/error.rb', line 4

def code
  @code
end

#descriptionObject (readonly)

Returns the value of attribute description.



4
5
6
# File 'lib/messagebird_texter/response/error.rb', line 4

def description
  @description
end

Instance Method Details

#countObject



24
25
26
# File 'lib/messagebird_texter/response/error.rb', line 24

def count
  @errors.count
end

#errorsObject



20
21
22
# File 'lib/messagebird_texter/response/error.rb', line 20

def errors
  @errors.map { |e| e.merge(error_message: ERROR_CODES[e[:code]]) }
end