class Eth::Client::Http
Provides an HTTP/S-RPC client.
def initialize(host)
-
host
(String
) -- an URI pointing to an HTTP RPC-API.
def initialize(host) super uri = URI.parse(host) raise ArgumentError, "Unable to parse the HTTP-URI!" unless ["http", "https"].include? uri.scheme @host = uri.host @port = uri.port @ssl = uri.scheme == "https" @uri = URI("#{uri.scheme}://#{@host}:#{@port}#{uri.path}") end
def send(payload)
-
(String)
- a JSON-encoded response.
Parameters:
-
payload
(Hash
) -- the RPC request parameters.
def send(payload) http = Net::HTTP.new(@host, @port) http.use_ssl = @ssl header = { "Content-Type" => "application/json" } request = Net::HTTP::Post.new(@uri, header) request.body = payload response = http.request(request) response.body end