Exception: Clickatell::API::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/clickatell/api/error.rb

Overview

Clickatell API Error exception.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, message) ⇒ Error

Returns a new instance of Error.



8
9
10
# File 'lib/clickatell/api/error.rb', line 8

def initialize(code, message)
  @code, @message = code, message
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/clickatell/api/error.rb', line 6

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/clickatell/api/error.rb', line 6

def message
  @message
end

Class Method Details

.parse(error_string) ⇒ Object

Creates a new Error from a Clickatell HTTP response string e.g.:

Error.parse("ERR: 001, Authentication error")
# =>  #<Clickatell::API::Error code='001' message='Authentication error'>


21
22
23
24
25
# File 'lib/clickatell/api/error.rb', line 21

def self.parse(error_string)
  error_details = error_string.split(':').last.strip
  code, message = error_details.split(',').map { |s| s.strip }
  self.new(code, message)
end

Instance Method Details

#to_sObject



12
13
14
# File 'lib/clickatell/api/error.rb', line 12

def to_s
  "#{@code}: #{@message}"
end