Class: Katapaty::Block
- Inherits:
-
Object
- Object
- Katapaty::Block
- Defined in:
- lib/katapaty/block.rb
Class Method Summary collapse
- .method_missing(name, *args) ⇒ Object
- .proxy_to_cp(method:, params: {}) ⇒ Object
- .request(method_name, params = {}) ⇒ Object
Class Method Details
.method_missing(name, *args) ⇒ Object
22 23 24 25 |
# File 'lib/katapaty/block.rb', line 22 def method_missing(name, *args) params = args.nil? ? {} : args.first request(name, params) end |
.proxy_to_cp(method:, params: {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/katapaty/block.rb', line 27 def proxy_to_cp(method:, params: {}) client = RestClient::Resource.new Katapaty.configuration.counterblock_url request = { method: :proxy_to_counterpartyd, params: { method: method, params: params }, jsonrpc: '2.0', id: '0' }.to_json response = JSON.parse client.post( request, accept: 'json', content_type: 'json' ) raise JsonResponseError.new response if response.has_key? 'code' raise ResponseError.new response['error'] if response.has_key? 'error' response['result'] end |
.request(method_name, params = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/katapaty/block.rb', line 9 def request(method_name, params={}) client = RestClient::Resource.new Katapaty.configuration.counterblock_url request = { method: method_name, params: params, jsonrpc: '2.0', id: '0' }.to_json response = JSON.parse client.post( request, accept: 'json', content_type: 'json' ) raise JsonResponseError.new response if response.has_key? 'code' raise ResponseError.new response['error'] if response.has_key? 'error' response['result'] end |