Class: ActiveRpc::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/active_rpc/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:) ⇒ Response

Returns a new instance of Response.



6
7
8
# File 'lib/active_rpc/response.rb', line 6

def initialize(id:)
  @id = id
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



3
4
5
# File 'lib/active_rpc/response.rb', line 3

def error
  @error
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/active_rpc/response.rb', line 4

def id
  @id
end

#resultObject

Returns the value of attribute result.



3
4
5
# File 'lib/active_rpc/response.rb', line 3

def result
  @result
end

Class Method Details

.from_request(req) ⇒ Object



23
24
25
# File 'lib/active_rpc/response.rb', line 23

def self.from_request(req)
  new(id: req.id)
end

Instance Method Details

#to_hashObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/active_rpc/response.rb', line 10

def to_hash
  {
   'jsonrpc' => '2.0',
    'id' => id
  }.tap do |h|
    if error
      h['error'] = error.to_hash
    else
      h['result'] = result
    end
  end
end