Class: Error

Inherits:
Object
  • Object
show all
Defined in:
lib/latchsdk/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



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/latchsdk/Error.rb', line 27

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.



23
24
25
# File 'lib/latchsdk/Error.rb', line 23

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



24
25
26
# File 'lib/latchsdk/Error.rb', line 24

def message
  @message
end

Instance Method Details

#to_jsonObject

JSON representing the Error Object



41
42
43
44
45
46
# File 'lib/latchsdk/Error.rb', line 41

def to_json
  error =  {}
  error["code"] = @code
  error["message"] = @message
  error.to_json
end