class QRPC::Protocol::JsonRpc::Response
JSON-RPC response implementation. @since 0.9.0
Attributes
native[W]
Holds native object.
Public Class Methods
parse(raw)
click to toggle source
Parses the data for new object.
@param [String] raw raw data @return [Response] new request according to data
# 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::options.serializer) return object end
Public Instance Methods
error()
click to toggle source
Returns response error. @return [Exception] error object
# 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.message, backtrace) end return exception end
error?()
click to toggle source
Indicates, error state of the response. @return [Boolean] error indication
# File lib/qrpc/protocol/json-rpc/response.rb, line 101 def error? self.native.error? end
id()
click to toggle source
Returns ID of the response. @return [Object] response ID
# File lib/qrpc/protocol/json-rpc/response.rb, line 92 def id self.native.id end
native()
click to toggle source
Returns the native object. @return [JsonRpcObjects::Response] native response object
# 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
result()
click to toggle source
Returns response result. @return [Object] response result
# File lib/qrpc/protocol/json-rpc/response.rb, line 140 def result self.native.result end
serialize()
click to toggle source
Serializes object to the resultant form. @return [String] serialized form
# File lib/qrpc/protocol/json-rpc/response.rb, line 83 def serialize self.native.serialize end