Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/clickatell/api/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ def initialize(code, message)
# Error.parse("ERR: 001, Authentication error")
# # => #<Clickatell::API::Error code='001' message='Authentication error'>
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)
if error_string =~ /^ERR: (\d+), (.*)$/
self.new($1, $2)
else
self.new(nil, error_string)
end
end
end

Expand Down
8 changes: 5 additions & 3 deletions lib/clickatell/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class << self
def parse(http_response)
return { 'OK' => 'session_id' } if API.test_mode

if http_response.body.scan(/ERR/).any?
raise Clickatell::API::Error.parse(http_response.body)
lines = http_response.body.split("\n").reject {|line| line.strip.size == 0 }

if lines.size == 1 && lines.first =~ /^ERR:/
raise Clickatell::API::Error.parse(lines.first)
end
results = http_response.body.split("\n").map do |line|
results = lines.map do |line|
# YAML.load converts integer strings that have leading zeroes into integers
# using octal rather than decimal. This isn't what we want, so we'll strip out any
# leading zeroes in numbers here.
Expand Down