class Saorin::Response
Attributes
error[RW]
id[RW]
result[RW]
version[RW]
Public Class Methods
from_hash(hash)
click to toggle source
# File lib/saorin/response.rb, line 45 def self.from_hash(hash) raise Saorin::InvalidResponse unless hash.is_a?(::Hash) new Saorin::Utility.symbolized_keys(hash) end
new(options = {})
click to toggle source
# File lib/saorin/response.rb, line 11 def initialize(options = {}) @version = options[:version] || Saorin::JSON_RPC_VERSION @result = options[:result] @error = options[:error] @id = options[:id] end
Public Instance Methods
error?()
click to toggle source
# File lib/saorin/response.rb, line 18 def error? !!@error end
to_h()
click to toggle source
# File lib/saorin/response.rb, line 36 def to_h h = {} h['jsonrpc'] = @version h['result'] = @result unless error? h['error'] = @error if error? h['id'] = id h end
valid?()
click to toggle source
# File lib/saorin/response.rb, line 22 def valid? return false unless !(@result && @error) return false unless [String].any? { |type| @version.is_a? type } return false unless [Object].any? { |type| @result.is_a? type } return false unless [Saorin::Error, Hash, NilClass].any? { |type| @error.is_a? type } return false unless [String, Numeric, NilClass].any? { |type| @id.is_a? type } return false unless @version == JSON_RPC_VERSION true end
validate()
click to toggle source
# File lib/saorin/response.rb, line 32 def validate raise Saorin::InvalidResponse unless valid? end