Class: Latch::Error
- Inherits:
-
Object
- Object
- Latch::Error
- Defined in:
- lib/latch/error.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(json) ⇒ Error
constructor
A new instance of Error.
-
#to_json ⇒ Object
JSON representing the Error Object.
Constructor Details
#initialize(json) ⇒ Error
Returns a new instance of Error.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/latch/error.rb', line 24 def initialize(json) if (json.is_a?(String)) json = JSON.Parse(json) end if(json.has_key?("code") && json.has_key?("message")) @code = json["code"] @message = json["message"] else puts "Error creating error object from string " + json end end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
20 21 22 |
# File 'lib/latch/error.rb', line 20 def code @code end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
21 22 23 |
# File 'lib/latch/error.rb', line 21 def @message end |
Instance Method Details
#to_json ⇒ Object
JSON representing the Error Object
38 39 40 41 42 43 |
# File 'lib/latch/error.rb', line 38 def to_json error = {} error["code"] = @code error["message"] = @message error.to_json end |