lib/error.rb in bobes-textmagic-0.1.0 vs lib/error.rb in bobes-textmagic-0.2.0
- old
+ new
@@ -4,11 +4,20 @@
class Error < StandardError
attr_reader :code, :message
- def initialize(response)
- @code, @message = response[:error_code], response[:error_message]
+ # Creates an instance of TextMagic::API::Error. Error code and message
+ # can be supplied as arguments or as a response 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, @message = args.first['error_code'], args.first['error_message']
+ else
+ @code, @message = args
+ end
end
def to_s
"#{@message} (#{@code})"
end