Class: Latch::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/latch/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Error

Returns a new instance of Error.

Parameters:

  • string

    json a Json representation of an error with “code” and “message” elements



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

#codeObject (readonly)

Returns the value of attribute code.



20
21
22
# File 'lib/latch/error.rb', line 20

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



21
22
23
# File 'lib/latch/error.rb', line 21

def message
  @message
end

Instance Method Details

#to_jsonObject

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