Class: Eth::Client::Http
- Inherits:
-
Eth::Client
- Object
- Eth::Client
- Eth::Client::Http
- Defined in:
- lib/eth/client/http.rb
Overview
Provides an HTTP/S-RPC client with basic authentication.
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
The host of the HTTP endpoint.
-
#port ⇒ Object
readonly
The port of the HTTP endpoint.
-
#ssl ⇒ Object
readonly
Attribute indicator for SSL.
-
#uri ⇒ Object
readonly
The full URI of the HTTP endpoint, including path.
-
#user ⇒ Object
readonly
Attribute for user.
Instance Method Summary collapse
-
#initialize(host) ⇒ Http
constructor
Constructor for the HTTP Client.
-
#send_request(payload) ⇒ String
Sends an RPC request to the connected HTTP client.
Constructor Details
#initialize(host) ⇒ Http
Constructor for the HTTP Client. Should not be used; use Eth::Client.create instead.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/eth/client/http.rb', line 42 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" if !(uri.user.nil? && uri.password.nil?) @user = uri.user @password = uri.password if uri.query @uri = URI("#{uri.scheme}://#{uri.user}:#{uri.password}@#{@host}:#{@port}#{uri.path}?#{uri.query}") else @uri = URI("#{uri.scheme}://#{uri.user}:#{uri.password}@#{@host}:#{@port}#{uri.path}") end else @uri = uri end end |
Instance Attribute Details
#host ⇒ Object (readonly)
The host of the HTTP endpoint.
24 25 26 |
# File 'lib/eth/client/http.rb', line 24 def host @host end |
#port ⇒ Object (readonly)
The port of the HTTP endpoint.
27 28 29 |
# File 'lib/eth/client/http.rb', line 27 def port @port end |
#ssl ⇒ Object (readonly)
Attribute indicator for SSL.
33 34 35 |
# File 'lib/eth/client/http.rb', line 33 def ssl @ssl end |
#uri ⇒ Object (readonly)
The full URI of the HTTP endpoint, including path.
30 31 32 |
# File 'lib/eth/client/http.rb', line 30 def uri @uri end |
#user ⇒ Object (readonly)
Attribute for user.
36 37 38 |
# File 'lib/eth/client/http.rb', line 36 def user @user end |
Instance Method Details
#send_request(payload) ⇒ String
Sends an RPC request to the connected HTTP client.
66 67 68 69 70 71 72 73 74 |
# File 'lib/eth/client/http.rb', line 66 def send_request(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 |