Class: Ethereum::HttpConnection
- Defined in:
- lib/elchapo/ethereum/http_connection.rb
Constant Summary
Constants inherited from Client
Client::DEFAULT_GAS_LIMIT, Client::DEFAULT_GAS_PRICE, 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, #gas_limit, #gas_price, #id, #log, #logger
Instance Method Summary collapse
-
#initialize(host) ⇒ HttpConnection
constructor
A new instance of HttpConnection.
- #send_single(payload) ⇒ Object
Methods inherited from Client
#encode_params, #get_id, #int_to_hex, #reset_id, #send_command
Constructor Details
#initialize(host) ⇒ HttpConnection
Returns a new instance of HttpConnection.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/elchapo/ethereum/http_connection.rb', line 7 def initialize(host) 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 Attribute Details
#host ⇒ Object
Returns the value of attribute host.
5 6 7 |
# File 'lib/elchapo/ethereum/http_connection.rb', line 5 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
5 6 7 |
# File 'lib/elchapo/ethereum/http_connection.rb', line 5 def port @port end |
#ssl ⇒ Object
Returns the value of attribute ssl.
5 6 7 |
# File 'lib/elchapo/ethereum/http_connection.rb', line 5 def ssl @ssl end |
#uri ⇒ Object
Returns the value of attribute uri.
5 6 7 |
# File 'lib/elchapo/ethereum/http_connection.rb', line 5 def uri @uri end |
Instance Method Details
#send_single(payload) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/elchapo/ethereum/http_connection.rb', line 22 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 |