class Eth::Client::HttpAuth

Provides an HTTP/S-RPC client with basic authentication.

def initialize(host)

Parameters:
  • 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"
  @user = uri.user
  @password = uri.password
  @uri = URI("#{uri.scheme}://#{uri.user}:#{uri.password}@#{@host}:#{@port}#{uri.path}")
end

def send(payload)

Returns:
  • (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