Class: Jimson::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Response

Returns a new instance of Response.



5
6
7
# File 'lib/jimson/response.rb', line 5

def initialize(id)
  @id = id
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



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

def error
  @error
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#resultObject

Returns the value of attribute result.



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

def result
  @result
end

Instance Method Details

#is_error?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/jimson/response.rb', line 16

def is_error?
  !!@error
end

#populate!(data) ⇒ Object



24
25
26
27
# File 'lib/jimson/response.rb', line 24

def populate!(data)
  @error = data['error'] if !!data['error']
  @result = data['result'] if !!data['result']
end

#succeeded?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/jimson/response.rb', line 20

def succeeded?
  !!@result
end

#to_hObject



9
10
11
12
13
14
# File 'lib/jimson/response.rb', line 9

def to_h
  h = {'jsonrpc' => '2.0'}
  h.merge!('result' => @result) if !!@result
  h.merge!('error' => @error) if !!@error
  h.merge!('id' => @id)
end