Class: Ethereum::HttpClient
- Inherits:
-
Client
- Object
- Client
- Ethereum::HttpClient
- Defined in:
- lib/ethereumex/http_client.rb
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.
Instance Method Summary collapse
-
#initialize(host, port, ssl = false, log = false) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #send_batch(batch) ⇒ Object
- #send_single(payload) ⇒ Object
Constructor Details
#initialize(host, port, ssl = false, log = false) ⇒ HttpClient
Returns a new instance of HttpClient.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ethereumex/http_client.rb', line 6 def initialize(host, port, ssl = false, log = false) super(log) @host = host @port = port @ssl = ssl 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/ethereumex/http_client.rb', line 4 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
4 5 6 |
# File 'lib/ethereumex/http_client.rb', line 4 def port @port end |
#ssl ⇒ Object
Returns the value of attribute ssl.
4 5 6 |
# File 'lib/ethereumex/http_client.rb', line 4 def ssl @ssl end |
#uri ⇒ Object
Returns the value of attribute uri.
4 5 6 |
# File 'lib/ethereumex/http_client.rb', line 4 def uri @uri end |
Instance Method Details
#send_batch(batch) ⇒ Object
30 31 32 |
# File 'lib/ethereumex/http_client.rb', line 30 def send_batch(batch) raise NotImplementedError end |
#send_single(payload) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ethereumex/http_client.rb', line 18 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 |