Class: Bitcoin::RPC
- Inherits:
-
Object
- Object
- Bitcoin::RPC
- Defined in:
- lib/bitcoin/rpc.rb
Instance Method Summary collapse
- #credentials ⇒ Object
- #dispatch(request) ⇒ Object
-
#initialize(options) ⇒ RPC
constructor
A new instance of RPC.
- #service_url ⇒ Object
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() @user, @pass = [:user], [:pass] @host, @port = [:host], [:port] @ssl = [:ssl] end |
Instance Method Details
#credentials ⇒ Object
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 31 |
# File 'lib/bitcoin/rpc.rb', line 25 def dispatch(request) RestClient.post(service_url, request.to_post_data, content_type: :json) do |respdata, request, result| response = JSON.parse(respdata) raise Bitcoin::Errors::RPCError, response['error'] if response['error'] response['result'] end end |
#service_url ⇒ Object
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 |