Class: QRPC::Protocol::JsonRpc::Response
- Inherits:
-
Abstract::Response
- Object
- Abstract::Object
- Abstract::Response
- QRPC::Protocol::JsonRpc::Response
- Defined in:
- lib/qrpc/protocol/json-rpc/response.rb
Overview
JSON-RPC response implementation.
Instance Attribute Summary collapse
-
#native ⇒ JsonRpcObjects::Response
Returns the native object.
Attributes inherited from Abstract::Object
Class Method Summary collapse
-
.parse(raw) ⇒ Response
Parses the data for new object.
Instance Method Summary collapse
-
#error ⇒ Exception
Returns response error.
-
#error? ⇒ Boolean
Indicates, error state of the response.
-
#id ⇒ Object
Returns ID of the response.
-
#result ⇒ Object
Returns response result.
-
#serialize ⇒ String
Serializes object to the resultant form.
Methods inherited from Abstract::Response
Methods inherited from Abstract::Object
Constructor Details
This class inherits a constructor from QRPC::Protocol::Abstract::Response
Instance Attribute Details
#native ⇒ JsonRpcObjects::Response
Returns the native object.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/qrpc/protocol/json-rpc/response.rb', line 63 def native if @native.nil? result = @options.result error = @options.error request = @options.request error_native = error.nil? ? nil : error.native @native = request.native.class::version.response::create(result, error_native, :id => request.id) @native.serializer = @options.serializer @native.qrpc = QRPC::Protocol::JsonRpc::Native::QrpcObject::create.output end @native end |
Class Method Details
.parse(raw) ⇒ Response
Parses the data for new object.
52 53 54 55 56 |
# File 'lib/qrpc/protocol/json-rpc/response.rb', line 52 def self.parse(raw) object = self::new object.native = JsonRpcObjects::Response::parse(raw, :wd, self::.serializer) return object end |
Instance Method Details
#error ⇒ Exception
Returns response error.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/qrpc/protocol/json-rpc/response.rb', line 110 def error # Converts protocol exception to exception data object proto = QRPC::Protocol::JsonRpc::Native::ExceptionData::new(native.error.data) # Tries to unmarshall if proto.dump.format == :ruby begin exception = Marshal.load(Base64.decode64(proto.dump.raw)) rescue # pass end end # If unsuccessfull, creates from data if exception.nil? backtrace = data.backtrace.map { |i| Base64.decode64(i) } backtrace.reject! { |i| i.empty? } exception = self::new(data.name, data., backtrace) end return exception end |
#error? ⇒ Boolean
Indicates, error state of the response.
101 102 103 |
# File 'lib/qrpc/protocol/json-rpc/response.rb', line 101 def error? self.native.error? end |
#id ⇒ Object
Returns ID of the response.
92 93 94 |
# File 'lib/qrpc/protocol/json-rpc/response.rb', line 92 def id self.native.id end |
#result ⇒ Object
Returns response result.
140 141 142 |
# File 'lib/qrpc/protocol/json-rpc/response.rb', line 140 def result self.native.result end |
#serialize ⇒ String
Serializes object to the resultant form.
83 84 85 |
# File 'lib/qrpc/protocol/json-rpc/response.rb', line 83 def serialize self.native.serialize end |