Sha256: c097eebbad27708f31beee5c2298d51feb85b6c8f852330ca3ba6f3c0cefd273

Contents?: true

Size: 678 Bytes

Versions: 2

Compression:

Stored size: 678 Bytes

Contents

module TextMagic

  class API

    class Error < StandardError

      attr_reader :code, :message

      # Creates an instance of TextMagic::API::Error. Error code and error message
      # can be supplied as arguments or in a hash.
      #
      #  TextMagic::API::Error.new(code, message)
      #  TextMagic::API::Error.new("error_code" => code, "error_message" => message)
      def initialize(*args)
        if args.first.is_a?(Hash)
          @code = args.first["error_code"]
          @message = args.first["error_message"]
        else
          @code, @message = args
        end
      end

      def to_s
        "#{@message} (#{@code})"
      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
textmagic-0.7.1 lib/textmagic/error.rb
textmagic-0.7.0 lib/textmagic/error.rb