Class: JsonRpcObjects::V10::Response
- Inherits:
-
Generic::Response
- Object
- Generic::Object
- Generic::Response
- JsonRpcObjects::V10::Response
- Defined in:
- lib/json-rpc-objects/v10/response.rb
Overview
Response object class.
Direct Known Subclasses
Constant Summary collapse
- VERSION =
Holds link to its version module.
JsonRpcObjects::V10
- ERROR_CLASS =
Identifies the error object class.
JsonRpcObjects::V10::Error
Instance Attribute Summary collapse
-
#error ⇒ JsonRpcObjects::V10::Error
Holds error data.
-
#id ⇒ String
Call ID.
-
#result ⇒ Object
Holds result data.
Attributes inherited from Generic::Object
Class Method Summary collapse
-
.create(result = nil, error = nil, opts = { }) ⇒ V10::Response
Creates new one.
Instance Method Summary collapse
-
#<<(result) ⇒ Object
Receives result by array fill operator.
-
#check! ⇒ Object
Checks correctness of the request data.
-
#error? ⇒ Boolean
Indicates, response is error.
-
#output ⇒ Hash
Renders data to output hash.
Methods inherited from Generic::Object
#initialize, parse, #serialize, #to_json, version
Constructor Details
This class inherits a constructor from JsonRpcObjects::Generic::Object
Instance Attribute Details
#error ⇒ JsonRpcObjects::V10::Error
Holds error data.
51 52 53 |
# File 'lib/json-rpc-objects/v10/response.rb', line 51 def error @error end |
#id ⇒ String
Call ID.
59 60 61 |
# File 'lib/json-rpc-objects/v10/response.rb', line 59 def id @id end |
#result ⇒ Object
Holds result data.
43 44 45 |
# File 'lib/json-rpc-objects/v10/response.rb', line 43 def result @result end |
Class Method Details
.create(result = nil, error = nil, opts = { }) ⇒ V10::Response
Creates new one.
71 72 73 74 75 76 77 78 79 |
# File 'lib/json-rpc-objects/v10/response.rb', line 71 def self.create(result = nil, error = nil, opts = { }) data = { :result => result, :error => error } data.merge! opts return self::new(data) end |
Instance Method Details
#<<(result) ⇒ Object
Receives result by array fill operator.
121 122 123 |
# File 'lib/json-rpc-objects/v10/response.rb', line 121 def <<(result) @result = result end |
#check! ⇒ Object
Checks correctness of the request data.
85 86 87 88 89 90 91 |
# File 'lib/json-rpc-objects/v10/response.rb', line 85 def check! self.normalize! __check_coherency __check_id __check_error end |
#error? ⇒ Boolean
Indicates, response is error.
132 133 134 |
# File 'lib/json-rpc-objects/v10/response.rb', line 132 def error? not @error.nil? end |
#output ⇒ Hash
Renders data to output hash.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/json-rpc-objects/v10/response.rb', line 98 def output self.check! if @error.nil? error = nil else error = @error.output end data = { "result" => @result, "error" => error, "id" => @id } return data end |