Class: StartcoinClient::RPC
- Inherits:
-
Object
- Object
- StartcoinClient::RPC
- Defined in:
- lib/startcoin_client/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 9 |
# File 'lib/startcoin_client/rpc.rb', line 4 def initialize() @user, @pass = [:user], [:pass] @host, @port = [:host], [:port] @ssl, @proxy = [:ssl], [:proxy] @verify_ssl = [:verify_ssl] end |
Instance Method Details
#credentials ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/startcoin_client/rpc.rb', line 11 def credentials if @user "#{@user}:#{@pass}" else nil end end |
#dispatch(request) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/startcoin_client/rpc.rb', line 26 def dispatch(request) process_response = lambda do |respdata, _request, _result| response = JSON.parse(respdata) raise StartcoinClient::Errors::RPCError, response['error'] if response['error'] response['result'] end RestClient::Request.execute(method: :post, url: service_url, payload: request.to_post_data, proxy: @proxy, verify_ssl: false, headers: { content_type: :json }, &process_response) end |
#service_url ⇒ Object
19 20 21 22 23 24 |
# File 'lib/startcoin_client/rpc.rb', line 19 def service_url url = @ssl ? "https://" : "http://" url.concat "#{credentials}@" if c = credentials url.concat "#{@host}:#{@port}" url end |