Class: Jimson::Request
- Inherits:
-
Object
- Object
- Jimson::Request
- Defined in:
- lib/jimson/request.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#method ⇒ Object
Returns the value of attribute method.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(method, params, id = nil) ⇒ Request
constructor
A new instance of Request.
- #to_h ⇒ Object
- #to_json(*a) ⇒ Object
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
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/jimson/request.rb', line 4 def id @id end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/jimson/request.rb', line 4 def method @method end |
#params ⇒ Object
Returns the value of attribute params.
4 5 6 |
# File 'lib/jimson/request.rb', line 4 def params @params end |
Instance Method Details
#to_h ⇒ Object
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 |