Sha256: 9044f56e7f3d148d02817f09d6d957bbfe3a2e2450a6e7f0aa51ade8d9e8d41f

Contents?: true

Size: 689 Bytes

Versions: 13

Compression:

Stored size: 689 Bytes

Contents

module Clickatell
  class API
  
    # Clickatell API Error exception.
    class Error < StandardError
      attr_reader :code, :message
      
      def initialize(code, message)
        @code, @message = code, message
      end
      
      # 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'>
      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
    end
  
  end
end

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
commonthread-clickatell-0.5.1 lib/clickatell/api/error.rb
commonthread-clickatell-0.5.2 lib/clickatell/api/error.rb
clickatell-0.8.2 lib/clickatell/api/error.rb
clickatell-0.8.1 lib/clickatell/api/error.rb
clickatell-0.8.0 lib/clickatell/api/error.rb
clickatell-ruby19-0.7.1 lib/clickatell/api/error.rb
clickatell-0.7.1 lib/clickatell/api/error.rb
dimiro1-clickatell-0.7.0 lib/clickatell/api/error.rb
clickatell-0.7.0 lib/clickatell/api/error.rb
clickatell-0.6.0 lib/clickatell/api/error.rb
clickatell-0.5.0 lib/clickatell/api/error.rb
clickatell-0.4.1 lib/clickatell/api/error.rb
clickatell-0.4.0 lib/clickatell/api/error.rb