class CounterpartyRPC

Public Class Methods

new(service_url) click to toggle source
# File lib/counterparty_client/counterparty_rpc.rb, line 6
def initialize(service_url)
  @uri = URI.parse(service_url)
end

Public Instance Methods

http_post_request(post_body) click to toggle source
# File lib/counterparty_client/counterparty_rpc.rb, line 18
def http_post_request(post_body)
  http    = Net::HTTP.new(@uri.host, @uri.port)
  http    = http.start
  request = Net::HTTP::Post.new(@uri.request_uri)
  request.basic_auth @uri.user, @uri.password
  request.content_type = 'application/json'
  request.body = post_body
  ret = http.request(request).body
  http.finish
  return ret
end
method_missing(name, *args) click to toggle source
# File lib/counterparty_client/counterparty_rpc.rb, line 10
def method_missing(name, *args)
  args = args.nil? ? nil : args.first
  post_body = { 'method' => name, 'params' => args, 'jsonrpc' => '2.0', 'id' => '0' }.to_json
  resp = JSON.parse( http_post_request(post_body) )
  raise JSONRPCError, resp['error'] if resp['error']
  resp['result']
end