Class: Bitcoin::RPC

Inherits:
Object
  • Object
show all
Defined in:
lib/bitcoin/rpc.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ RPC

Returns a new instance of RPC.



4
5
6
7
8
# File 'lib/bitcoin/rpc.rb', line 4

def initialize(options)
  @user, @pass = options[:user], options[:pass]
  @host, @port = options[:host], options[:port]
  @ssl = options[:ssl]
end

Instance Method Details

#credentialsObject



10
11
12
13
14
15
16
# File 'lib/bitcoin/rpc.rb', line 10

def credentials
  if @user
    "#{@user}:#{@pass}"
  else
    nil
  end
end

#dispatch(request) ⇒ Object



25
26
27
28
29
30
# File 'lib/bitcoin/rpc.rb', line 25

def dispatch(request)
  respdata = RestClient.post service_url, request.to_post_data
  response = JSON.parse(respdata)
  raise Bitcoin::Errors::RPCError, response['error'] if response['error']
  response['result']
end

#service_urlObject



18
19
20
21
22
23
# File 'lib/bitcoin/rpc.rb', line 18

def service_url
  url = @ssl ? "https://" : "http://"
  url.concat "#{credentials}@" if c = credentials
  url.concat "#{@host}:#{@port}"
  url
end