class Katapaty::Block

Public Class Methods

method_missing(name, *args) click to toggle source
# 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: {}) click to toggle source
# File lib/katapaty/block.rb, line 27
def proxy_to_cp(method:, params: {})
  client = RestClient::Resource.new(Katapaty.configuration.counterblock_url, timeout: Katapaty.configuration.timeout)
  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={}) click to toggle source
# File lib/katapaty/block.rb, line 9
def request(method_name, params={})
  client = RestClient::Resource.new(Katapaty.configuration.counterblock_url, timeout: Katapaty.configuration.timeout)
  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