class WirisPlugin::JsonAPIResponse
Constants
- STATUS_ERROR
- STATUS_OK
- STATUS_WARNING
Attributes
errors[RW]
result[RW]
status[RW]
warnings[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/com/wiris/util/json/JsonAPIResponse.rb, line 10 def initialize() super() self.result = Hash.new() self.errors = Array.new() self.warnings = Array.new() end
Public Instance Methods
addError(error)
click to toggle source
# File lib/com/wiris/util/json/JsonAPIResponse.rb, line 53 def addError(error) self.errors::push(error) end
addResult(key, value)
click to toggle source
# File lib/com/wiris/util/json/JsonAPIResponse.rb, line 37 def addResult(key, value) self.result::set(key,value) end
addWarning(warning)
click to toggle source
# File lib/com/wiris/util/json/JsonAPIResponse.rb, line 50 def addWarning(warning) self.warnings::push(warning) end
getResponse()
click to toggle source
# File lib/com/wiris/util/json/JsonAPIResponse.rb, line 20 def getResponse() response = Hash.new() if self.status == STATUS_ERROR response::set("errors",self.errors) response::set("status","error") end if self.status == STATUS_WARNING response::set("warnings",self.warnings) response::set("result",self.result) response::set("status","warning") end if self.status == STATUS_OK response::set("result",self.result) response::set("status","ok") end return JSon::encode(response) end
getResult()
click to toggle source
# File lib/com/wiris/util/json/JsonAPIResponse.rb, line 43 def getResult() if self.status == STATUS_ERROR return nil else return self.result end end
getStatus()
click to toggle source
# File lib/com/wiris/util/json/JsonAPIResponse.rb, line 62 def getStatus() return self.status end
setResult(obj)
click to toggle source
# File lib/com/wiris/util/json/JsonAPIResponse.rb, line 40 def setResult(obj) self.result = obj end
setStatus(status)
click to toggle source
# File lib/com/wiris/util/json/JsonAPIResponse.rb, line 56 def setStatus(status) if ((status != STATUS_OK) && (status != STATUS_WARNING)) && (status != STATUS_ERROR) raise Exception,"Invalid status code" end self.status = status end
toString()
click to toggle source
# File lib/com/wiris/util/json/JsonAPIResponse.rb, line 65 def toString() return self.getResponse() end