Class: Jeth::HttpClient
Constant Summary
Constants inherited from Client
Client::RPC_COMMANDS, Client::RPC_MANAGEMENT_COMMANDS
Instance Method Summary collapse
-
#initialize(host = 'http://localhost:8545') ⇒ HttpClient
constructor
A new instance of HttpClient.
- #send_single(payload) ⇒ Object
Methods inherited from Client
#batch, #encode_params, #get_id, #reset_id, #send_batch
Constructor Details
#initialize(host = 'http://localhost:8545') ⇒ HttpClient
Returns a new instance of HttpClient.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/jeth/http_client.rb', line 5 def initialize(host = 'http://localhost:8545') super() uri = URI.parse(host) raise ArgumentError unless ['http', 'https'].include? uri.scheme @host = uri.host @port = uri.port @ssl = uri.scheme == 'https' if @ssl @uri = URI("https://#{@host}:#{@port}") else @uri = URI("http://#{@host}:#{@port}") end end |
Instance Method Details
#send_single(payload) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/jeth/http_client.rb', line 20 def send_single(payload) http = ::Net::HTTP.new(@host, @port) if @ssl http.use_ssl = true end header = {'Content-Type' => 'application/json'} request = ::Net::HTTP::Post.new(@uri, header) request.body = payload response = http.request(request) return response.body end |