Class: Ethereum::HttpClient

Inherits:
Client
  • Object
show all
Defined in:
lib/ethereum/http_client.rb

Constant Summary

Constants inherited from Client

Client::RPC_COMMANDS, Client::RPC_MANAGEMENT_COMMANDS

Instance Attribute Summary collapse

Attributes inherited from Client

#command, #id, #log, #logger

Instance Method Summary collapse

Methods inherited from Client

#batch, #get_id, #reset_id

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/ethereum/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

#hostObject

Returns the value of attribute host


4
5
6
# File 'lib/ethereum/http_client.rb', line 4

def host
  @host
end

#portObject

Returns the value of attribute port


4
5
6
# File 'lib/ethereum/http_client.rb', line 4

def port
  @port
end

#sslObject

Returns the value of attribute ssl


4
5
6
# File 'lib/ethereum/http_client.rb', line 4

def ssl
  @ssl
end

#uriObject

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

Raises:

  • (NotImplementedError)

30
31
32
# File 'lib/ethereum/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/ethereum/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