Class: Ethereum::HttpClient
- Defined in:
- lib/ethereum/http_client.rb
Constant Summary
Constants inherited from Client
Client::RPC_COMMANDS, Client::RPC_MANAGEMENT_COMMANDS
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#ssl ⇒ Object
Returns the value of attribute ssl.
-
#uri ⇒ Object
Returns the value of attribute uri.
Attributes inherited from Client
#command, #default_account, #id, #log, #logger
Instance Method Summary collapse
-
#initialize(host, log = false) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #send_batch(batch) ⇒ Object
- #send_single(payload) ⇒ Object
Methods inherited from Client
#batch, create, #encode_params, #get_id, #int_to_hex, #reset_id
Constructor Details
#initialize(host, log = false) ⇒ HttpClient
Returns a new instance of HttpClient.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ethereum/http_client.rb', line 6 def initialize(host, log = false) super(log) 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 Attribute Details
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/ethereum/http_client.rb', line 4 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/ethereum/http_client.rb', line 4 def port @port end |
#ssl ⇒ Object
Returns the value of attribute ssl.
4 5 6 |
# File 'lib/ethereum/http_client.rb', line 4 def ssl @ssl end |
#uri ⇒ Object
Returns the value of attribute uri.
4 5 6 |
# File 'lib/ethereum/http_client.rb', line 4 def uri @uri end |
Instance Method Details
#send_batch(batch) ⇒ Object
33 34 35 |
# File 'lib/ethereum/http_client.rb', line 33 def send_batch(batch) raise NotImplementedError end |
#send_single(payload) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ethereum/http_client.rb', line 21 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 |