Class: Jimson::Request

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, params, id = nil) ⇒ Request

Returns a new instance of Request.



5
6
7
8
9
# File 'lib/jimson/request.rb', line 5

def initialize(method, params, id = nil)
  @method = method
  @params = params
  @id = id
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/jimson/request.rb', line 4

def id
  @id
end

#methodObject

Returns the value of attribute method.



4
5
6
# File 'lib/jimson/request.rb', line 4

def method
  @method
end

#paramsObject

Returns the value of attribute params.



4
5
6
# File 'lib/jimson/request.rb', line 4

def params
  @params
end

Instance Method Details

#to_hObject



11
12
13
14
15
16
17
18
# File 'lib/jimson/request.rb', line 11

def to_h
  h = {
    'jsonrpc' => '2.0',
    'method'  => @method
  }
  h.merge!('params' => @params) if !!@params && !params.empty?
  h.merge!('id' => id)
end

#to_json(*a) ⇒ Object



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

def to_json(*a)
  self.to_h.to_json(*a)
end