Class: WirisPlugin::JsonAPIResponse
- Inherits:
-
Object
- Object
- WirisPlugin::JsonAPIResponse
- 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
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#result ⇒ Object
Returns the value of attribute result.
-
#status ⇒ Object
Returns the value of attribute status.
-
#warnings ⇒ Object
Returns the value of attribute warnings.
Instance Method Summary collapse
- #addError(error) ⇒ Object
- #addResult(key, value) ⇒ Object
- #addWarning(warning) ⇒ Object
- #getResponse ⇒ Object
- #getResult ⇒ Object
- #getStatus ⇒ Object
-
#initialize ⇒ JsonAPIResponse
constructor
A new instance of JsonAPIResponse.
- #setResult(obj) ⇒ Object
- #setStatus(status) ⇒ Object
- #toString ⇒ Object
Constructor Details
#initialize ⇒ JsonAPIResponse
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
#errors ⇒ Object
Returns the value of attribute errors.
18 19 20 |
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 18 def errors @errors end |
#result ⇒ Object
Returns the value of attribute result.
17 18 19 |
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 17 def result @result end |
#status ⇒ Object
Returns the value of attribute status.
16 17 18 |
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 16 def status @status end |
#warnings ⇒ Object
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 |
#getResponse ⇒ Object
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 |
#getResult ⇒ Object
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 |
#getStatus ⇒ Object
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 |
#toString ⇒ Object
65 66 67 |
# File 'lib/com/wiris/util/json/JsonAPIResponse.rb', line 65 def toString() return self.getResponse() end |