Class: Lightning::Request
- Inherits:
-
Object
- Object
- Lightning::Request
- Defined in:
- lib/lightning/request.rb
Overview
c-lightning request
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#plugin ⇒ Object
readonly
Returns the value of attribute plugin.
-
#result ⇒ Object
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
- #apply_result(result) ⇒ Object
-
#initialize(plugin, id, method, params) ⇒ Request
constructor
A new instance of Request.
- #method_args ⇒ Object
Constructor Details
#initialize(plugin, id, method, params) ⇒ Request
Returns a new instance of Request.
13 14 15 16 17 18 19 |
# File 'lib/lightning/request.rb', line 13 def initialize(plugin, id, method, params) @plugin = plugin @id = id @method = method @params = params @log = plugin.log end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/lightning/request.rb', line 7 def id @id end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
11 12 13 |
# File 'lib/lightning/request.rb', line 11 def log @log end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
8 9 10 |
# File 'lib/lightning/request.rb', line 8 def method @method end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/lightning/request.rb', line 9 def params @params end |
#plugin ⇒ Object (readonly)
Returns the value of attribute plugin.
6 7 8 |
# File 'lib/lightning/request.rb', line 6 def plugin @plugin end |
#result ⇒ Object
Returns the value of attribute result.
10 11 12 |
# File 'lib/lightning/request.rb', line 10 def result @result end |
Class Method Details
.parse_from_json(plugin, json) ⇒ Object
21 22 23 |
# File 'lib/lightning/request.rb', line 21 def self.parse_from_json(plugin, json) self.new(plugin, json['id'], json['method']&.to_sym, json['params']) end |
Instance Method Details
#apply_result(result) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/lightning/request.rb', line 35 def apply_result(result) @result = result json = { jsonrpc: '2.0', id: id, result: result }.to_json log.info "write response: #{json.to_s}" plugin.stdout.write(json.to_s + "\n\n") plugin.stdout.flush end |
#method_args ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/lightning/request.rb', line 25 def method_args if params.is_a?(Array) params elsif params.is_a?(Hash) params.values else raise ArgumentError, "params does not support format. #{params}" end end |