Class: WirisPlugin::JsonAPIResponse

Inherits:
Object
  • Object
show all
Includes:
Wiris
Defined in:
lib/com/wiris/util/json/JsonAPIResponse.rb

Constant Summary collapse

STATUS_OK =
0
STATUS_WARNING =
1
STATUS_ERROR =
-1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJsonAPIResponse

Returns a new instance of JsonAPIResponse.



10
11
12
13
14
15
# 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

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



18
19
20
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 18

def errors
  @errors
end

#resultObject

Returns the value of attribute result.



17
18
19
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 17

def result
  @result
end

#statusObject

Returns the value of attribute status.



16
17
18
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 16

def status
  @status
end

#warningsObject

Returns the value of attribute warnings.



19
20
21
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 19

def warnings
  @warnings
end

Instance Method Details

#addError(error) ⇒ Object



53
54
55
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 53

def addError(error)
    self.errors::push(error)
end

#addResult(key, value) ⇒ Object



37
38
39
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 37

def addResult(key, value)
    self.result::set(key,value)
end

#addWarning(warning) ⇒ Object



50
51
52
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 50

def addWarning(warning)
    self.warnings::push(warning)
end

#getResponseObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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

#getResultObject



43
44
45
46
47
48
49
# 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

#getStatusObject



62
63
64
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 62

def getStatus()
    return self.status
end

#setResult(obj) ⇒ Object



40
41
42
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 40

def setResult(obj)
    self.result = obj
end

#setStatus(status) ⇒ Object



56
57
58
59
60
61
# 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

#toStringObject



65
66
67
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 65

def toString()
    return self.getResponse()
end